my8bird / node-leveldb

NodeJS bindings to levelDB - a fast and lightweight key/value database library
http://code.google.com/p/leveldb/
BSD 2-Clause "Simplified" License
63 stars 12 forks source link

share the same leveldb database between nodejs cluster processes #21

Closed twojcik closed 12 years ago

twojcik commented 12 years ago

Hi, I know that sharing the same leveldb instance between various processes is discouraged, but I was wondering if it could work in case of node.js core cluster where only master process would update database and workers would only query db. Did anyone tried that?

Cheers,

mikepb commented 12 years ago

leveldb locks the database file so multiple processes will not be able to open it. There is only support for multiple thread accesses to a database in the underlying library. There is no support for concurrent database access from multiple processes.

You could spawn a dedicated Node.js process for leveldb and use IPC to access the database as described, but unless and until the leveldb itself supports multiple processes, it is not currently possible to access a database from multiple processes.

twojcik commented 12 years ago

Thanks @mikepb. In that case I'll find other way to do want I want:).

mikepb commented 12 years ago

You could try to use ØMQ with the as_buffer option to do what you want: https://github.com/JustinTulloss/zeromq.node

I'm not sure how faster a Node.js core cluster would be, though.