Code Monkey home page Code Monkey logo

luves's Introduction

Luves

Build Status

Luves是一个轻量级的事件触发网络库,封装了Socket,简化基于Socket程序开发。目标是封装了以下三种事件的响应:IO事件,定时器事件,信号事件。支持跨平台,OS X环境使用kqueue模型,Linux环境使用Epoll模型,实现半同步/半异步(HSHA)服务器框架模型。

将自己理解的网络框架以"学习"的标准实现,简化复杂网络库的细节部分,实现网络库的本质,必要的地方注释了代码实现思路,欢迎提PR或更好的建议。

	make
	g++ -std=c++11 test_echo.cpp -L/usr/local/lib  -lluves

简单的Echo服务器

	#include "luves/luves.h"
	using namespace luves;

	Buffer GetInput(const TcpConnectionPtr & conn)
	{
			return conn->GetInputBuffer();
	}

	int main()
	{
			EventLoop loop;
	 		Ip4Addr server_addr("0.0.0.0", 6543);
			TcpServer server(&loop, server_addr);
			server.SetReadCb(GetInput);

			server.SetWriteCb([](const TcpConnectionPtr & conn)
                  		{conn->Send(conn->GetInputBuffer());});

			server.RunServer();
			loop.loop();
	}
  • 使用ApacheBench测试:

      @ubuntu:~$ ab -n 10000 -c 10  -k  http://0.0.0.0:6543/
    
  • 测试结果:

      Server Software:
      Server Hostname:        0.0.0.0
      Server Port:            6543
    
      Document Path:          /
      Document Length:        0 bytes
    
      Concurrency Level:      10
      Time taken for tests:   2.998 seconds
      Complete requests:      10000
      Failed requests:        0
      Keep-Alive requests:    0
      Total transferred:      0 bytes
      HTML transferred:       0 bytes
      Requests per second:    3335.80 [#/sec] (mean)
      Time per request:       2.998 [ms] (mean)
      Time per request:       0.300 [ms] (mean, across all concurrent requests)
      Transfer rate:          0.00 [Kbytes/sec] received
    
      Connection Times (ms)
            		min  mean[+/-sd] median   max
      Connect:        0    0   1.2      0      77
      Processing:     0    3   4.6      2      78
      Waiting:        0    0   0.0      0       0
      Total:          1    3   4.7      2      79
    

Version 0.01

  • 原型开发,目前使用kqueue,暂支持OS X系统,实现半同步半异步服务器框架.封装了IO事件与定时事件。
  • 实现跨平台,添加Linux平台的Epoll模块。
  • 修复多线程日志bug
  • 修复Hsha模式下kqueue模块bug

MIT

luves's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.