Webserver optimization in linux using pipe
I have written a web server which reads the requested file and writes to the socket. When I read the file I put开发者_JAVA技巧 the content of the file to the user space of OS and, when I write it to the socket again I put the content to the kernel space of the operating system.
So I put it to the user space and again to the kernel space. This seems to be a waste of resources.
- Isn't there a better option? Like directly sending to the kernel space rather than going through user space?
- How can I optimize this process?
- Can I use PIPE to optimize this?
Try those, which can copy data from a file to a socket directly through kernel :
- http://linux.die.net/man/2/sendfile
- http://linux.die.net/man/2/splice
精彩评论