Chinaunix首页 | 论坛 | 博客
  • 博客访问: 239762
  • 博文数量: 39
  • 博客积分: 199
  • 博客等级: 二等列兵
  • 技术积分: 426
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-25 14:39
个人简介

博客已全部转移至个人站 www.jasonwho.com

文章分类

全部博文(39)

文章存档

2017年(2)

2014年(1)

2013年(28)

2010年(8)

分类: C/C++

2013-01-23 09:46:55


读过挺多select的总结,感觉还是这段比较直白,关注性能的同学可以mark一下。


Generating and reading the select() bit arrays takes time proportional to the largest fd that you provided for select(), the select() call scales terribly when the number of sockets is high. []

Different operating systems have provided different replacement functions for select. These include poll(), epoll(), kqueue(), evports, and /dev/poll. All of these give better performance than select(), and all but poll() give O(1) performance for adding a socket, removing a socket, and for noticing that a socket is ready for IO.

Unfortunately, none of the efficient interfaces is a ubiquitous standard. Linux has epoll(), the BSDs (including Darwin) have kqueue(), Solaris has evports and /dev/poll… and none of these operating systems has any of the others. So if you want to write a portable high-performance asynchronous application, you’ll need an abstraction that wraps all of these interfaces, and provides whichever one of them is the most efficient.

And that’s what the lowest level of the Libevent API does for you. It provides a consistent interface to various select() replacements, using the most efficient version available on the computer where it’s running.

[2]: On the userspace side, generating and reading the bit arrays takes time proportional to the number of fds that you provided for select(). But on the kernel side, reading the bit arrays takes time proportional to the largest fd in the bit array, which tends to be around the total number of fds in use in the whole program, regardless of how many fds are added to the sets in select().


阅读(1671) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~