在C / C高性能应用程序的网络服务器++ [英] high performance application webserver in C/C++

查看:436
本文介绍了在C / C高性能应用程序的网络服务器++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有高性能的(理想事件触发和开放源码)Web服务器在C或C ++?

Is there any high performance (ideally evented and open source) web server in C or C++?

我希望能够在使用它,它调用一个方法/函数在我的应用程序与填写HTTP请求类/结构,然后我可以返回填写HTTP响应类/结构给它。

I'd like to be able to use it in that it calls a method/function in my application with a filled out HTTP Request class/struct, and then I can return a filled out HTTP Response class/struct to it.

如果它不是开源的,我需要内置支持长轮询连接,保活等,否则,我认为我可以添加这些东西我自己。

If it isn't open source, I'd need built in support for long-polling connections, keep-alive, etc—otherwise, I think that I can add these things myself.

如果你不知道用的这样的服务器中,你会建议写我自己的Web服务器,以适应任务吗?它的无法的是基于文件的,必须在高性能C / C ++。写入

If you don't know of any such servers available, would you recommend writing my own web server to fit the task? It cannot be file-based, and must be written in high-performance C/C++.

编辑:我想是这样的红宝石杂种的C,如果这能帮助

I'm thinking something like the Ruby Mongrel for C, if that helps.

推荐答案

我对我的工作非常相同的要求,所以我评估了一些解决方案:猫鼬,libmicrohttpd,libevent的。而且我还想着写Nginx的模块。这里是我的调查结果的摘要:

I had the very same requirements for my job, so I evaluated a number of solutions: mongoose, libmicrohttpd, libevent. And I also was thinking about writing nginx modules. Here is the summary of my findings:

nginx的项目页面

我爱这个服务器,并使用了很多。它的性能和资源使用比Apache的,这也是我仍在使用,但计划迁移到nginx的要好得多。

I love this server and use it a lot. Its performance and resource usage is much better than that of Apache, which I also still use but plan migrating to nginx.


  • 很好的可调谐性能。丰富的功能。便携性。

  • 模块API未记录,似乎是非常详细。看到这个 nginx的世界你好模块为例。

  • Nginx的不使用线程,但使用多个进程。这使得写作模块更难,需要学习nginx的API共享内存等。

猫鼬项目


  • 所有服务器的code是单mongoose.c文件(约130K),无依赖性。这是不错的。

  • 每个连接一个线程,所以如果你需要的并发你必须配置大量的线程,即得。高RAM的使用。不是太好。

  • 表现还是不错的,虽然也不例外。

  • API很简单,但你必须自己撰写的所有响应HTTP头,IE浏览器。了解详细的HTTP协议。

libmicrohttpd项目


  • 官方GNU项目。

  • 详细的API,似乎尴尬的我,虽然要简单得多比写nginx的模块。

  • 在保持模式下表现良好(链接到我下面的基准),不保活不是那么好。

libevent的项目页面

LIBEVENT库内置的Web服务器调用evhttp。

Libevent library has built-in web server called evhttp.


  • 这是基于事件的,使用了libevent为。

  • 易于API。自动构造HTTP标头。

  • 正式单线程的。这是主要的缺点。我发现一个黑客,这使得evhttp运行多个实例同时接受来自相同的连接插座。不知道它是所有安全可靠的。

  • 单线程evhttp的性能是令人惊讶的差。多线程劈更好地工作,但仍然不好。

  • It is event based, uses libevent for that.
  • Easy API. Constructs HTTP headers automatically.
  • Officially single-threaded. This is major disadvantage. I've found a hack, which makes several instances of evhttp run simultaneously accepting connections from the same socket. Not sure if it is all safe and robust.
  • Performance of single-threaded evhttp is surprisingly poor. Multi-threaded hack works better, but still not good.

G-WAN项目是不开源的,但我想说一下几句话。

G-WAN project is not open source, but I'd like to say a few words about it.


  • 非常不错的表现,低内存占用,150 KB的可执行文件。

  • 非常方便servlet的部署:只需复制.c文件到CSP目录,并正在运行的服务器会自动编译它。 code修改还编上飞。

  • 简单的API。虽然受限于某些方面。丰富的功能(JSON,key-value存储,等等)。

  • 不稳定。我对静态文件段错误。挂在一些示例脚本。 (经历了干净安装。不同版本的混合从未文件)。

  • <击>只有32位二进制(不再)。

  • Very good performance, low memory usage, 150 KB executable.
  • Very convenient 'servlet' deployment: just copy .c file into csp directory, and running server automatically compiles it. Code modifications also compiled on the fly.
  • Simple API. Although constrained in some ways. Rich functionality (json, key-value store, etc.).
  • Unstable. I had segfaults on static files. Hangs on some sample scripts. (Experienced on clean install. Never mixed files of different versions).
  • Only 32-bit binary (not anymore).

因此​​,大家可以看到,没有现有的替代品已经完全满足了我。所以,我已经开发了我自己的服务器,这是...

So as you can see, none of existing alternatives have fully satisfied me. So I have developed my own server, which is ...

NXWEB项目

功能亮点:


  • 非常不错的表现;看到项目页面上的基准

  • 可以服务于数以万计的并发请求

  • 小内存占用

  • 多线程模型设计规模

  • 超轻code基

  • 的简单API

  • 体面HTTP协议处理

  • 保持连接

  • 支持SSL(通过GNUTLS)

  • HTTP代理(与保持活动连接池)

  • 非阻塞发送文件支持(可配置的小文件,内存缓存,gzip的pre-CN $ C $光盘文件服务)

  • 模块化设计,开发

  • 可运行的后台程序;重新推出本身的误差

  • 开启源

限制:


  • <击>取决于libev库<​​/击>(不再)

  • 仅在Linux测试

这篇关于在C / C高性能应用程序的网络服务器++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