Why can't I store Session with memcached

Source: Internet
Author: User
Tags memcached

if the Session is stored with memcached, the user will not be able to log in or be kicked off when the memcached cluster fails (such as a memory overflow) or maintenance (such as upgrading, increasing, or reducing the server).

Second, the memcached recovery mechanism may cause the user to drop the line without reason. Because Memcached uses the least recently used (LRU) algorithm to reclaim the cache. This means that if all sessions are roughly the same size, they will be divided into two or three slab classes. All other data of roughly the same size will be placed in the same slab with the Session contention storage space. Once the slab is full, even if there is room in the larger slab, the data will be collected instead of being put into the larger slab ... In a particular slab, the oldest user of the Session will be dropped. The user will start to randomly drop the line, and worst of all, you probably won't even notice it until the user starts complaining ... In addition, if new data is added to the session, then the session becomes larger and may lead to a drop-off problem.

It was proposed to use separate memcached caches for Session and other data respectively. However, because Memcached's LRU algorithm is local , that approach not only leads to low memory usage, but also eliminates the risk that users will be randomly dropped due to Session recycling.

Note: memcached is a system designed to cache data instead of storing data, so it should not be used to store the Session.


If you really want to use memcached to improve the Session read speed, then you can draw on the Norkūnas proposed Memcached+rdbms (in some cases, NoSQL can) mode:

1, when the user login, the Session "set" to memcached, and write to the database;

2. Add a field to the session to identify when the session was last written to the database;

3, each page load, the priority from memcached read Session, followed by reading from the database;

4, after each load N pages or Y minutes, the Session is written to the database again;

5. Get the expired Session from the database, and get the latest data from memcached first.

Why can't I store Session with memcached

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.