skynet简单测试QPS记录

简单调用skynet的QPS的记录,仅供参考。

1. 简单调用 math.random

local math = require "math"
local skynet = require "skynet"

skynet.start(function()
    local v = nil
    local count = 0
    local t = skynet.now()
    while skynet.now() - t < 100*10 do
        count = count + 1
        v = math.random(3,3)
    end

    local time = (skynet.now()-t) / 100

    print("v", v)

    print("time", time, "count", count, "per", count/time)
end)

结果

time 1.0 count 10889947 per 10889947.0

2. 简单调用 skynet.call

local skynet = require "skynet"
require "skynet.manager"    -- import skynet.register

skynet.start(function()
    local sdb = skynet.newservice("simpledb", "agent")
    skynet.call("SIMPLEDB", "lua", "SET", "a", "foobar")

    local v = nil
    local count = 0
    local t = skynet.now()
    while skynet.now() - t < 100*10 do
        count = count + 1
        v = skynet.call("SIMPLEDB", "lua", "GET", "a")
    end

    local time = (skynet.now()-t) / 100

    print("v", v)

    print("time", time, "count", count, "per", count/time)

    skynet.exit()
end)

结果

time 10.0 count 1021166 per 102116.6

3. 简单调用 cluster.call

local skynet = require "skynet"
require "skynet.manager"    -- import skynet.register
local cluster = require "skynet.cluster"

skynet.start(function()
    local sdb = skynet.newservice("simpledb", "agent")
    skynet.call("SIMPLEDB", "lua", "SET", "a", "foobar")

    cluster.open "db"
    cluster.register("sdb", sdb)

    local proxy = cluster.proxy "db@sdb"

    local v = nil
    local count = 0
    local t = skynet.now()
    while skynet.now() - t < 100*10 do
        count = count + 1
        -- v = cluster.call("db", "SIMPLEDB", "GET", "a")
        v = skynet.call(proxy, "lua", "GET", "a")
    end

    local time = (skynet.now()-t) / 100

    print("v", v)

    print("time", time, "count", count, "per", count/time)

    skynet.exit()
end)

结果

time 10.0 count 52784 per 5278.4

4. 简单调用 redis mq

service服务 simplemq.lua

local skynet = require "skynet"
require "skynet.manager"    -- import skynet.register
local redis = require "skynet.db.redis"

local conf = {
    host = "127.0.0.1" ,
    port = 6379 ,
    db = 11
}

local function process()
    print("process...")
    local db = redis.connect(conf)
    while true do
        local task_json = db:brpop("test_queue", 0)
        -- print("task_json", task_json[2])
        db:lpush(task_json[2], "secessed")
    end
end

skynet.start(function()
    skynet.dispatch("lua", function(session, address, cmd, ...)
        cmd = cmd:upper()
        if cmd == "PING" then
            assert(session == 0)
            local str = (...)
            if #str > 20 then
                str = str:sub(1,20) .. "...(" .. #str .. ")"
            end
            skynet.error(string.format("%s ping %s", skynet.address(address), str))
            return
        end
        local f = command[cmd]
        if f then
            skynet.ret(skynet.pack(f(...)))
        else
            error(string.format("Unknown command %s", tostring(cmd)))
        end
    end)

    skynet.timeout(
        100,
        function()
            process()
        end
    )

end)

调用测试

local skynet = require "skynet"
require "skynet.manager"    -- import skynet.register
local cluster = require "skynet.cluster"
local redis = require "skynet.db.redis"

local conf = {
    host = "127.0.0.1" ,
    port = 6379 ,
    db = 11
}

-- 添加任务到任务队列
local function call(db, queue_name, task_name)
    db:lpush(queue_name, task_name)
    local result = db:brpop(task_name, 3)
    return result[2]
end

skynet.start(function()
    skynet.newservice("simplemq", "agent")

    local db = redis.connect(conf)

    local v = nil
    local count = 0
    local t = skynet.now()
    while skynet.now() - t < 100*10 do
        count = count + 1
        v = call(db, "test_queue", "test_queue_result_".. tostring(skynet.now()))
    end

    local time = (skynet.now()-t) / 100

    print("v", v)

    print("time", time, "count", count, "per", count/time)

    skynet.exit()
end)

结果

time 10.0 count 13821 per 1382.1

5. 结果列表:

调用 QPS 相对于上项的% 备注
math.random 10889947.0 -
skynet.call 102116.6 0.94 -
cluster.call 5278.4 5.17 -
redis mq 1382.1 26.17 redis满载了,skynet单核70%,用python测试也差不多
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,323评论 19 139
  • java 基础 JDK1.8新特性 Lambda表达式 函数式接口 方法引用和构造器调用 Stream API 接...
    __Covet阅读 2,790评论 0 0
  • 1.启动 1.1windows版本启动命令 redis-server.exe ./redis.windows.co...
    渡边Hok阅读 3,959评论 0 0
  • 1.1 资料 ,最好的入门小册子,可以先于一切文档之前看,免费。 作者Antirez的博客,Antirez维护的R...
    JefferyLcm阅读 17,180评论 1 51
  • 1、谈谈对http协议的认识流程:1.域名解析域名解析检查顺序为:浏览器自身DNS缓存---》OS自身的DNS缓存...
    Zzmi阅读 4,149评论 0 0