Ruby open shared memory block

2019-09-11 03:12发布

问题:

Is there a way to open shared memory block with Ruby, equivalent to shmop_open in PHP?

I have one process periodically update a memory block. My Rails app needs to read those data.

回答1:

You have a few options as gems, but I've never used them myself.

sysvmq implements System V IPC message queues.

posix-mqueues implements POSIX message queues.



回答2:

Maybe try hammerspace

We use this as a caching layer for translations and configurations on our production machines.

You can have one process that periodically updates the hammerspace files, and then all the rails processes can consume it. The file gets memorymapped when hammerspace accesses it, so it is defacto shared memory.

See https://github.com/airbnb/hammerspace