NodeJS Driver for BloomD
A NodeJS client for Bloomd
- Complete support for all Bloomd's commands.
- Fast performance: insertion of 235k items in ~600ms on a 2010 MBP, over localhost.
- Familiar interface, similar to node-redis
- A number of useful extensions over and above bloomd's default behaviour:
- [set|bulk|check|multi|info]Safe() commands to automatically create a filter if it doesn't exist when running a filter-specific command.
- Squashing non-existent filter errors on drop.
npm install bloomd
node-bloomd uses stream transforms, and therefore requires Node 0.10 or later.
Create a client, then call bloomd commands directly on it. A simple example:
var bloomd = require'./index'client = bloomdcreateClientclienton'error'console.log'Error:' + errconsole.logdataclientlistnull bloomdprintclientcreate'newFilter' printerclient.info'newFilter' bloomdprintclientcheck'newFilter' 'monkey' printerclientset'newFilter' 'monkey' printerclientcheck'newFilter' 'monkey' printerclientbulk'newFilter' 'monkey' 'magic' 'muppet' printerclientmulti'newFilter' 'monkey' 'magic' 'muppet' printerclient.info'newFilter' bloomdprintclientdrop'newFilter' printerclientdispose
A number of config options are available for the client:
host [127.0.0.1]: The host of bloomd to connect to.
port : The port to connect on.
debug [false]: Outputs debug information to the log.
reconnectDelay : The base amount of time in ms to wait between reconnection attempts. This number is multiplied by the current count of reconnection attempts to give a measure of backoff.
maxConnectionAttempts : The amount of times to try to get a connection to bloomd, after which the client will declare itself unavailable. 0 means no limit.
Pop quiz: Bulk and Multi - which is used for batch checking, and which is used for batch setting? I
can never remember either. node-bloomd helps out by providing two methods to make it explicit:
bulkSet(). Use them. The maintainers of your code will thank you.
Typically, when issuing a
bloomd will respond with "Filter does not exist" if the filter has not been created. node-bloomd
provides 'safe' versions of these commands which auto-create the filter in this situation. These
The method signatures of these are the same as the non-safe equivalent, with the addition of an optional createOptions parameter, which can be used to control the configuration of the filter that might be created.
There is overhead to co-ordinating all this (see below), so if you are sure that a filter exists, you should use the non-safe version of the command.
Subsequent commands issued to the same filter are guaranteed to happen after both the creation command and the safe command that triggered the creation, even if the filter didn't previously exist. For example:
var bloomd = require'./index'client = bloomdcreateClientclientbulkSafe'nonExistent' 'a' 'b' 'c' 'd'console.log'First, we created and bulk set some values'prob: 0.01capacity: 50000clientcheck'nonExistent' 'a'console.log'This will run second, and will be true'
In order to do this, when a safe command is issued, subsequent commands on the same filter are held until we have attempted to create the filter and process the original safe command.
This requires the use of a per-filter sub-queue, which is then processed when both the create command and the originating command has completed. While not a huge overhead, it is certainly slower than just the non-safe version of the command.
In order of speed, from fastest to slowest:
- setSafe(), where the filter already exists.
- setSafe() on a non-existent filter.
Note that a safe command can still fail if the create method fails. Typically, this happens due to bad creation parameters, such as too low a capacity being chosen. To aid with debugging, in this instance, the error passed to the safe command's callback will be the reason that the filter creation failed, not the reason that the safe command failed (which would be, in all cases "Filter does not exist"). Any subsequent commands that were also queued will still fail with "Filter does not exist".
Finally, 'safe' is a terrible designation, and I welcome suggestions for a better name.
- More Error checking.
- Instrumentation and optimisation.
- Better documentation.
- Auto-retry of filter creation when failing due to the filter having recently been dropped.
Questions, comments, bug reports and pull requests are all welcomed.
In particular, improvements that address any of the tasks on the above list would be great.
Copyright 2013 The Obvious Corporation
Licensed under Apache License Version 2.0. Details in the attached LICENSE file.