Rails and copy-on-write
When Linux forks new processes, variables will be symbol linked until they got modified.
So if you are going to serve some static (read-only) data structure in Rails, you could just load them in an initializer, rather than using an external server such as Redis.
The memory address will be symbol linked to all workers so there is no duplicated memory waste. Don’t be fooled by
htop. You need to use
pmap -x or this script to see the how many memory is “really” being used.
This OS-level optimization offers great speed, throughput advantages over application-level solutions such as Redis. For 300MB of data, you are likely to get a 5x better performance in every aspect.