If you are using the Puma webserver for your Ruby app (Rails or otherwise), then you should take some additional steps due to the multi-threaded runtime being used. This applies to all threaded webservers for Ruby, not just Puma.
Dalli by default uses a single connection to each server. This works fine normally, but can become a bottleneck in a multi-threaded environment and limit performance. In this case, Dalli supports connection pooling, where multiple connections are created to MemCachier’s servers. To use this, start by adding the
connection_pool gem to your Gemfile:
Next, you’ll need to set the
:pool_size configuration option when setting up Dalli. For example, in Rails your configuration would become:
Where the number 5 should be chosen according to how many threads you will be running and the available concurrency on the machines running your webserver.