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

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

问题描述

是否有使用 C 或 C++ 编写的高性能(最好是事件化和开源)Web 服务器?

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 语言的 Ruby Mongrel 之类的东西.

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

推荐答案

我对我的工作有非常相同的要求,所以我评估了许多解决方案:mongoose、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.

  • 非常好的可调性能.功能丰富.便携性.
  • Module API 没有记录,而且似乎非常冗长.以 nginx hello world 模块为例.
  • Nginx 不使用线程,而是使用多个进程.这使得编写模块变得更加困难,需要学习用于共享内存的 nginx API 等.

猫鼬项目页面

  • 所有服务器的代码都在单个 mongoose.c 文件中(大约 130K),没有依赖项.这很好.
  • 每个连接一个线程,所以如果你需要并发,你必须配置很多线程,即.RAM使用率高.不太好.
  • 表现不错,但并不出色.
  • API 很简单,但您必须自己编写所有响应 HTTP 标头,即.详细了解 HTTP 协议.

libmicrohttpd 项目页面

  • 官方 GNU 项目.
  • 详细的 API,对我来说似乎很笨拙,虽然比编写 nginx 模块要简单得多.
  • 在 keep-alive 模式下性能良好(链接到下面我的基准测试),没有 keep-alive 时表现不佳.

libevent 项目页面

Libevent 库具有名为 evhttp 的内置 Web 服务器.

Libevent library has built-in web server called evhttp.

  • 它是基于事件的,为此使用 libevent.
  • 简单的 API.自动构造 HTTP 标头.
  • 官方单线程.这是主要的缺点.我发现了 一个 hack,这使得多个 evhttp 实例同时运行,接受来自同一个插座.不确定它是否安全可靠.
  • 单线程 evhttp 的性能出奇地差.多线程 hack 效果更好,但仍然不好.
  • 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 目录中,运行服务器就会自动编译它.代码修改也会即时编译.
  • 简单的 API.虽然在某些方面受到限制.丰富的功能(json、键值存储等).
  • 不稳定.我在静态文件上有段错误.挂在一些示例脚本上.(有干净安装经验.从不混合不同版本的文件).
  • 只有 32 位二进制(不再).

如您所见,现有的替代方案都没有让我完全满意.所以我开发了自己的服务器,这是...

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

NXWEB 项目页面

功能亮点:

  • 性能非常好;查看项目页面上的基准
  • 可以处理数以万计的并发请求
  • 内存占用小
  • 可扩展的多线程模型
  • 极其轻量的代码库
  • 简单的 API
  • 体面的 HTTP 协议处理
  • 保持活动连接
  • SSL 支持(通过 GNUTLS)
  • HTTP 代理(带保持连接池)
  • 非阻塞发送文件支持(具有可配置的小文件内存缓存;gzip 预编码文件服务)
  • 面向开发人员的模块化设计
  • 可以作为守护进程运行;出错时重新启动
  • 开源

限制:

  • 依赖于 libev 库(不再)
  • 仅在 Linux 上测试

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

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