Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memcache vs Java Memory

Simple, probably dumb question: Suppose I have a Java server that stores in memory commonly used keys and values which I can query (let's say in a HashMap)

What's the difference between that and using Memcache (or even Redis)? They both store things in memory. Is there a benefit to one or the other? Does Memcache leaves less of a memory footprint? Can store more in less memory? Faster to query? No difference?

like image 872
Henley Avatar asked Mar 28 '11 22:03

Henley


People also ask

How much RAM does Memcached use?

By default, memcached generally only sets aside a small amount of RAM for the cache. This may differ depending on the operating system or Linux distribution, but it varies between 64MB and 512MB. The more memory you can give to memcached, the better. We recommend at least 2GB, if you can afford it.

Is Memcache a memory?

Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering. Memcached is simple yet powerful. Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches.

Why is memcache better than Redis?

Redis uses a single core and shows better performance than Memcached in storing small datasets when measured in terms of cores. Memcached implements a multi-threaded architecture by utilizing multiple cores. Therefore, for storing larger datasets, Memcached can perform better than Redis.


1 Answers

Advantages of Java memory over memcache:

  1. Java memory is faster (no network).
  2. Java memory won't require serialization, you have Java objects available to you.

Advantages of memcache over Java memory:

  1. It can be accessed by more than one application server, so your cache will be shared among all your app servers.
  2. It can be accessed by a variety of different servers, so long as they all agree on the key scheme and the serialization.
  3. It will discard expired cache values, so you get time-based invalidation.
like image 162
Ned Batchelder Avatar answered Sep 18 '22 04:09

Ned Batchelder