Skip to content

Commit

Permalink
Remove command queue high and low water marks
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Bridgewater committed Oct 28, 2015
1 parent 4e5e463 commit afc4989
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ So please attach the error listener to node_redis.
`client` will emit `drain` when the TCP connection to the Redis server has been buffering, but is now
writable. This event can be used to stream commands in to Redis and adapt to backpressure.

All commands return a boolean if the stream had to buffer or not. If false is returned the stream had to buffer.
If the stream is buffering `client.should_buffer` is set to true. Otherwise the variable is always set to false.
That way you can decide when to reduce your send rate and resume sending commands when you get `drain`.

You can manually control the low water and high water marks by passing ommand_queue_high_water` and `command_queue_low_water` to the client options.
Check the [Node.js streams API](https://nodejs.org/api/stream.html) for further info.
You can also check the return value of each command as it will also return the backpressure indicator.
If false is returned the stream had to buffer.

### "idle"

Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Features
- using .multi / .batch (up to +50% / on Node.js 0.10.x +300%)
- saving small buffers
- Increased coverage to 99% ([@BridgeAR](https://github.com/BridgeAR))
- Refactored manual backpressure control ([@BridgeAR](https://github.com/BridgeAR))
- Removed the high water mark and low water mark. Such a mechanism should be implemented by a user instead
- The `drain` event is from now on only emitted if the stream really had to buffer

Bugfixes

Expand Down
10 changes: 4 additions & 6 deletions examples/backpressure_drain.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
'use strict';

var redis = require('../index'),
client = redis.createClient(null, null, {
command_queue_high_water: 5,
command_queue_low_water: 1
}),
client = redis.createClient(),
remaining_ops = 100000, paused = false;

function op() {
Expand All @@ -14,11 +11,12 @@ function op() {
}

remaining_ops--;
if (client.hset('test hash', 'val ' + remaining_ops, remaining_ops) === false) {
client.hset('test hash', 'val ' + remaining_ops, remaining_ops);
if (client.should_buffer === true) {
console.log('Pausing at ' + remaining_ops);
paused = true;
} else {
process.nextTick(op);
setTimeout(op, 1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/pub_sub.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var redis = require('redis'),
client1 = redis.createClient(), msg_count = 0,
client2 = redis.createClient();

// Most clients probably don't do much on 'subscribe'. This example uses it to coordinate things within one program.
// Most clients probably don't do much on 'subscribe'. This example uses it to coordinate things within one program.
client1.on('subscribe', function (channel, count) {
console.log('client1 subscribed to ' + channel + ', ' + count + ' total subscriptions');
if (count === 2) {
Expand Down
2 changes: 0 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ function RedisClient(stream, options) {
options.detect_buffers = false;
}
this.should_buffer = false;
this.command_queue_high_water = +options.command_queue_high_water || 1000;
this.command_queue_low_water = options.command_queue_low_water | 0;
this.max_attempts = options.max_attempts | 0;
this.command_queue = new Queue(); // Holds sent commands to de-pipeline them
this.offline_queue = new Queue(); // Holds commands issued but not able to be sent
Expand Down
2 changes: 0 additions & 2 deletions test/commands/keys.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ describe("The 'keys' method", function () {

beforeEach(function (done) {
args = args || {};
// This is going to test if the high water is also respected
args.command_queue_high_water = 100;
client = redis.createClient.apply(redis.createClient, args);
client.once("ready", function () {
client.flushdb(done);
Expand Down

0 comments on commit afc4989

Please sign in to comment.