Parsing Linux installation Memcacheq (MCQ) Full process notes _php tutorial

Source: Internet
Author: User
Memcacheq is a simple distributed Message Queuing service.
One, the application background of Memcacheq
What is in the Web App
Do you need a message queue? The main reason is because in high concurrency environment, due to too late synchronous processing, the request will often occur congestion, for example, a large number of insert,update and other requests to reach MySQL, directly resulting in countless row lock table lock, even the final request will accumulate too much, thereby triggering too Manyconnections error. By using Message Queuing, we can handle requests asynchronously to relieve the pressure on the system. In the era of Web2.0, the situation of high concurrency is becoming more and more common, so that the message queue has become a necessary trend in the home, the corresponding also emerged a lot of implementation scenarios, such as Twitter used to implement the Message Queuing service RABBITMQ, and now the use of Kestrel to implement the Message Queuing service, there are many other options , such as: Activemq,zeromq and so on.

Most of the above Message Queuing software is extremely heavyweight in order to implement protocols such as AMQP,STOMP,XMPP, but the reality in many Web applications is that we just want to find a solution that alleviates high concurrent requests and does not require assorted functionality. A lightweight way to implement Message Queuing is what we really need.

Second, the characteristics of Memcacheq
1 Easy to use
2 Faster processing speed
More than 3 queues
4 Concurrency performance is good
5 compatible with the Memcache protocol. This means that as long as the memcache extension is available, no additional plugins are required.

Three, installation
Memcacheq relies on libevent and berkleydb.
Berkleydb data that is used to persist the storage queue. So when the Memcacheq crashes or the server hangs up,
Data loss is not a result. This is important and important.
Its installation depends on BerkeleyDB and libevent, so install this berkeleydb and libevent first:
Where libevent if you have installed memcached has been installed, if not sure, check it

1. Check libevent First, Libevent-devel is installed: rpm-qa|grep libevent output must contain libevent, Libevent-deve, if missing, install using the following command:
Yum Install libevent Yum
Install Libevent-devel
Note:libevent, Libevent-devel priority to use the Yum installation source, disc image in the RPM package installation, so that stability and compatibility can be guaranteed, online circulation of the use of the source code installation Libevent method will be problematic, Because it is likely that the system has been installed Libevent, and then use the source installation, will inevitably lead to conflict, causing unexpected problems, so be sure to use the above command to check whether the system has installed the appropriate library

2. Installing Berkleydb
1.tar ZXVF bdb-5.3.3.tar.gz
2.CD db-5.3.3/
#需要进入特定操作系统编译环境, there are some differences in the compilation of more conventional software
3.CD build_unix/
4 ... /dist/configure--prefix=/usr/local/berkeleydb
#如果没有指定特殊安装路径, compile, the path to the Berkeley DB Runtime needs to be added to the system configuration
echo "/usr/local/berkeleydb.5.3/lib/" >>/etc/ld.so.conf
#重载系统Ld运行库
Ldconfig
5. Make & make Install
Remember to change the/etc/ld.so.conf file, add/usr/local/berkeleydb.5.3/lib Ah, or the MCQ will install errors later.
And BerkeleyDB's going to download it.
Click to download Berkeley DB 5.3.21.rar
Install Memcacheq below,
Download a memcacheq-0.2.0.rar first
Unzip, enter the catalogue
./configure–with-bdb=/usr/local/berkeleydb.5.1–with-libevent=/usr/local/lib–enable-threads
Make
Make install
The key is the red font that step, must be entered correctly, or make does not pass, unable to install

here is the boot
memcacheq-d-r-u root-p21201-h/data/memcacheq-n-v-l 1024-b 1024x768 >/data/mq_error.log 2>&1
It is not recommended to use root user, some of the posts say no, I can test here, but it may be unsafe.
1 The following are the parameters at the start time
Use memcacheq-h commands to view command-line Options
2 This is the right start memcacheq:memcacheq-d-uroot-r-p11212-h/home/wwwroot/mcq-n-r-v-L 1024-b 1024x768 >/home/wwwlogs/mq_err Or.log 2 > &1
3 this doesn't know why./usr/local/memcacheq/bin/memcacheq-d-L 127.0.0.1-a 8192-h/data/memcacheq-b 65535-n-r-u Root
-P TCP Listening port (default:22201)
-U UDP Listener port (default:0, off)
-S UNIX socket Path (network not supported)
-a UNIX socket access Mask (default 0700)
-L listens for network card
-D daemon
-r maximize core file limit
-u Run as user (only if run as root)
-C Maximum number of concurrent connections (default is 1024x768)
-v Verbose output (print errors/warnings while in event loop) br>-vv more verbose 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 Bottom 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 How many seconds checkpoint once, 0 for disable, and default is 5 minutes
-T How many seconds Memp_trickle once, 0 for disable, and default is seconds
-S How many seconds queue stats dump once, 0 for disable, and default is seconds
-E How much cache needs to be refreshed, default is 60%
-E How many pages of a single DB file, default is 16*1024, 0 for disable
-B Specifies the length of the message body, in bytes, default is 1024
-D How many milliseconds do one time deadlock detection (deadlock detecting), 0 for disable, default is 100ms
-N open Db_txn_nosync for great performance improvements, default is off
-r automatically deletes log files that are no longer needed, default is off
Test

Third, testing
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 the set when the success of the not_stored, check your command bar, the parameters are not set, if you are a novice, dry cui more than a few posts, try to start the command, change parameters, on the line

Four, using
After starting MQ with the above command (note that the-b parameter above indicates that the body length of Messag cannot exceed bytes), only two commands are required to use MQ: Set and get:
Set 0 \ r \ n
\ r \ n
stored\r\n
Get \ r \ n
VALUE \ r \ n
\ r \ n
end\r\n
As you can see, the Memcache protocol is basically the same, except that the key name is replaced by the queue name, and the parameters of the Expire_time are ignored in the set command. After all, MQ's data storage is present in BerkeleyDB, and does a persistent storage, with no memory expiration time.
When the set command is used, a new message is written to the specified message queue, that is, a new insert is made to the berkeleydb, and when the Get command is used, a new message is removed from the specified queue, which is the delete of the data to the BerkeleyDB. When using stats to view a specified queue, you can see how many messages the queue received and how many were fetched.
Example:
Copy CodeThe 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 above executes two sets of commands, when using stats queue to view, you can see the Q4 queue has a message 2, has been removed 0; When you use get to remove the first bar, then use Stats queue view, Q4 message has 2, which has been removed 1.
PHP Test:
Copy CodeThe 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);

Comments:
This time there will be a problem like this
Memcacheq:error while loading shared libraries:libdb-5.0.so:cannot open Shared object file:no such file or directory
Workaround: Build a libdb-5.0.so soft chain on/usr/lib.
Ln-s/usr/local/berkeleydb.5.0/lib/libdb-5.0.so/usr/lib/

Five, close Memcacheq
Use the PS command to check the MEMCACHEQ process: Ps-ef|grep wuf, then kill the process directly.

http://www.bkjia.com/PHPjc/327880.html www.bkjia.com true http://www.bkjia.com/PHPjc/327880.html techarticle Memcacheq is a simple distributed Message Queuing service. One, why do I need Message Queuing in the MEMCACHEQ application background Web application? The main reason is because in high concurrency environment, by ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.