Jacko
Jacko

Reputation: 13195

Linux: what is the most efficient way of reading a file from a NAS and sending over a socket

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!

Upvotes: 0

Views: 1048

Answers (2)

MarkR
MarkR

Reputation: 63548

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.

Upvotes: 0

sarnold
sarnold

Reputation: 104080

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.

Upvotes: 1

Related Questions