Redis 225 ms Retrieval of Hash Value

I am new to Redis, and I'm unsure why this query would take so long. It is 7mb string essentially of a json object. I used HGet key data and the amount of time that it is taking is 225 milliseconds on average. This is actually slower than the sql server in the same virtualized environment. They have the same allocated resources as well.

The built in latency in the virtualized environment is only about 9000 micro seconds at its worst.

I can't even wrap my head around how could something completely cached in memory take longer than getting the same data in sql. The redis server is taking about twice as long. Here is an example of the string below.

[ {"name":"Christopher", "advocate": "John"}, {"name": "Jane", "advocate": "John"}, etc..]

The sql is just a table of the exact same information.

|    name     | advocate |
| ----------  | -------- |
| Christopher | John     |
| Jane        | John     |

Is there something I am missing for larger objects in Hash, that would improve performance? I can't justify to anyone to use Redis, if the exact same query is slower in memory than sql. I understand once I start increasing the join complexity in sql I could see more imporvement. But I just think there is more that I could be missing in Redis.

I can provide any more detail if you need so.

2 answers

  • answered 2017-06-17 18:46 Didier Spezia

    It is not so suprising.

    SQL Server uses TDS to return the data. This protocol is designed to be efficient to return tabular data. It does not repeat the field names for each row - which happens in your JSON object. My guess is the JSON representation is actually bigger than the TDS representation. Because this use case is limited by the network bandwidth (more than the latency), Redis appears to be slower.

    Note that Redis is not especially optimized to store and return large objects anyway.

    7 MB for 225 ms represent 31 MB/s. It obviously depends on the size of your pipes, but it does not look so bad for a virtualized environment.

  • answered 2017-06-17 18:46 Srini Sydney

    Use msgpack to increase performance. Reference link on performance benchmarks - https://jsperf.com/msgpack-vs-json-perf/3