I would like to write a server that reads in a file from a NAS and sends it out over
a socket. What is the fastest way of doing this?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think standard CIFS mounts support
mmap(2)on the files (if I read correctly,directmode must be off).If so, your fastest option is probably to
open(2)files as normal, and usesendfile(2)to send the file data over your UDP sockets. (sendfile(2)requires the file to mappable, which isn’t always guaranteed, but the CIFS client code in the kernel (fs/cifs/file.c:cifs_file_strict_mmap()) appears to supportmmap(2).)Pat Patterson reports an 8% speedup with
sendfile(2)vswrite(2). But if it works, it’d save you the hassle of handling AIO operations yourself — the kernel would be in charge of requesting memory pages from the file, sending them over the socket when the socket buffers allow, and hopefully allow your application code to be short and sweet.