bugsnag / bugsnag-agent

A forwarding agent for BugSnag to guarantee minimal reporting impact.
MIT License
14 stars 9 forks source link

Sending thread can't send errors fast enough #4

Closed jesseschalken closed 9 years ago

jesseschalken commented 9 years ago

If a large volume of errors are sent to bugsnag-agent for a period of time, the queue quickly hits 1000 because the sending thread can't send them to bugsnag fast enough.

Is there a way the HTTP request to notify.bugsnag.com could be done asynchronously so the sending thread doesn't have to wait for the response from bugsnag for one error before sending the next?

Alternatively, could multiple sending threads be used?

jesseschalken commented 9 years ago

I was Googling how to make async HTTP requests in Python and ended up at https://twistedmatrix.com. It seems this also includes a HTTP server so you could probably ditch the threads and queue and do it all async.

ConradIrwin commented 9 years ago

Hey @jesseschalken. I've bumped the limit up to 10, which should be more than enough.

jesseschalken commented 9 years ago

@ConradIrwin That would do the trick.

I also wrote this Node.js script to submit errors without the arbitrary limits (# of threads, queue size).

var http = require('http'),
    https = require('https');

var count = 0;

var agent = new https.Agent();
agent.maxSockets = 100;

var server = http.createServer(function (req, res) {
    var body = '';
    req.on('data', function (chunk) { body = body + chunk; });
    req.on('end', function () {
        res.end('okay. ' + body.length + ' bytes received.');

        count++;
        console.log('recv (' + count + ' pending)');

        var req = https.request({
            host: 'notify.bugsnag.com',
            headers: {'content-type': 'application/json'},
            method: 'POST',
            agent: agent
        }, function (res) {
            var body = '';
            res.on('data', function (chunk) { body = body + chunk; });
            res.on('end', function () {
                count--;
                console.log('send (' + count + ' pending)');

                if (res.statusCode < 200 || res.statusCode >= 300)
                    console.error(res.statusCode + ' ' + res.statusMessage + ' ' + JSON.stringify(body));
            });
        });
        req.on('error', function (e) {
            count--;
            console.error(e);
        });
        req.end(body);
    });
});

server.listen(3829, '127.0.0.1', function () {
    console.log('HTTP server started');
});