C/C++ 中的高性能应用程序 Web 服务器
有没有用 C 或 C++ 编写的高性能(理想情况下事件化且开源)Web 服务器?
我希望能够使用它,因为它使用填写的 HTTP 请求类/结构调用我的应用程序中的方法/函数,然后我可以向它返回填写的 HTTP 响应类/结构。
如果它不是开源的,我需要内置对长轮询连接、保持活动等的支持,否则,我认为我可以自己添加这些东西。
如果您不知道有任何此类服务器可用,您会建议编写我自己的 Web 服务器来完成任务吗?它不能是基于文件的,并且必须用高性能C/C++编写。
编辑:我正在考虑类似 C 的 Ruby Mongrel 之类的东西,如果有帮助的话。
Is there any high performance (ideally evented and open source) web server in C or C++?
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.
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++.
Edit: I'm thinking something like the Ruby Mongrel for C, if that helps.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我对我的工作有完全相同的要求,因此我评估了许多解决方案:mongoose、libmicrohttpd、libevent。我也在考虑编写 nginx 模块。以下是我的发现摘要:
nginx
nginx 项目页面
我喜欢这个服务器并且经常使用它。它的性能和资源使用率比 Apache 好得多,我仍然在使用 Apache,但计划迁移到 nginx。
mongoose
mongoose 项目页面
libmicrohttpd
libmicrohttpd 项目页面
libevent
libevent 项目页面
Libevent 库有内置的 Web 服务器,称为 evhttp。
G-WAN
G-WAN 项目不是开源的,但我想简单说一下。
仅 32 位二进制(不再是)。正如您所看到的,现有的替代方案都没有让我完全满意。于是我开发了自己的服务器,那就是...
NXWEB
NXWEB 项目页面
功能亮点:
限制:
依赖于 libev 库(不再是)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
nginx project page
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.
mongoose
mongoose project page
libmicrohttpd
libmicrohttpd project page
libevent
libevent project page
Libevent library has built-in web server called evhttp.
G-WAN
G-WAN project is not open source, but I'd like to say a few words about it.
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
NXWEB project page
Feature highlights:
Limitations:
Depends on libev library(not anymore)我建议编写一个可以与许多高性能 Web 服务器(甚至闭源服务器)一起使用的 FastCGI 可执行文件。
I would suggest to write a FastCGI executable that can be used with many high performance web servers (even closed source ones).
猫鼬:一个文件。简单易用。不是 asycn io,但非常适合嵌入式和特殊用途。
关。出色的。没有崩溃。超精心规划的配置。非常智能且易于 C/C++ 开发,换句话说,与 nginx 相比,它的 api 非常干净、合理。每个核心提供一个线程。或您指定的任何内容。一个很好的选择。最大的缺点(也许我在这方面缺乏):无法单步执行代码。
libevent:单线程在单核机器上并不是劣势。毕竟它的重点是异步 I/O。其他核心确实有多线程。
nginx:没有个人经验。在不完整的服务器上取得了重大进展。 (非常令人困惑的 api)
boost asio:asynchio (asio) 的 C++ 库。惊人的。对于像我这样的傻瓜来说,需要一个友好的高级 API。以及来自 php、java、javascript、node.js 和其他 Web 语言的其他人。
python Bottle:很棒的 1 文件库(框架/系统),可以轻松构建 python Web 应用程序。有/是一个内置的 httpd 服务器,如 libevent 和 node.js
node.js:javascript 异步服务器。一个很好的选择。不幸的是,必须使用 javascript 进行编程,这确实变得乏味。虽然为了完成工作还有一些话要说;还有一些话要说,让自己在这个过程中享受乐趣。希望没有人提出node.php
mongoose: one file. simple and easy to use. not an asycn io but perfect for embedded and particular purposes.
gwan. excellent. no crashes. ultra well planned configuration. very smart and easy for c/c++ development in other words, very clean sensible api compared to nginx. provides a thread per core. or whatever you specify. a great choice. largest disadvantage (maybe im lacking in this area): cannot step thru code.
libevent: single thread is not a disadvantage on a single core machine. afterall its point is an async i/o. does have multithreads for other cores.
nginx: no personal experience. gaining serious ground on a-patchy server. (terribly confusing api)
boost asio: a c++ library for asynchio (asio). awesome. needs a friendly higher-level api for simpletons like myself. and others who come from php, java, javascript, node.js and other web languages.
python bottle: awesome 1 file lib (framework/system) that makes it easy to build python web apps. has/is a built in httpd server, like libevent and node.js
node.js: javascript asyncio server. an excellent selection. unfortunately, have to program in javascript that does become tedious. while there is something to be said for getting the job done; there is also something to be said for enjoying yourself during the process. hopefully no ones comes up with node.php
我将提出与 Axel Gneiting 相同的建议 - 但已经提供了我采用这种方法的原因的答案:
1)HTTP 作为协议并不简单 - 编写自己的服务器或修改现成的解决方案是一项非常复杂的任务 - 比使用可用的 API 来实现单独的处理引擎复杂得多
2)使用(未经修改的)主流网络服务器应该为您提供比您需要的更多的功能(因此您有成长的空间)。
3)使用(未经修改的)主流网络服务器通常意味着它比自制系统经过了更广泛的测试和记录。
4) ..并且它更有可能是安全和稳定的。
5) 使用 fastCGI,您可以使用各种语言来开发后端处理 - 包括 C++ 和 C。有 标准工具包可用于促进这一点。
6) 另外,许多网络服务器提供对进程内运行解释器引擎的支持(例如 mod_php、mod_perl)。不过,我建议不要将自己的本机代码作为模块运行。
呃?这意味着什么?
I'm going to suggest the same thing as Axel Gneiting - but have provided an answer with my reasons for taking this approach:
1) HTTP is not trivial as a protocol - writing your own server or amending an off-the-shelf solution is a very complex task - a lot more complex than using the available APIs for implementing a separate processing engine
2) Using (an unmodified) mainstream webserver should provide you with more functionality than you require (so you've got growing room).
3) Using (an unmodified) mainstream webserver will usually mean that it has been far more extensively tested and documented than a homebrew system.
4) .. and its more likely to be secure and stable.
5) Using fastCGI you can use all sorts of languages to develop your back-end processing in - including C++ and C. There are standard toolkits available to facilitate this.
6) alternatively many webservers provide support for running interpreter engines in-process (e.g. mod_php, mod_perl). I'd advise against running your own native code as a module though.
Eh? What does that mean?
我是一个狂热的 nginx 用户; nginx是用C语言编写的; nginx 似乎可以为你工作。如果你想要 nginx 的最佳速度,我会制作一个 nginx 模块。以下是 第 3 方模块,您可以检查它们以了解它需要什么。
至于长轮询要求,您可能想看看 http 推送模块。
I'm an avid nginx user; nginx is written in C; nginx seems like it could work for you. If you want the very best speed out of nginx, I would make a nginx module. Here are 3rd party modules which you can examine to get an idea of what it requires.
As for the long polling requirement, you might want to have a look at the http push modules.