Recently, due to a bottleneck in a business system, you need to find a tool that can quickly summarize data for an intermediate cache. The specific scenario is as follows: the server collects logs from the WEB Cluster for centralized processing. There is a large amount of duplicate information in the logs, and the COUNT needs to be summarized. MYSQL was first used, and later found that the writing bottleneck caused the database writing thread to be blocked.
Recently, due to a bottleneck in a business system, you need to find a tool that can quickly summarize data for an intermediate cache. The specific scenario is as follows: the server collects logs from the WEB Cluster for centralized processing. There is a large amount of duplicate information in the logs, and the COUNT needs to be summarized. MYSQL was first used, and later found that the writing bottleneck caused the database writing thread to be blocked.
Recently, due to a bottleneck in a business system, you need to find a tool that can quickly summarize data for an intermediate cache. The specific scenario is as follows: the server collects logs from the WEB Cluster for centralized processing. There is a large amount of duplicate information in the logs, and the COUNT needs to be summarized. MYSQL was first used. Later, it was found that the writing bottleneck caused the database writing thread to be blocked. The log processing thread can only wait until it fills up the database writing queue in the memory. Later, table sharding was performed by business, and both database writing and log processing were changed to multithreading. The problem still cannot be solved, and the server load is also soaring. After discussion in the Group, we decided to adopt redis. This is also the opportunity to study.
I. Installation
First, let's talk about the installation environment and process:
Operating System: centos5.4
Redis edition: redis-2.8.7.tar.gz
The process is as follows:
Cd/data0/software/installmkdir install_rediscd install_rediswget http://download.redis.io/releases/redis-2.8.7.tar.gztar zxvf redis-2.8.7.tar.gzcd redis-2.8.7make & make install # modify the configuration file, redis runs vi redis in daemon mode. confdaemonize yes # Start redis and specify the configuration file location cd src /. /redis-server/usr/local/redis. conf
When redis-server starts the server, you must specify the location of the configuration file. Otherwise, the server is started with the default configuration. Port 6379 is used by default. It is said that the four letters typed on the mobile phone represent a singer. Note that the redis-server and redis-cli (client) programs are under the./src directory (Khan, I have been searching for a long time ).
By default, the server does not start the daemonize mode. You need to modify it in the configuration file (daemonize yes)
There is a load testing tool redis-benchmark under src. I did a test and compared it with other people. It is a little ahead. It should be a good machine, less than 1.7 seconds and concurrent jobs. The result is as follows:
Run redis-cli to start the client program. In this way, you can interact with redis. Enter several test commands:
Ii. java package and php extension installation Configuration
The java environment is easy to set up, just download a package and import it.
Php extension installation is a little troublesome. the linux installation process is as follows:
tar zvxf redis-2.8.7.tar.gzcd redis-2.8.7/bin/phpize./configure --with-php-config=bin/php-configmakemake installcd ..
Because I have to perform a test on the Local Computer and install it on windows, the installation process of redis is relatively easy and can be run after downloading. Expansion is a little troublesome, roughly as follows:
Php_redis.dll extension for redis in PHP5.4.x
Extension:
Https://github.com/nicolasff/phpredis/downloads
Includes both Non-Thread Safe and Thread Safe versions.
First, put php_redis.dll and php_igbinary.dll into the ext folder of PHP,
Then add the following code in the php. ini configuration file:
Extension = php_igbinary.dll extension = php_redis.dll
Restart WebServer
Note:
Extension = php_igbinary.dll must be placed before extension = php_redis.dll; otherwise, this extension will not take effect.
The test code is as follows: