You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Remove command queue high and low water marks
This commit is contained in:
@@ -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
|
`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.
|
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`.
|
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.
|
You can also check the return value of each command as it will also return the backpressure indicator.
|
||||||
Check the [Node.js streams API](https://nodejs.org/api/stream.html) for further info.
|
If false is returned the stream had to buffer.
|
||||||
|
|
||||||
### "idle"
|
### "idle"
|
||||||
|
|
||||||
|
@@ -10,6 +10,9 @@ Features
|
|||||||
- using .multi / .batch (up to +50% / on Node.js 0.10.x +300%)
|
- using .multi / .batch (up to +50% / on Node.js 0.10.x +300%)
|
||||||
- saving small buffers
|
- saving small buffers
|
||||||
- Increased coverage to 99% ([@BridgeAR](https://github.com/BridgeAR))
|
- 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
|
Bugfixes
|
||||||
|
|
||||||
|
@@ -1,10 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var redis = require('../index'),
|
var redis = require('../index'),
|
||||||
client = redis.createClient(null, null, {
|
client = redis.createClient(),
|
||||||
command_queue_high_water: 5,
|
|
||||||
command_queue_low_water: 1
|
|
||||||
}),
|
|
||||||
remaining_ops = 100000, paused = false;
|
remaining_ops = 100000, paused = false;
|
||||||
|
|
||||||
function op() {
|
function op() {
|
||||||
@@ -14,11 +11,12 @@ function op() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
remaining_ops--;
|
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);
|
console.log('Pausing at ' + remaining_ops);
|
||||||
paused = true;
|
paused = true;
|
||||||
} else {
|
} else {
|
||||||
process.nextTick(op);
|
setTimeout(op, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@ var redis = require('redis'),
|
|||||||
client1 = redis.createClient(), msg_count = 0,
|
client1 = redis.createClient(), msg_count = 0,
|
||||||
client2 = redis.createClient();
|
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) {
|
client1.on('subscribe', function (channel, count) {
|
||||||
console.log('client1 subscribed to ' + channel + ', ' + count + ' total subscriptions');
|
console.log('client1 subscribed to ' + channel + ', ' + count + ' total subscriptions');
|
||||||
if (count === 2) {
|
if (count === 2) {
|
||||||
|
2
index.js
2
index.js
@@ -82,8 +82,6 @@ function RedisClient(stream, options) {
|
|||||||
options.detect_buffers = false;
|
options.detect_buffers = false;
|
||||||
}
|
}
|
||||||
this.should_buffer = 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.max_attempts = options.max_attempts | 0;
|
||||||
this.command_queue = new Queue(); // Holds sent commands to de-pipeline them
|
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
|
this.offline_queue = new Queue(); // Holds commands issued but not able to be sent
|
||||||
|
@@ -15,8 +15,6 @@ describe("The 'keys' method", function () {
|
|||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
args = args || {};
|
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 = redis.createClient.apply(redis.createClient, args);
|
||||||
client.once("ready", function () {
|
client.once("ready", function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
|
Reference in New Issue
Block a user