Introducing Dragonfly Cloud! Learn More

Question: How many objects can be stored in Memcached?

Answer

The number of objects that can be stored in Memcached depends on several factors, including the amount of memory available, the size of the objects being stored, and the eviction policy being used.

To determine the maximum number of objects that can be stored in Memcached, we need to consider the following:

  1. Memory allocation: In Memcached, the memory for storing objects is pre-allocated when the server starts up. The default setting for memory allocation in Memcached is 64MB. However, this value can be increased or decreased based on the requirements of your application.

  2. Object size: The maximum size of an object that can be stored in Memcached is 1MB. If the size of the objects you are storing exceeds this limit, you may need to consider splitting them into smaller objects.

  3. Eviction policy: When the memory allocated for storing objects in Memcached is full, the server uses an eviction policy to determine which objects to remove from memory to make space for new objects. There are several eviction policies available in Memcached, including LRU (Least Recently Used), LFU (Least Frequently Used), and Random.

Given these factors, it is difficult to provide an exact number of objects that can be stored in Memcached. However, as a rough estimate, assuming an average object size of 1KB and using the default memory allocation of 64MB, Memcached can store around 65,000 objects.

Here's an example of how you can get the current statistics about the cached items using the stats command in Memcached:

$ echo "stats" | nc localhost 11211 STAT pid 12345 STAT uptime 1800 STAT time 1611580977 STAT version 1.6.9 STAT curr_items 1000 STAT total_items 5000 STAT bytes 10485760 STAT curr_connections 10 STAT total_connections 100 STAT cmd_set 1000 STAT cmd_get 500 END

In the example above, curr_items indicates the current number of items stored in Memcached, while total_items indicates the total number of items that have been stored since the server started.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Start building today 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.