How to Write Linux Friendly Async Socket I/O


 
Thread Tools Search this Thread
Top Forums Programming How to Write Linux Friendly Async Socket I/O
# 1  
Old 05-24-2007
How to Write Linux Friendly Async Socket I/O

I am presently refactoring a windows deamon with an eye towards porting it to linux someday.

Presently the application uses a single background thread and asynchronous socket I/O to implement FTP and HTTP clients in a single switch statement (2000 lines and 100 cases just for the switch statement).

We need to be able to handle 4000 FTP/HTTP servers simultaneously (worst case).

I was going to rewrite this using synchonous socket I/O and lots of threads but I hear that this does not scale well.

Since this is presently a windows app, I was going to use BindIoCompletionCallback thinking that Microsoft implemented this function because they could do it more efficiently than I can (perhaps it is implemented in the kernel?). BindIoCompletion is a function that accepts a socket handle and a function pointer and automagically grabs a thread from a automagically managed thread queue and has the thread execute it when the I/O is complete.

Does the Linux/UNIX API have anything similar to this?

What is the recommmended approach in Linux/UNIX?
(1) A single thread and Async I/O
(2) Lots of threads and synch I/O?
(3) A few threads and async I/O?

Thanks,
Siegfried
# 2  
Old 05-24-2007
Your main limit will be the number of file descriptors per process. If a process can only have 256 then you may only be able to have around 250 clients max with a few other fds doing other things (like stdio, listen/accept)

Don't use SIGIO, it's a pain to get right and you end up having to call select anyway.

Write a single threaded application that uses select to handle multiple connections, but run a number of copies and each have a listener bound to the same port (SO_REUSEADDR).

Use non-blocking IO so you never sit waiting for send/receive.
# 3  
Old 05-25-2007
I suggest you to try SOLARIS 10 port-events mechanism

http://developers.sun.com/solaris/ar...ompletion.html

best regards
Mipko
# 4  
Old 05-25-2007
The event mechanism is implemented in the Linux, but it isn't portable of all olther Unix basic OS.
http://www.die.net/doc/linux/man/man4/epoll.4.html

The asynchronous mechanism is implemented in most Unix basic OS.
http://www.freebsd.org/cgi/man.cgi?q...SE&format=html

The article "The C10K problem" is usefully for you.
http://kegel.com/c10k.html


Best regards,
Iliyan Varshilov

Last edited by ilko_partizan; 05-25-2007 at 08:17 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Socket dual client/server Linux

I'm trying to make a "dual/server client" (ipv4,ipv6) with sockets in linux but i don't know how to join both codes. I have a dual client ipv4 and ipv6, but i have problems with the server if you notice the only difference between them it's the AF_INET (pf_inet ipv4, and if_inet6 ipv6) and the port... (3 Replies)
Discussion started by: godna
3 Replies

2. Shell Programming and Scripting

Read and write to tcp socket

Hello all, I have a requirement to read and write to a tcp socket from an HP-UX shell script. I see a /dev/tcp character device on my servers: crw-rw-rw- 1 root root 72 0x00004f Mar 28 18:37 /dev/tcp So I believe this is what I should use. The problem is that all the... (2 Replies)
Discussion started by: lupin..the..3rd
2 Replies

3. IP Networking

Packets sent from Linux TCP socket

Hello, Our software is using a TCP socket (AF_INET, SOCK_STREAM) to communicate with an Ethernet device. When we send a message, the message object writes itself in full onto the socket's stream buffer before the software invokes send() from socket.h. I'm still researching, but have 2... (1 Reply)
Discussion started by: bix_20002000
1 Replies

4. Programming

write on Non Blocking Socket

How to know whether socket is ready for write. select(maxfds, (fd_set *)NULL, &writefds, NULL, &timeout); By default socket is set for write without checking whether it would block or not? If so how do I know my FD is ready for writing. (3 Replies)
Discussion started by: satish@123
3 Replies

5. Programming

help me about sending file through socket udp with c in linux

hi, i am newbie of socket. i want to ask some question. if i want to send file from client to server, how do i do? and if i want to send file from server to client, how do i do? any pro help me and if possible, you can post code for an example i need it very much thank you for helping me:)... (1 Reply)
Discussion started by: tung1984
1 Replies

6. Programming

Write-Write on a socket

Can anyone tell what happens if each end writes at the same time on the same socket ? - if one of them issues a read() after write() has completed, will it record into the buffer what the other sent ? ex. e1 writes to e2 - - - while - - - e2 writes to e1 (at the same time) e1 read () - what... (1 Reply)
Discussion started by: gendaox
1 Replies

7. Programming

Help needed linux socket programming in c

Good evening everyone! :) I'm doing a small client / server application for sharing files in C, and I am trying to implement the following: The client of my application sends to the address 255.255.255.255 a message requesting a particular file.In the network there is only one server,... (1 Reply)
Discussion started by: esmeco
1 Replies

8. IP Networking

Can we write a multiple thread to receive from a single socket file descriptor

Hi Friends, I have written a program which will listener for more than 1000 requests per second from a single socket descriptor and then it will process those requestes. Its taking X amount of time. Now i want to reduce that time. Will I can write multiple threads to receive the... (2 Replies)
Discussion started by: pa.chidhambaram
2 Replies

9. UNIX for Advanced & Expert Users

Fedora Linux for Socket Program Development

Hi, I am trying to port a networking application to linux, I get error while binding a socket to a port, The port is not used by any application and was verified by using netstat and other tools. I tried a simple socket and bind on a unused port, but even that fails. Is there any document... (0 Replies)
Discussion started by: venkatesh.n
0 Replies

10. Programming

read/write socket error

I have client and server connected. client write and read from csock. server write and read from ssock suppose the server does : .... close(ssock); //send FIN to client othertask(); .... READ ERROR if after the server close() the client does: ... read(csock,...); ...... (2 Replies)
Discussion started by: gio
2 Replies
Login or Register to Ask a Question