How to use MongoDB as a pure in-memory DB
edgystuff.tumblr.com
edgystuff.tumblr.com
Basically you're wasting RAM and introducing yet another moving part. What happens then is: on each "write" MongoDB touches a page in RAM which maps to a block in tmpfs file which maps back to the same RAM page which maps to a block in a swap.
Why? If you have enough RAM to hold your working set, just use MongoDB directly with async writes and you won't be blocked by disk I/O. You will get blocked by the global DB lock, but that's another story.
EDIT: edited the sequence of mappings.
> The reason is that Linux is smart and it does not duplicate the pages between tmpfs and its cache
From you:
> MongoDB touches a page in RAM which maps to a block in tmpfs
These two statements sound contradictory to me.
The OP did mention the security angle, i.e. the database is never written to a disk, so perhaps there's some convenience there.
This would improve security and reduce the potential attack surface if this were used for ephemeral mongodb instances, but only in that it would prevent poor programming practices from lasting beyond a working session.
I'm a little confused about how you are wasting RAM. tmpfs lives entirely in the page cache and mmaped files are always page cache resident as well so they always map to the same page cache. It is possible that file system overhead will be less as tmpfs is simpler but maybe you should simply change the mongodb source code to mmap the database anonymously without a file backing in the first place.
In should be noted that if you really want a database that exists in RAM without messing with the filesystem mounts, SQLite supports this out of the box: http://www.sqlite.org/inmemorydb.html
Not to mention the hoops you have to go through to administer this setup. Mongodb is already essentially tuned for working sets that fit in memory. If your disk is a bottleneck after turning after data durability(journaling,fsync etc) you are doing something wrong.
Redis at the very least would be far better for this use case.
Please never use this as an excuse to store credit card numbers or track two data in the clear.
Why? Mongodb does offer secondary indices among other useful features.
That being said, I'm keeping an eye on HyperDex (http://hyperdex.org).
I actually don't understand why it's so slow - running it on a server with 256GB of RAM, writes are still disk-bound. Why aren't the disk writes running in a subtask? Yes, I'm running with write confirm off.
Anyway, if you need the speed of Redis, use Redis.
However, the performance was not great, as it had to go through the VFS layer, everything was in blocks and emulated a filesystem.