1

我们公司正计划从 REDIS 过渡到 Aerospike,但我们发现一些奇怪的问题是缺少 get 请求(只有 35% 的人返回回调函数)。

这是我们正在测试的代码:

var cluster = require('cluster');
var numCPUs = require('os').cpus().length;

if (cluster.isMaster) 
{
    for (var i = 0; i < numCPUs; i++) 
    {
        var worker = cluster.fork();
    }
} 
else 
{

    var start = new Date().getTime();
    var requests = 0;
    var responses = 0;

    var aerospike = require('./node_modules/aerospike');
    var status = aerospike.status;

    var client = aerospike.client({
        hosts: [
            { addr: '127.0.0.1', port: 3000 } 
        ]
    });

    function connect_cb( err, client) {
        if (err.code == status.AEROSPIKE_OK) {
            console.log("Aerospike Connection Success")
        }
    }

    client.connect(connect_cb)

    setInterval(function(){
        for(var i=0; i<50; i++)
        {
            var key = aerospike.key('dexi','toys','floor_'+i);
            requests++;
            client.get(key, function(err, rec, meta) {
                responses++;
                if ( err.code == status.AEROSPIKE_OK ) 
                {

                }
                else 
                {
                    console.error('Get Error:', err);
                }
            });


        }
    },10);

    setInterval(function(){
        for(var i=0; i<50; i++)
        {
            var key = aerospike.key('dexi','toys','floor_'+i);
            var rec = { 
              uid:    1000,  // integer data stored in bin called "uid"
              name:   "user_name", // string data stored in bin called "user_name"
              dob:    { mm: 12, dd: 29, yy: 1995},  // map data stored (msgpack format) in bin called "dob" 
              friends: [1001, 1002, 1003]
             };

            var metadata = {
                ttl: 10000,
                gen: 0
            };
            client.put(key, rec, metadata, function(err) {
                switch ( err.code ) {
                    case status.AEROSPIKE_OK:
                        break;

                    default:
                        console.error("Put Error: " + err.message);
                        exitCode = 1;
                        break;
                }
            });
        }
    },10);

    setInterval(function(){
        var timeSpent = ( new Date().getTime()) - start;
        console.log(requests, responses,timeSpent);
    },15000);

}

下面是我们看到的控制台输出:

34400 9306 15098
34150 9250 15080
35050 9330 15087
34150 9235 15092
33250 9310 15120
33950 9249 15090
34650 9298 15101
35000 9400 15102
34700 9300 15166
33150 9399 15181
34500 9300 15193
33850 9292 15207
34400 9250 15162
34100 9360 15212
34050 9250 15171
34100 9348 15159
33800 9250 15118
34300 9309 15189
34050 9300 15152
34250 9405 15181

如您所见,平均而言,对于我们发送的每 35k 获取请求,我们只看到其中一小部分实际返回。我们的 Aerospike 仪表板也反映了差异(仅看到 35% 的被发送),因为吞吐量反映了我们得到的响应。

4

0 回答 0