Skip to content

Commit afc4989

Browse files
author
Ruben Bridgewater
committed
Remove command queue high and low water marks
1 parent 4e5e463 commit afc4989

File tree

6 files changed

+11
-14
lines changed

6 files changed

+11
-14
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ So please attach the error listener to node_redis.
154154
`client` will emit `drain` when the TCP connection to the Redis server has been buffering, but is now
155155
writable. This event can be used to stream commands in to Redis and adapt to backpressure.
156156

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

160-
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.
161-
Check the [Node.js streams API](https://nodejs.org/api/stream.html) for further info.
160+
You can also check the return value of each command as it will also return the backpressure indicator.
161+
If false is returned the stream had to buffer.
162162

163163
### "idle"
164164

changelog.md

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

1417
Bugfixes
1518

examples/backpressure_drain.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
'use strict';
22

33
var redis = require('../index'),
4-
client = redis.createClient(null, null, {
5-
command_queue_high_water: 5,
6-
command_queue_low_water: 1
7-
}),
4+
client = redis.createClient(),
85
remaining_ops = 100000, paused = false;
96

107
function op() {
@@ -14,11 +11,12 @@ function op() {
1411
}
1512

1613
remaining_ops--;
17-
if (client.hset('test hash', 'val ' + remaining_ops, remaining_ops) === false) {
14+
client.hset('test hash', 'val ' + remaining_ops, remaining_ops);
15+
if (client.should_buffer === true) {
1816
console.log('Pausing at ' + remaining_ops);
1917
paused = true;
2018
} else {
21-
process.nextTick(op);
19+
setTimeout(op, 1);
2220
}
2321
}
2422

examples/pub_sub.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var redis = require('redis'),
44
client1 = redis.createClient(), msg_count = 0,
55
client2 = redis.createClient();
66

7-
// Most clients probably don't do much on 'subscribe'. This example uses it to coordinate things within one program.
7+
// Most clients probably don't do much on 'subscribe'. This example uses it to coordinate things within one program.
88
client1.on('subscribe', function (channel, count) {
99
console.log('client1 subscribed to ' + channel + ', ' + count + ' total subscriptions');
1010
if (count === 2) {

index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ function RedisClient(stream, options) {
8282
options.detect_buffers = false;
8383
}
8484
this.should_buffer = false;
85-
this.command_queue_high_water = +options.command_queue_high_water || 1000;
86-
this.command_queue_low_water = options.command_queue_low_water | 0;
8785
this.max_attempts = options.max_attempts | 0;
8886
this.command_queue = new Queue(); // Holds sent commands to de-pipeline them
8987
this.offline_queue = new Queue(); // Holds commands issued but not able to be sent

test/commands/keys.spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ describe("The 'keys' method", function () {
1515

1616
beforeEach(function (done) {
1717
args = args || {};
18-
// This is going to test if the high water is also respected
19-
args.command_queue_high_water = 100;
2018
client = redis.createClient.apply(redis.createClient, args);
2119
client.once("ready", function () {
2220
client.flushdb(done);

0 commit comments

Comments
 (0)