• luanet性能测试


    测试环境 intel-i5 双核 2.53HZ 服务器客户端均在本机运行

    测试内容:echo回射,每个包的字节数在20字节内

    luanet

    连接数    每秒回射数            
    1         19,000/s
    10        12,5000/s
    100       12,0000/s
    1000      80,000/s 
    

    node.js

    连接数    每秒回射数            
    1         27,000/s
    10        30,000/s
    100       30,000/s
    1000      27,000/s

    luvit

    连接数    每秒回射数            
    1         16,500/s
    10        74,000/s
    100       75,000/s
    1000      51,000/s

    从测试结果上看只有在1个连接的情况下luanet不如node.js,当连接数上去之后 luanet每秒的回射数基本都在

    node.js的3倍左右.在所有的连接数下都比luvit 高30%以上.

    node.js:echo.js

     var net = require('net');
        var server = net.createServer(function(c) { // 'connection' 监听器
          console.log('一个新连接');
          c.on('end', function() {
            console.log('连接断开');
          });
          c.on('data',function(data){
            c.write(data);
          });
          c.on('close',function(){
              console.log('连接断开');
          });   
          c.on('error',function(e){
          });  
        });
        server.listen(8010, function() { // 'listening' 监听器
          console.log('服务器监听8010');
        });

    luvit:echo.lua

    local net = require('net')
    
    net.createServer(function (client)
      -- Echo everything the client says back to itself
      client:pipe(client)
    end):listen(8010)
    
    print("TCP echo server listening on port 8010")

    luanet:echoserver.lua

    local cjson = require "cjson"
    
    function on_data(s,data,err)
        if not data then
            print("a client disconnected")
            C.close(s)
        else
            local tb = cjson.decode(data)
            C.send(s,cjson.encode(tb),nil)
        end
    end
    
    function on_newclient(s)
        print("on_newclient")
        if not C.bind(s,{recvfinish = on_data})then
            print("bind error")
            C.close(s)
        end
    end
    
    C.listen(IPPROTO_TCP,SOCK_STREAM,net.netaddr_ipv4("127.0.0.1",8010),
             {onaccept=on_newclient})

    统一的测试客户端:echoclient.lua

    local net = require "lua/netaddr"
    local cjson = require "cjson"
    local Sche = require "lua/scheduler"
    local count = 0
    
    function on_data(s,data,err)
        if not data then
            print("a client disconnected")
            C.close(s)
        else
            count = count + 1
            local tb = cjson.decode(data)
            C.send(s,cjson.encode(tb),nil)
        end
    end
    
    function on_connected(s,remote_addr,err)
        print("on_connected")
        if s then
            if not C.bind(s,{recvfinish = on_data}) then
                print("bind error")
                C.close(s)
            else
                print("bind success")
                C.send(s,cjson.encode({"hahaha"}),nil)
            end
        end 
    end
    print("echoclient")
    for i=1,1 do
        C.connect(IPPROTO_TCP,SOCK_STREAM,net.netaddr_ipv4("127.0.0.1",8010),
                  nil,{onconnected = on_connected},3000)
    end
    
    local tick = C.GetSysTick()
    local now = C.GetSysTick()
    while true do 
        now = C.GetSysTick()
        if now - tick >= 1000 then
            print(count*1000/(now-tick) .. " " .. now-tick)
            tick = now
            count = 0
        end
        Sche.Sleep(50)
    end

    luanet rpc测试:客户端调用服务端的Plus函数,函数只是把客户端提供的两个参数相加并返回

    平均每秒rpc调用次数在6,8000左右.而用C+协程实现的版本在70,0000左右.我试着用luajit来运行 同样的测试,非常意外的是性能差了一大截,

    只有可怜的2,000次,具体原因还在调查中.

    测试代码:server.lua,client.lua

  • 相关阅读:
    对 getaddrinfo Android 返回错误 EAI_BADFLAGS
    getaddrinfo详解
    使用moment.js管理时间
    ejs循环实例
    Express优化-合并路由
    Express重定向
    Express中间件
    express.Router创建模块化路由
    Express路由
    nodejs + express访问静态资源
  • 原文地址:https://www.cnblogs.com/sniperHW/p/3701525.html
Copyright © 2020-2023  润新知