slow http performance

5 views
Skip to first unread message

Jeff Rose

unread,
Jul 30, 2013, 6:36:00 PM7/30/13
to node-...@googlegroups.com
Hi,
  I'm trying to use couchdb from node-webkit, and the http request performance is considerably slower then in the browser or with node.js.  (Code pasted below...)  For a basic document insert it typically takes about 20-30ms using the http module in node or with jquery from the browser, but from node-webkit it is taking more like 1500-2000ms.  This is on OSX with the latest nw release.  If anyone has any ideas or pointers to the problem it would be great to figure out what is causing this slowdown.

Thanks,
Jeff


Example code:

var http = require('http')
var util = require('sys')

function now() {
    return new Date().getTime();
}


function node_test(id) {
    var t = now();
    var req = http.request({hostname: "127.0.0.1", port: 5984, path: "/foo/" + id, method: "PUT", agent: false},
            function(res) {
                res.setEncoding('utf-8');
                console.log('RESPONSE: ' + res.statusCode);
                console.log(util.inspect(res.headers));
                res.on('data', function(v) { console.log('BODY:' + v + '\ninsert time: ' + (now() - t))});
            });

    req.write('{"_id" : "' + id + '", "biz": "boz"}');
    req.end();
}

node_test(Math.floor(Math.random()*1000000));


function jquery_test(id) {
      var t = now();
        $.ajax({
                url: 'http://127.0.0.1:5984/foo/' + id,
                type: 'PUT',
                data: '{"_id" : "' + id + '", "biz": "boz"}',
        }).done(function(res) {
              console.log('RES: ' + res)
               console.log('jquery insert time: ' + (now() - t));
        });
}

jquery_test(Math.floor(Math.random()*1000000));
Reply all
Reply to author
Forward
Message has been deleted
0 new messages