唉,本来好好的使用的memcached的,突然要修改成支持多线程。对于memcached默认是只使用一个线程的,也就是说所有的请求都是通过一个线程来响应请求。如果想使memcached支持多线程,那么你就必须重新编译memcached。在编译memcached的时候,使用--enable-threads
选项来告诉memcached来支持多线程。然后编译安装完成之后,memcached就可以支持多线程响应请求。
需要注意的是如果你在启动的是没有通过-t选项指定thread的个数,那么memcached默认是四个线程。另外如果你指定的线程树超过了你cpu的核数,则有可能引发死锁问题,而且必须你的机器支持多线程编程(这句话不是很理解,是翻译过来的。现在机器不都是支持的吗)。
首先贴上安装的代码步骤,然后对出现问题简单分析一下。
下面的安装步骤是分为两个部分,一种是直接通过yum安装工具进行安装。这种方式是安装的单线程的memcached,如果想支持多线程,那么就必须采用第二种即通过编译源码进行安装。通过源码编译安装的话,必须是要机器上安装有libevent包,否则也是无法正常编译完成的。
1:Installing memcached from a Binary Distribution
To install memcached on a Red Hat, or Fedora host, use yum:
root-shell> yum install memcached
On CentOS, you may be able to obtain a suitable RPM from another source, or use the source tarball.
To install memcached on a Debian or Ubuntu host, use apt-get:
root-shell> apt-get install memcached
To install memcached on a Gentoo host, use emerge:
root-shell> emerge install memcached
2:Building memcached from Source
On other Unix-based platforms, including Solaris, AIX, HP-UX and Mac OS X, and Linux distributions not mentioned already, you must install from source. For Linux, make sure you have a 2.6-based kernel, which includes the improved epoll
interface. For all platforms, ensure that you have libevent
1.1 or higher installed. You can obtain libevent
from libevent
web page.
You can obtain the source for memcached from memcached Web site.
To build memcached, follow these steps: