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!开发者_如何学Go
I think standard CIFS mounts support mmap(2)
on the files (if I read correctly, direct
mode must be off).
If so, your fastest option is probably to open(2)
files as normal, and use sendfile(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 support mmap(2)
.)
Pat Patterson reports an 8% speedup with sendfile(2)
vs write(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.
Assuming your network interfaces on both sides are 1Gbit ethernet or slower, just do anything you like. Your machine will be able to fill them up.
精彩评论