Search code examples
c++ignitein-memory

How are the key-value pairs stored in apache ignite?


For the below cache implementation, I have a considerable throughput for put and remove operations.

Cache<double , CacheData> lCache = gGrid.GetOrCreateCache<double, CacheData>("myCache");

When i use a string as key there is very drastic reduction about 10 times in throughput.

Cache<string , CacheData> lCache = gGrid.GetOrCreateCache<string, CacheData>("myCache");

The key-value pair that i am populating is in the below implementation

double lKey=111111111111111;
CacheData lCacheData;
string lKeyStr;
std::ostringstream strs;
strs << (lKey+=mIncrement);
lKeyStr = strs.str();
cache.Put(lKeyStr,lCacheData);

CacheData Structure.

namespace ignite
{
        struct CacheData
        {
                CacheData() :
                        data()
                {
                     data.assign(2048, 'a');
                }
                std::string data;
        };
}

Why is there a reduction in throughput for the above implementation?


Solution

  • String is not the best type to be used as a key. Each time you read or update an entry, Ignite calculates key hashcode and then checks for equality. Equals check for string implies iteration over all characters, which is obviously worse than comparing a single double value, and also gets worse for longer strings.

    The above is actually true for any hash map, not only for Ignite.