Reasons for slow recv call

I am writing two applications (in C) that make several calls to send and receive (for example, I implement a remote copy of the file).

I always send a 64 byte header that contains the length of the next message body and some other information.

When testing my application on some files, I realized that some recv calls take a lot of time (about 40 ms ). Using strace, I found out that this happens first when sending a message body of 377 bytes (which in this case copies the entire contents of my file).

The server application starts sending the body of the message, which takes about 48 of us . The client application now consumes about 38 ms to receive these bytes.

From this time on, each call consumes so much time, since each of them blocks the reception and awaits a response.

server network

[pid 27158] 1292236124.465827 send (6, "\ 0 \ 0 \ 1 \ 271 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0core.fwrite \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 "..., 64, 0) = 64 <0,000031>

[pid 27158] 1292236124.466074 send (6, "\ 0 \ 0 \ 0 \ 1 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 10 \ 0 \ 0 \ 0 \ 1 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 1 \ 0 \ 0 \ 0 \ 0 "..., 377, 0) = 377 <0,000048>

client network

[pid 27159] 1292236124.466364 recv (4, "\ 0 \ 0 \ 1 \ 271 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0core.fwrite \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 "..., 64, 0) = 64 <0,000027>

[pid 27159] 1292236124.466597 recv (4, "\ 0\0\0\1\0\0\0\0\0\0\0\0\0\0\0\10\0\0\0\1\0\0\0\0\0\0\0\1\0\0\0\0"..., 377, 0) = 377 < 0,037456 >

, , .

.

+3
2

Nagle. , , . .

+7

, Nagle. , , , "" . , , "", , , .

, , , - . ( ) " - ". . , - , - . , . , , , , , . 64- . .

. , A, B , .

. , , , .

0

Source: https://habr.com/ru/post/1779985/


All Articles