1

My nodejs url is very slow when I check it with apachebench mark. I'm getting only 500 req/sec. where as I have few other functions on the same file. And with that am getting 7000-12000 req/sec

function bid_now(req, res) {
    req.qs = req.url.split('?')[1];
    if (!req.qs) return;
    req.qs = qs.parse(req.qs);

    if (!parseInt(req.qs.auction_id) || !parseInt(req.qs.uid)) return res.end('0');

    if (!objcache['auctions']) objcache['auctions'] = {};
    var auction = objcache['auctions'][req.qs.auction_id];
    if (!auction) return res.end('NO AUCTION ' + req.qs.auction_id);
        auction.last_bidder = [req.qs.uid, '"pcontent"', auction.id, auction.cp_pcontent_points, Math.floor(new Date().valueOf() / 1000)];
    if (!auction.inc_by) auction.inc_by = 0;

    auction.inc_by++;

    if (!objcache['users']) objcache['users'] = {};
    if (!objcache['users'][req.qs.uid]) {
        objcache['users'][req.qs.uid] = {
            negate_points: 0
        }
    }

    objcache['users'][req.qs.uid].negate_points += parseFloat(auction.cp_pcontent_points || 0);
    if (!objcache['current_bidders']) {
        objcache['current_bidders'] = {};
    }

    objcache['current_bidders'][parseInt(req.qs.auction_id, 10)] = parseInt(req.qs.uid, 10);
    res.end(auction.cp_pcontent_points.toString());

    try {
        sync_object_cache();
    } catch (e) {
        // 
    }
}
James Z
  • 12,209
  • 10
  • 24
  • 44
Vinay K
  • 41
  • 4
  • You have `if (!req.qs) return;` in your code. As you don't do `res.send('...')` this request hangs around and probably apache benchmark runs into timeout. The rest doesn't seem to be performance killing IMO, besides `sync_object_cache()` which is not visible to us. – hgoebl Jan 20 '14 at 07:25
  • Thanks, I added res.send(200) , but not finding any difference. And it was working few days back, i was getting 3000 req/ sec. `function sync_object_cache() { if (sync_object_cache.timeout) { clearTimeout(sync_object_cache.timeout); sync_object_cache.timeout = setTimeout(sync_object_cache, intervals.sync_cache); return; } process.send({cmd: 'sync_cache', objcache: objcache}); sync_object_cache.timeout = null; }` And this is the function – Vinay K Jan 20 '14 at 09:36
  • Is there any changes in hosting will be the reason for this?, because 5-6 days back the same code was able to process 3000 req/sec – Vinay K Jan 20 '14 at 09:39
  • possible duplicate of [Why is node.js only processing six requests at a time?](http://stackoverflow.com/questions/12060869/why-is-node-js-only-processing-six-requests-at-a-time) – Paul Sweatte Apr 25 '14 at 02:16

0 Answers0