On Wed, 17 Mar 2010 16:53:11 +0000 Sad Clouds <cryintotheblue...@googlemail.com> wrote:
> This is because it is common for web server to send many small text > files to many concurrent clients. You could fit several of those files > in a socket's TCP send buffer. Only if you have pipelined requests. In case of pipelining you can send multiple files in a row and writev(2) will do for you. You wane use writev(2) anyway, as you have to send HTTP headers in front of each file. Without pipelining you have a request - response - request - response - etc. sequence. A new request will only be sent after the client received the complete response. And completely forget about sending those pipelined files to multiple clients simultaneously in a single system call. This will only work if all clients request the same files in the same sequence at about the same time. To filter out matching client connections will cost more CPU power then handling each client in a separate writev(2). Also don't forget that browsers usually use multiple connections to the same server to fetch multiple parts of a page. E.g. if you have a page with four JPEGs the browser will not issue a single pipelined request for those four JPEGs, but open for concurrent connections to the server and request each JPEG on a separate TCP stream. > On a busy server you cache the most frequently accessed files in > memory, so the data is ready to be sent down the TCP sockets. Todays web pages are 99.9% dynamic. Even if they seem to be static at first sight. Think of CMS etc.. Delivering a file like a bitmap picture or PDF from disk is an exeption. In that case you wane do mmap(2) and write(2) / writev(2). On NetBSD this is equivalent to what Linux calls sendfile(2). The VM subsytem will take care of caching etc. for you and it will do better then you as it knows better then you how much physical memory is free at the moment etc.. E.g. thttpd(8) does this: Files get mmap(2)ed. Headers get written to a malloc(3)ed buffer. Then the headers and the file are sent with a single writev(2) using non-blocking IO. -- tschüß, Jochen Homepage: http://www.unixag-kl.fh-kl.de/~jkunz/