Hello!
On Thu, Aug 21, 2014 at 12:03 PM, isheff1 wrote:
> For caching purposes, would there be significant latency/performance
> improvements if I were to use, say, a 1 GB nginx shared dict as my first
> level of caching and then fall back to Redis with lua-resty-redis for
> everything else, and to store semi-persistent data?
The benefit of an extra caching layer depends on the cache hit rate of
your app's use pattern.
We use 2 levels of caching (lua-resty-lrcache and ngx.shared.DICT)
before our memcached-like data service based on sockets in production,
for example. Because the locality and cache hit rate is good enough.
> Or would performance be
> approximately the same using Redis listening locally on a Unix socket
> (though Redis may be separated into its own server eventually once I need
> load distribution)?
Theoretically, shm outperforms sockets a *lot* due to the lack of
expensive socket-related system calls and almost no context switches.
But in reality there can be more complications with shm like
serialization/de-serialization overhead and also locking overhead
involved with many nginx worker processes busy accessing the same shm
zone at exactly the same time. How much such ngx.shared.DICT overhead
can be really depends on your actual data set and use patterns, and
can be very different from app to app.
> I know that logically speaking a shared dict is probably
> going to have less overhead, but I'm wondering if the difference could be
> considered significant.
>
It'll be very hard to do reasonable predictions without knowing data
set and use patterns well enough. And yeah, computer engineering is
hard :) And that's why profiling and experiments are always
recommended.
I think the rule of thumb is that ngx.shared.DICT is usually more
efficient than socket services if we are not doing something special
or stupid :)
> I do know profiling would give me the best answer to this, but I'm just
> thinking about how to architecture some other parts of my application as it
> eventually becomes bigger and wanted to get some general guidance.
>
See above :)
Regards,
-agentzh