Home  >  Article  >  Backend Development  >  Analysis of notes on the entire process of installing memcacheq (mcq) under Linux_PHP tutorial

Analysis of notes on the entire process of installing memcacheq (mcq) under Linux_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:03:05956browse

memcacheQ是一个单纯的分布式消息队列服务。
一,MEMCACHEQ的应用背景
Web应用中为什
么会需要消息队列?主要原因是由于在高并发环境下,由于来不及同步处理,请求往往会发生堵塞,比如说,大量的insert,update之类的请求同时到达mysql,直接导致无数的行锁表锁,甚至最后请求会堆积过多,从而触发too manyconnections错误。通过使用消息队列,我们可以异步处理请求,从而缓解系统的压力。在Web2.0的时代,高并发的情况越来越常见,从而使消息队列有成为居家必备的趋势,相应的也涌现出了很多实现方案,像Twitter以前就使用RabbitMQ实现消息队列服务,现在又转而使用Kestrel来实现消息队列服务,此外还有很多其他的选择,比如说:ActiveMQ,ZeroMQ等。

上述消息队列的软件中,大多为了实现AMQP,STOMP,XMPP之类的协议,变得极其重量级,但在很多Web应用中的实际情况是:我们只是想找到一个缓解高并发请求的解决方案,不需要杂七杂八的功能,一个轻量级的消息队列实现方式才是我们真正需要的。

二,MEMCACHEQ的特性
1 简单易用
2 处理速度快
3 多条队列
4 并发性能好
5 与memcache的协议兼容。这就意味着只要装了memcache的extension就可以了,不需要额外的插件。

三,安装
MEMCACHEQ依赖于libevent和BerkleyDB。
BerkleyDB用于持久化存储队列的数据。 这样在MEMCACHEQ崩溃或者服务器挂掉的时候,
不至于造成数据的丢失。这一点很重要,很重要。
它的安装依赖于BerkeleyDB 和 libevent,所以要先安装这BerkeleyDB和libevent:
其中libevent如果你安装过memcached就已经安装了,如果不确定,就检查一下吧

1. 先检查libevent, libevent-devel是否已经安装:  rpm -qa|grep libevent 输出中必须包含libevent, libevent-deve, 如果缺失,使用以下命令安装:
yum install libevent yum
install libevent-devel
注意事项:libevent, libevent-devel优先使用yum安装源,光盘镜像中的rpm包安装,这样稳定性和兼容性可得到保证,网上流传的使用源码安装libevent的方法会有问题,因为很可能系统已经安装libevent, 再使用源码安装, 必然导致冲突,造成意外问题,所以一定要使用上述命令检查系统是否已经安装相应的库

2. 安装BerkleyDB
1.tar zxvf bdb-5.3.3.tar.gz
2.cd db-5.3.3/
#需要进入特定操作系统编译环境,更常规软件的编译有些区别
3.cd build_unix/
4. ../dist/configure --prefix=/usr/local/berkeleydb
#如果没有指定特殊安装路径,编译完成,需要将Berkeley Db运行库的路径添加到系统配置里面
echo "/usr/local/BerkeleyDB.5.3/lib/" >> /etc/ld.so.conf
#重载系统Ld运行库
ldconfig
5. make & make install
记得改/etc/ld.so.conf文件,添加/usr/local/BerkeleyDB.5.3/lib啊,不然后面的mcq会安装错误。
而BerkeleyDB就要去下载了
点击下载Berkeley DB 5.3.21.rar
下面安装memcacheq,
先下载一个memcacheq-0.2.0.rar
解压,进目录
./configure –with-bdb=/usr/local/BerkeleyDB.5.1 –with-libevent=/usr/local/lib –enable-threads
make
make install
关键是红色字体那一步,一定输入正确,不然make不通过,无法安装

