Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest socket method for a lot of data between a lot of files

I'm building a socket application that need to shuffle a lot of small/medium sized files, something like 5-100kb sized files to a lot of different clients (sort of like a web server, but still not quite).

Should I just go with the standard poll/epoll (linux) or async sockets in winsock (win32), or are there any methods with even more performance around (overlapped i/o on win32 for example) ?

Both Linux and Windows are possible platforms!

like image 597
thr Avatar asked Feb 27 '23 23:02

thr


1 Answers

On Linux, demultiplexing multiple sockets using epoll is the fastest possible way to do parallel I/O over TCP.

But I'll also mention that in the interest of portability, (and since you seem to be interested in either Linux or Windows), you should look into Boost.Asio. It has a portable API, but uses epoll on Linux and overlapped I/O on windows, so you can built highly efficient and portable networking apps.

Also since you're working with files, you should also implement double buffering when performing I/O for maximum performance. In other words, you send / recv each file using two buffers. For example, on the sending side, you read from disk into one buffer and then send that buffer over the network, while another thread reads the next block of data from disk into the second buffer. This way you overlap disk I/O with network I/O.

like image 152
Charles Salvia Avatar answered Mar 05 '23 16:03

Charles Salvia