select vs poll


 
Thread Tools Search this Thread
Special Forums IP Networking select vs poll
# 8  
Old 04-28-2007
Quote:
Originally Posted by smanu
Do you by any chance have any idea about how much performance improvement can be achieved by replacing poll with Asynchronous I/O framework.
Alternatively consider pthreads. If your application takes advantage of threads for concurrent activity it will scale better on SMP hardware.
# 9  
Old 04-28-2007
You sure don't mention many details. Not even which OS you use. "Connections"... so you are awaiting connections from a listen(2)? How many fd's are involved? Lots of connections to lots of fd's is a different problem than lots of connections to a few fd's.

For lots of fd's, select/poll bogs down because massive structures to describe the fd's must be copied between user/kernel space. This is one of several problems addressed be the epoll facility which I have only seen in Linux. (But note that fd_set can be large with modern implementions. People need to stop assuming it is an int!)

Lots of connections to a few fd's can be addressed by not allowing select to get involved with every connection... instead drain the listen queue on the first select. This paper argues that when select(2) returns, accept(2) should be called in loop until it gets EWOULDBLOCK. The authors describe a considerable performance boost. You might want to try this... I thought it sounded very interesting.

Or are you reading and writing on established connections? Assuming your OS has a decent thread implementation, I would try one thread per socket in each direction that data flows.

You ask about asyncronous I/O. Traditionally this is a problem if more than one fd is involved since there is only one SIGPOLL signal to deliver to a process. Sure, you can get the signal and then do poll(2)/select(2) but this is only useful for very sparse data arriving on multiple fd's. And now with threads, perhaps it is not useful at all. Posix defines some new async i/o stuff, but your OS may not have and I have never used the new stuff.
# 10  
Old 04-29-2007
My OS is Solaris 9. But I can also try experimenting on Solaris 10 & if there is any real performance boost, don't you think it would be possible to implement the equivalent things on Solaris 9?
I shall provide more info on no. of connections & fd's tomorrow.
# 11  
Old 04-29-2007
Quote:
Originally Posted by smanu
.... if there is any real performance boost
Rarely does merely switching versions give you a huge performance boost.

I suggest you look at your application architecture and look for bottlenecks.

1. Do you use non-blocking sockets?

2. Do you use threads?

3. Do you parallelise concurrent activity?

4. Do you have large global locks/mutexes?

5. Does your program support SMP?

Quote:
It's easier to improve the performance of a correct program than improve the correctness of a high performing program
# 12  
Old 04-30-2007
I guess, I made my statement ambiguous. I mean: I shall experiment asynchronous I/O, the new feature introduced in Solaris 10 & if that improves perfromance, implement the equivalent stuff in Solaris 9.

Now my question is: shouldn't replacing the synchronous calls with asynchronous ones improve the performance?
# 13  
Old 04-30-2007
Quote:
Originally Posted by smanu
Now my question is: shouldn't replacing the synchronous calls with asynchronous ones improve the performance?
What is performance? Speed of handling a single client connection or total system throughput? You may find one is a trade off against the other.

Also, increasing performance may increase the complexity, robustness and maintainability of your application. It's your decision.

Threads are far easier to manage correctly than signals.

Ironically one way to improve system performance is to make applications do nothing as efficiently as possible. (as in what does an application do when it has nothing to do).
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. What is on Your Mind?

Powerhouses and mainstream poll

This not a joke but a quite serious question to maybe have your point of view about this very topic of content on the net. So I start this poll to ask the users if they can imagine that the so called content industry of former times sooner or later or anyway will regain lost ground or not? Do you... (1 Reply)
Discussion started by: 1in10
1 Replies

2. Shell Programming and Scripting

How to use poll() for I/O multiplex

Hi, guys: I want to write my own shell using C. I am confused about the usage of I/O multiplex. Does anyone know some examples or explain it to me ? Thanks so much (1 Reply)
Discussion started by: tomlee
1 Replies

3. Shell Programming and Scripting

how to poll for new files?

Hi , i have a requirement in which i have to ftp files to unix from windows and vice versa. I have to encrypt files in windows which will then be decrypted in unix and vice versa. Now the process needs to be automated ..therefore when windows server or unix server recieves the files a shell... (5 Replies)
Discussion started by: lifzgud
5 Replies

4. UNIX for Dummies Questions & Answers

Poll data from a file

I have to write a script where I poll a txt file for data (30 min interval) Dependent on the data read, the script should return a message. It should look something like the "code" below: -- do while <data recived> sleep 30m read data from file Done If <data> x return "A" If... (1 Reply)
Discussion started by: ioniCoder
1 Replies

5. Programming

select/poll and Signal Safety

Hi I am struggling to understand why one should use pselect()/ppoll() instead of wrapping an ordinary select() or poll() call around sigprocmask(). The linux man page talks about “race conditions”, but how would such dangers occur? I plan to use poll() for an application (since ppoll() isn't... (0 Replies)
Discussion started by: nopcoder
0 Replies

6. UNIX for Dummies Questions & Answers

Replace select/poll with kqueue/kevent

Hi, As far as I known, kqueue/kevent model can be used to improve the efficiency of systems event dispatching. I m wondering whether kqueue/kevent is same as the real-time OS event model. I also want to know when writing multiplexing app in real-time OS, what APIs need to be used for... (1 Reply)
Discussion started by: bsderss
1 Replies

7. Programming

How to convert the "select" function into a "poll" function

i have a program using the select function but i want to convert it to poll... how can i do this? thanks in advance... :) (1 Reply)
Discussion started by: rbolante
1 Replies
Login or Register to Ask a Question