Nodejs处理请求太慢

时间:2014-01-20 07:14:54

标签: performance node.js apache benchmarking

当我使用apachebench mark检查时,我的nodejs url非常慢。我只得到500 req / sec。我在同一个文件上几乎没有其他功能。随之而来的是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) {
        // 
    }
}

0 个答案:

没有答案