在哪里可以找到不同网络架构的基准?
在哪里可以找到不同网络架构的基准?
我正在使用套接字/线程/叉子,我想知道最好的是什么。我想一定有一个地方,有人已经阐明了套接字服务的不同架构的所有优点和缺点,列出了运行代码的基准。
最终,我想用我自己的代码运行这些不同的配置,看看哪种配置在不同的情况下运行最好。
与我交谈的许多人都说我应该只使用单线程选择。但是,当您在线程内存储状态信息以保持代码简单时,我看到了线程的一个论点。编写自己的状态结构与使用经过验证的线程架构的权衡标准是什么?
我还被告知分叉是不好的...但是当您在一台无法提高每个进程打开文件限制的计算机上需要 12000 个连接时,分叉是一种选择!当您有一个进程需要重新启动时,分叉也是一种不错的稳定性选择,它不会干扰其他进程。
抱歉,这是我较长的问题之一......很多变量都留空。
谢谢, 陈兹
Where can I find benchmarks on different networking architectures?
I am playing with sockets / threads / forks and I'd like to know what the best is. I was thinking there has got to be a place where someone has already spelled out all the pros and cons of different architectures for a socket service, listed benchmarks with code that runs.
Ultimately I'd like to run these various configurations with my own code and see which runs best in different circumstances.
Many people I talk to say that I should just use single threaded select. But I see an argument for threads when you're storing state information inside the thread to keep code simple. What is the trade off mark for writing my own state structure vs using a proven thread architecture.
I've also been told forking is bad... but when you need 12000 connections on a machine that cannot raise the open file per process limit, forking is an option! Forking is also a nice option for stability when you've got one process that needs restarting, it doesn't disturb the others.
Sorry, this is one of my longer questions... so many variables are left empty.
Thanks,
Chenz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:这是我正在寻找的链接,这是回答您问题的整篇论文。 http://www.kegel.com/c10k.html
有一些网络服务器是按照所有设计的三种模型(fork、thread、select)。人们喜欢对网络服务器进行基准测试。
http://www.lighttpd.net/benchmark
Libevent 有一些基准测试和链接,内容涉及如何选择 select() 与线程模型,通常倾向于使用 libevent 模型。
http://monkey.org/~provos/libevent/
edit: here's the link I was looking for, which is a whole paper answering your question. http://www.kegel.com/c10k.html
There are web servers designed along all three models (fork, thread, select). People like to benchmark web servers.
http://www.lighttpd.net/benchmark
Libevent has some benchmarks and links to stuff about how to choose a select() vs. threaded model, generally in favour of using the libevent model.
http://monkey.org/~provos/libevent/
回答这个问题非常困难,因为很大程度上取决于您的服务实际在做什么。是否必须查询数据库?从文件系统读取文件?执行复杂的计算?去和其他服务交谈吗?另外,客户端连接的寿命有多长?连接是否可能与其他连接有某种语义交互,或者它们都被视为彼此独立?您稍后是否需要考虑在多个服务器之间对服务进行负载平衡? (如果是这样,您现在可能会有效地考虑这一点,以便从一开始就可以设计任何必要的帮助。)
正如您所暗示的,服务机器可能存在与各种技术相互作用的限制,引导您走向一个或另一个答案。您有每个进程的文件描述符限制,但请记住您也可能有固定大小的进程表!无论如何,您预计有多少并发客户端?
如果您的服务不断崩溃并且需要不断重新启动它,或者您认为需要多进程模型以便连接彼此隔离,那么您可能做错了。在这种情况下,稳定性极其重要,这意味着良好的实践和内存卫生,无论是在一般情况下还是在面对基于网络的攻击时。
记住历史…… fork() 在 Unix 世界中很便宜,但在 Windows 上生成新进程相对昂贵。 OTOH,Windows 线程是轻量级的,而线程对于 Unix 来说一直有点陌生,直到最近才变得普遍。
It's very difficult to answer this question as so much depends on what your service is actually doing. Does it have to query a database? read files from the filesystem? perform complicated calculations? go off and talk to some other service? Also, how long-lived are client connections? Might connections have some semantic interaction with other connections, or are they all treated as independent of each other? Might you want to think about load-balancing your service across multiple servers later? (If so, you might usefully think about that now so that any necessary help can be designed in from the start.)
As you hint, the serving machine might have limits which interact with the various techniques, steering you towards one answer or another. You have a per-process file descriptor limit, but remember that you may also have a fixed size process table! How many concurrent clients are you expecting, anyway?
If your service keeps crashing and you need to keep restarting it or you think you want a multi-process model so that connections are isolated from each other, you're probably doing it wrong. Stability is extremely important in this sort of context, and that means good practice and memory hygiene, both in general and in the face of network-based attacks.
Remember the history... fork() is cheap in the Unix world, but spawning new processes relatively expensive on Windows. OTOH, Windows threads are lightweight, whereas threading has always been a bit alien to Unix and only relatively recently become widespread.