为什么响应在使用Jmeter进行负载测试时变为空?

时间:2016-11-18 10:53:02

标签: node.js mongodb jmeter async-await

我正在研究Node.js api的负载测试操作,我正在根据我的要求进行操作,请仔细阅读。

搜索API结构。

我的收藏中有商家列表,我根据用户搜索查询搜索商家详情。

阿比

/api/user/57887cc8755f3c4390a5fg908/search/rajesh

回复

{
   "merchants": [{
       "_id": "5790ea87b29cf246a27345de",
       "checkins": [],
       "name": "Rajesh",
       "address": "landing",
       "phone": 123456789,
       "description": "hello",
       "location": {
           "latitude": "0",
           "longitude": "0"
        }
   }]
}

Jmeter API结果

当我用100个线程组在jmeter中测试这个api时,对于某些组商家[]变空了,我不知道在进行负载测试时发生了什么。

负载测试截图

150个线程组

enter image description here

加载测试结果(商家数组为空)

enter image description here

部分请求的结果

enter image description here

Node.js代码

exports.searchMerchantLocation = function(req, res) {
var total_lat = 0;
var total_long = 0;
var merchant_count = 0;
var search_suggestions = {};
var location = {
    latitude: decodeURIComponent(req.params.lat),
    longitude: decodeURIComponent(req.params.long)
}
var radius = req.params.zoom;
var responseJSON = {
    merchants: []
}
async.waterfall([
    function(callback) {
        User.findById(req.params.id, callback);
    },
    function(user, callback) {
        if (user == null) {
            return res.json(messages.not_found("user"))
        }
        radius *= globals.miles2meters;
        Merchant.find({}, 'location description name phone address timings', callback);
    },
    function(merchants, callback) {

        if (merchants.length == 0) {
            return res.json(messages.not_found("merchants"));
        }
        async.each(merchants, function(merchant, done) {
            search_suggestions["merchants"] = [];

            var dist;
                if (JSON.stringify(merchant.location) === '{}'){
                    dist = radius + 100;
                }
                else {
                    dist = geolib.getDistance({ latitude: location.latitude, longitude: location.longitude }, { latitude: merchant.location.latitude, longitude: merchant.location.longitude });
                }
                if (dist < radius) {
                    Checkin.find({ merchant: merchant._id, is_active: true }, "user").populate("user", "firstname lastname").exec(function(err, checkins) {
                        if (err) {
                            return callback(err);
                        }
                        if(JSON.stringify(merchant.location) !== '{}'){
                            merchant_count += 1;
                            total_lat += merchant.location.latitude;
                            total_long += merchant.location.longitude;
                            var temp = {
                                "_id": merchant._id,
                                "checkins": checkins,
                                "name": merchant.name,
                                "timings": merchant.timings,
                                "address": merchant.address,
                                "phone": merchant.phone,
                                "description": merchant.description,
                                "location": {
                                    "latitude": merchant.location.latitude,
                                    "longitude": merchant.location.longitude
                                }
                            }
                            search_suggestions["merchants"].push(temp);
                            done();
                        }
                        else{
                            done();
                        }

                    })
                }
                else{
                    done();
                }
        }, callback);
    }
], function(err, results) {
    if (err) {
        return res.json({
            error: "database error",
            message: err.toString()
        })
    }
    setTimeout(function(){
        return res.json(search_suggestions);
    }, 1000);
})
 }

请仔细阅读我的帖子并向我推荐一些解决方案。

0 个答案:

没有答案