Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 44f1ac8

Browse files
committed
Send 500 events at a time and wait between sends.
1 parent 0211438 commit 44f1ac8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/cube/emitter-http.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ module.exports = function(protocol, host, port) {
99
if (protocol != "http:") throw new Error("invalid HTTP protocol");
1010

1111
function send() {
12-
var event = queue.shift();
13-
if (!event) return;
12+
var events = queue.splice(0, 500);
13+
if (events.length === 0) return;
1414

15-
var body = JSON.stringify(event);
15+
var body = JSON.stringify(events);
1616

1717
var postOptions = {
1818
host: host,
@@ -26,11 +26,12 @@ module.exports = function(protocol, host, port) {
2626
};
2727

2828
var postRequest = http.request(postOptions, function(res) {
29-
if (queue.length) process.nextTick(send);
29+
if (queue.length) setTimeout(send, 500);
3030
});
3131

3232
postRequest.on('error', function (e) {
3333
console.warn(e.message);
34+
// TODO: Add events back to queue on error
3435
});
3536

3637
postRequest.write(body);

0 commit comments

Comments
 (0)