0

I want to write a gRPC server(c++) which serves as a FTP server in some case. In detail, client requests a file by its name, while server returns the file content if it exists. In traditional socket programming, I can implement zero-copy utilizing sendfile for linux system. It means that the file content would go directly to socket buffer from disk without transferred in user space. But in gRPC world, the socket detail is hidden, which means you might not access the file descriptor behind the socket that is necessary for sendfile:

ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count);

Therefore, I must read the file bytes into memory first and return it in gRPC response afterwards. That's an unnecessary performance loss. I'm wondering if there's any APIs or workaround for it.

1 Answers1

2

Doing a sendfile straight over a low-level grpc socket wouldn't make a lot of sense, as the grpc protocol will itself have a lot of framing around the data being sent. Your data will be naturally chunked and potentially multiplexed with other control data. Therefore, there is no API to do what you want.

Nicolas Noble
  • 699
  • 3
  • 7
  • In my case, server receives request from client with filename and returns the file content if exists. Most of files are large, which might lead to performance loss if data copied from disk to memory and then from memory to network. That's why I need sendfile and I don't think it wouldn't make sense. I think gRPC might be inappropriate option in this case. – Chen Shengkun Jul 30 '21 at 03:30