The following is startup
memcacheq -d -r -u root -p21201 -H /data/memcacheq -N -v -L 1024 -B 1024 > /data/mq_error.log 2> ;&1
It is not recommended to use the root user here. Some posts say it is not possible. I tested it here and it is OK, but it may be unsafe.
1 The following are the parameters at startup
Use the memcacheq -h command to view the command line options
2 This is the correct way to start memcacheq: memcacheq -d -uroot - r -p11212 -H /home/wwwroot/mcq -N -R -v -L 1024 -B 1024 > /home/wwwlogs/mq_error.log 2 > &1
3 I don’t know about this Why not /usr/local/memcacheq/bin/memcacheq -d -l 127.0.0.1 -A 8192 -H /data/memcacheq -B 65535 -N -R -u root
-p -U UDP listening port (default: 0, off)
-s unix socket path (network is not supported)
-a unix socket access mask (default 0700)
-l Monitor network card
-d daemon
-r Maximize core file limit
-u Run as user (only when run as root)
-c Maximum number of concurrent connections (default is 1024)
-v Verbose output (print errors/warnings while in event loop)
- vv More detailed output (also print client commands/reponses)
-i Print license information
-P PID file
-t Number of threads (default 4)
--------------------------BerkeleyDB Options-------------------------- -------
-m BerkeleyDB memory cache size, default is 64MB
-A Underlying page size, default is 4096, (512B ~ 64KB, power -of-two)
-H

Database home directory, default is '/data1/memcacheq'
-L Log buffer size, default is 32KB
-C < num> How many seconds to checkpoint once, 0 for disable, default is 5 minutes
-T How many seconds to memp_trickle once, 0 for disable, default is 30 seconds
-S How many seconds to queue stats Dump once, 0 for disable, default is 30 seconds
-e What percentage of the cache needs to be refreshed, default is 60%
-E How many pages does a single DB file have? , default is 16*1024, 0 for disable
-B Specify the length of the message body in bytes, default is 1024
-D How many milliseconds to perform deadlock detection (deadlock detecting), 0 for disable, default is 100ms
-N Turn on DB_TXN_NOSYNC to get huge performance improvements, default is off
-R Automatically delete log files no longer needed, default is off
Test

3. Test
1.telnet 10.218.31.121 22201
2.stats
2.stats queue
3.set q4 0 0 5
4 hello
5 get q4
6 stats queue
7 delete q4
If not_STORED is successful during set, check your startup command. The parameters are not set properly. If you are a novice, Gan Cui Read a few more posts, try more startup commands, change the parameters, and it will be fine

Fourth, use
to start mq using the above command (note that the -B parameter above indicates that the body length of the message cannot exceed 1024 bytes), only two commands are needed when using mq :set and get:
set 0 rn
rn
STOREDrn
get rn
VALUE rn
rn
ENDrn
As you can see, it is basically the same as the memcache protocol, except that The key name is replaced with the queue name, and the expire_time parameter is ignored in the set command. After all, mq's data storage is stored in BerkeleyDB, which is a persistent storage and has no memory expiration time.
When the set command is used, a new message is written to the specified message queue, that is, a new piece of data is inserted into BerkeleyDB. When the get command is used, a new message is taken out from the specified queue. That is, a piece of data is deleted from BerkeleyDB. When you use stats to view a specified queue, you can see how many messages the queue has received and how many have been taken out.
Example:

Copy code The code is as follows:

fengbo@onlinegame-10-121:~$ telnet 127.0. 0.1 22202
Trying 127.0.0.1…
Connected to 127.0.0.1.
Escape character is '^]'.
set q4 0 0 5
hello
STORED
set q4 0 0 5
world
STORED
stats queue
STAT q4 2/0
END
get q4
VALUE q4 0 5
hello
END
stats queue
STAT q4 2/1
END

The set command has been executed twice above. When using stats queue to view it, you can see that there are 2 messages in the queue of q4 and 0 messages have been taken out. After using get to take out the first one, use stats queue to view it. , there are 2 messages in q4, 1 of which has been taken out.
PHP test:
Copy code The code is as follows:

session_start();
$memcache_obj = new Memcache ;
$memcache_obj->connect('127.0.0.1′, 11212) or die ("error");
memcache_set($memcache_obj, 'k',10, 0, 0);
echo "queue".memcache_get($memcache_obj, 'k');
memcache_close($memcache_obj);

Note:
This problem will occur at this time
memcacheq: error while loading shared libraries: libdb-5.0.so: cannot open shared object file: No such file or directory
Solution: Create a libdb-5.0.so soft link under /usr/lib OK
ln -s /usr/local/BerkeleyDB.5.0/lib/libdb-5.0.so /usr/lib/

Fifth, close memcacheQ
Use the ps command to check the memcacheQ process: ps -ef|grep wuf, and then kill the process directly.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327880.htmlTechArticlememcacheQ is a simple distributed message queue service. 1. Application background of MEMCACHEQ Why is a message queue needed in web applications? The main reason is that in a high-concurrency environment,...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn