Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Socket select ( ) question

2 views
Skip to first unread message

Eyal Ben gal

unread,
Feb 4, 2004, 3:20:03 AM2/4/04
to
Hi,

I'm looking for a better design.
Every time before I call the select function I have to initialize an array
with all my socket,

I have to do it each time before calling the select.
This is not a problem in case of 10 socket.

But in case of server handling 2500 sockets it is not affeciant each time
before the select to go through this sockets and build from them an array.

Looking for your comments,

Thanks,

Eyal.


Fernando Gont

unread,
Feb 4, 2004, 5:55:13 AM2/4/04
to
On Wed, 4 Feb 2004 10:20:03 +0200, "Eyal Ben gal"
<eyalb...@hotmail.com> wrote:

>I have to do it each time before calling the select.
>This is not a problem in case of 10 socket.
>But in case of server handling 2500 sockets it is not affeciant each time
>before the select to go through this sockets and build from them an array.

Save the arguments you pass to select() and you won't have to "build"
them again.

--
Fernando Gont
e-mail: fern...@ANTISPAM.gont.com.ar

[To send a personal reply, please remove the ANTISPAM tag]

p...@icke-reklam.ipsec.nu

unread,
Feb 4, 2004, 11:57:37 AM2/4/04
to
Eyal Ben gal <eyalb...@hotmail.com> wrote:
> Hi,

> Looking for your comments,

Use 2500 processes instead. ( or like apache a number of processeses
handling some decent number each)

Process-handling in unix is cheap.

> Thanks,

> Eyal.

--
Peter Håkanson
IPSec Sverige ( At Gothenburg Riverside )
Sorry about my e-mail address, but i'm trying to keep spam out,
remove "icke-reklam" if you feel for mailing me. Thanx.

Barry Margolin

unread,
Feb 4, 2004, 12:21:42 PM2/4/04
to
In article <4020...@news.bezeqint.net>,

"Eyal Ben gal" <eyalb...@hotmail.com> wrote:

Use something like this:

fd_set master_list, cur_list;

FD_SET(&master_list, fd1);
FD_SET(&master_list, fd2);
...

while (<whatever>) {
cur_list = master_list;
result = select(nfds, &cur_list, NULL, NULL, NULL);
...
}

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

James Carlson

unread,
Feb 6, 2004, 9:24:56 AM2/6/04
to
"Eyal Ben gal" <eyalb...@hotmail.com> writes:
> But in case of server handling 2500 sockets it is not affeciant each time
> before the select to go through this sockets and build from them an array.

Even if you "fix" that to build them once, you'll end up copying a lot
of data in and out of the kernel on each iteration.

You didn't say what operating system you were using. Some
implementations have alternative interfaces (e.g., poll(7D) on
Solaris, kqueue on BSD) that are much more efficient.

--
James Carlson, IP Systems Group <james.d...@sun.com>
Sun Microsystems / 1 Network Drive 71.234W Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757 42.497N Fax +1 781 442 1677

Barry Margolin

unread,
Feb 6, 2004, 4:13:45 PM2/6/04
to
In article <xoav3c9o...@sun.com>,
James Carlson <james.d...@sun.com> wrote:

> "Eyal Ben gal" <eyalb...@hotmail.com> writes:
> > But in case of server handling 2500 sockets it is not affeciant each time
> > before the select to go through this sockets and build from them an array.
>
> Even if you "fix" that to build them once, you'll end up copying a lot
> of data in and out of the kernel on each iteration.
>
> You didn't say what operating system you were using. Some
> implementations have alternative interfaces (e.g., poll(7D) on
> Solaris, kqueue on BSD) that are much more efficient.

Poll() would need to copy even *more* data into and out of the kernel on
each iteration. Poll's data structure is more efficient when you're
only polling a few FD's, but since he's up in the thousands I'd expect
select() to be more efficient in that respect.

Then again, on most implementations select() is just a library wrapper
around poll() or vice versa; it's unlikely that both would be
implemented natively in the kernel. It probably would pay to use
whichever one is native in the kernel, to avoid lots of data translation.

However, there are other considerations beside just the data copying.
After select() returns, you have to go into a loop calling FD_ISSET() on
each FD, and this can take a while if there are thousands to check. I
don't recall poll()'s return structure -- does it just return the FD's
that are ready?

James Carlson

unread,
Feb 7, 2004, 4:47:30 PM2/7/04
to
Barry Margolin <bar...@alum.mit.edu> writes:
> > implementations have alternative interfaces (e.g., poll(7D) on
> > Solaris, kqueue on BSD) that are much more efficient.
>
> Poll() would need to copy even *more* data into and out of the kernel on
> each iteration. [...]

Please re-read. I said "poll(7D)," not "poll(2)."

There's a big difference.

0 new messages