Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra as session store under heavy load

Tags:

cassandra

I would like to use Cassandra to store session related informations. I do not have real HTTP session - it's different protocol, but the same concept.

Memcached would be fine, but I would like to additionally persist data.

Cassandra setup:

  • non replicated Key Space
  • single Column Family, where key is session ID and each column within row stores single key/value - (Map<String,Set<String,String>>)
  • column TTL = 10 minutes
  • write CL = ONE
  • read CL = ONE
  • 2.000 writes/s
  • 5.000 reads/s

Data example:

session1:{ // CF row key
   {prop1:val1, TTL:10 min},
   {prop2:val2, TTL:10 min},
.....
   {propXXX:val3, TTL:10 min}
},
session2:{ // CF row key
   {prop1:val1, TTL:10 min},
   {prop2:val2, TTL:10 min},
},
......
sessionXXXX:{ // CF row key
   {prop1:val1, TTL:10 min},
   {prop2:val2, TTL:10 min},
}

In this case consistency is not a problem, but the performance could be, especially disk IO.

Since data in my session leaves for short time, I would like to avoid storing it on hard drive - except for commit log.

I have some questions:

  1. If column expires in Memtable before flushing it to SSTable, will Cassandra anyway store such column in SSTable (flush it to HDD)?
  2. Replication is disabled for my Key Space, in this case storing such expired column in SSTable would not be necessary, right?
  3. Each CF hat max 10 columns. In such case I would enable row cache and disable key cache. But I am expecting my data to be still available in Memtable, in this case I could disable whole cache, right?
  4. Any Cassandra configuration hints for such session-store use case would be really appreciated :)

Thank you, Maciej

like image 431
Maciej Miklas Avatar asked Oct 10 '11 08:10

Maciej Miklas


People also ask

Can I use Cassandra as a data store for large objects?

If you use your object store for large objects and employ erasure coding and use Cassandra as your data store for small objects and use replication - you have introduced a non-trivial SLA problem. In this approach, data is protected by different guarantees.

What is your primary use case for Cassandra?

At Glassdoor we use Cassandra to store various datasets needed by search, machine learning models and other systems. Since most of these systems are built on Java, we use Java drivers for Cassandra, for read, write and delete operations.

What happens if counter cache is > 1 in Cassandra?

In case of RF = 1 a counter cache hit will cause Cassandra to skip the read before write entirely. With RF > 1 a counter cache hit will still help to reduce the duration of the lock hold, helping with hot counter cell updates, but will not allow skipping the read entirely.

How can I make Cassandra more durable?

The only reasonable way to make Cassandra durable is to use the synchronous batch mode committer which comes with a performance penalty. Cassandra’s high-availability guarantee is not suited for erasure coded object stores.


2 Answers

Here is what I did - and it works fine:

  1. Set replication_factor to 1 - means disable replication
  2. Set gc_grace to 0 - means delete columns on first compaction. This is fine, since data is not replicated.
  3. Increase memtable size and decrease cache size. We want to read data from memtable and omit cache - flushing data to HDD and reading it again from HDD into cache.
  4. Additionally commit log can be disabled - durable_writes=false

In this setup, data will be read from memtable and cache will be not used. Memtable can allocate enough heap to keep my data until it expires or even longer.

After flushing data to SSTable, compaction will immediately remove expired rows, since gc_grace=0.

like image 65
Maciej Miklas Avatar answered Oct 15 '22 07:10

Maciej Miklas


Considering your use case if I'm not wrong you wish to have all your key value[sessionID=>sessionData] pairs in memory and those values will expire every 10min[Means you don't want persistence].

Then why can't you try something like redis which is a in-memory store.

From Doc:

Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

Since u don't need replication redis master slave architecture even might not affect you

Redis supports TTL also

AFAIK cassandra is good for wide fat rows[More columns less rows] rather skinny rows[transpose of previous]. Your use case doesn't seem so.

Regards, Tamil

like image 42
Tamil Avatar answered Oct 15 '22 06:10

Tamil