Coder Social home page Coder Social logo

erikluo / httpevent Goto Github PK

View Code? Open in Web Editor NEW

This project forked from b-xiang/httpevent

0.0 3.0 0.0 338 KB

web server and c++/lua web framework

License: MIT License

Makefile 0.23% Shell 0.10% C++ 98.24% C 0.58% Lua 0.54% HTML 0.21% CSS 0.10% JavaScript 0.01%

httpevent's Introduction

httpevent

c++ and lua web framework

此项目以升级为hi-nginx.. 欢迎更新!!!

缘起

httpevent是webcppd的继承者。

由于webcppd内核采用的是Poco内置的多线程服务器,虽然性能不错,但是依然存在不小的提升空间。

httpevent不仅包含webcppd的全部特性,而且改进和增加了新的功能

主要改进

httpevent主要在以下三个方面了改进了webcppd:

  • 内核采用libevent2,性能倍增,稳定性更好,对信号处理更友好
  • handler采用基于libevent2的轻包装类,不再受限于Poco。
  • 不仅轻松支持C++开发,而且轻松支持lua开发

基本特性

  • HTTP 1.1
  • HTTPS
  • 支持多种服务器类型选择,可通过配置文件轻松配置
    • 0=static
    • 1=0+dynamic
    • 2=1+session
    • 3=1+cache
    • 4=3+session
    • 5=all
    • default=5
  • c++ 开发
  • lua 开发(支持lua v5.1,v5.2,v5.3以及luajit)
  • 会话管理
  • 自动缓存管理
  • ip动、静态黑名单
  • 正则路由(PCRE)
  • 防盗链
  • 日志

lua api

使用方法参见plugin/lua

  • httpevent.response : lua 对象实例

    • send_head
    • send_body
  • httpevent.request : lua 对象实例

    • get_client
    • get_method
    • get_uri
    • get_user_agent
  • httpevent.ROUTE : 一个 lua 表

  • httpevent.CONFIG : 一个 lua 表

  • httpevent.form_tool : lua 对象实例 包含GET,POST,可上传域为upload的文件

    • has
    • get
  • httpevent.cookie_tool : lua 对象实例

    • has
    • set
    • get
  • httpevent.session_tool : lua 对象实例

    • has
    • set
    • get
  • httpevent.util_tool : lua 对象实例

    • error
    • submit
    • redirect

c++ hello world

#include <httpevent.hpp>
namespace httpevent {
    class hello : public view {

        void handler(const request& req, response& res) {
            res.send_head("Content-Type", "text/plain;charset=UTF-8")
                    .send_body("hello,world");
        }

    };
}

lua hello world

local hello={}
function hello.main()
  httpevent.response:send_head("Content-Type", "text/plain;charset=UTF-8")
    :send_body('hello,world')
end

return hello

服务器选型

  • 做纯静态文件服务器,推荐0型
  • 作后端应用服务器,推荐1、2、3、4型,视乎业务需要选择是否需要缓存管理器或(和)会话管理器
  • 作通用服务器,推荐选择默认的5型

自动缓存服务

httpevent提供系统级的缓存服务,对于3、4、5型服务器,只要没有调用submit方法,系统都将自动缓存内容。 一旦调用submit方法,系统就会认为该内容无需缓存。

压力测试

以下数据以3型服务器为基准,压力测试工具为ab(ubuntu 16.10,i5-5200U,4G,笔记本)

  • c++ hello world

      ab -c500 -n 50000 http://localhost/
      Requests per second:    24538.13 [#/sec] (mean)
    
  • lua hello world

      ab -c500 -n 50000 http://localhost/demo/hello.lua
      Requests per second:    20470.11 [#/sec] (mean)
    

依赖

  • libevent v2.1.8+
  • Poco framework v1.6+
  • lua devel v5.1+
  • openssl devel

安装

build.sh

配置

/etc/httpevent/httpevent.properties

运行

sudo systemctl enable httpevent

sudo systemctl (start|stop|restart|status) httpevent

优化使用建议

  • C/C++可能比lua更适合需要密集计算的业务
  • 尽量使用通用性较强的路由规则,缩短路由表的长度
  • 绝不要require包含lua api的模块,用dofile替代

httpevent's People

Watchers

James Cloos 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.