After the recent increase in website traffic, the number of database connections has been high. After analysis, it is found that they are all normal requests. However, the website functions are divided into details. There are too many single-page database query sentences. A lot of data is unnecessary. Real-time query, just cache it! Consider using memcache for caching to reduce the pressure on mysql!
Project name: 15-day weather forecast query website http://15tianqi.cn
Cause of the problem: There are too many mysql connection requests and the database is under great pressure
Solution: Install and enable memcache
What is Memcache? Memcache is a free and open source, high-performance, allocated memory object caching system. Used to accelerate dynamic web applications and reduce database load.
It can handle any number of connections and uses non-blocking network IO. Since its working mechanism is to open up a space in the memory and then create a HashTable, Memcached manages these HashTables by itself. Memcached is simple yet powerful. Its simple design promotes rapid deployment, eases development problems, and solves many of the problems faced by large data caches. Its API is available for the most popular languages.
No matter what, if we want to use memcache as a memory cache, we must install memcache into php and then install memecached in the linux system. In this way, PHP can access data in memory through memecache.
1. Download memcached.
cd /usr/local/src wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz
2. Install memcached.
tar zxvf memcached-1.4.15.tar.gz cd memcached-1.4.15 ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent make make install
3. Start memcached and check whether the installation is functional
/usr/local/memcached/bin/memcached -d -m 128 -p 11211 -u root ps aux | grep memcached
memcache is a very practical caching technology. Well-known users of Memcache include: LiveJournal, Wikipedia, Flickr, Bebo, Twitter, Typepad, Yellowbot, Youtube, etc.