Random latency between headers and POST body

We use NSUrlConnection sendAsynchronousRequest to send simple POST requests to our Node JS server. After analyzing tcpdumps, we noticed that sometimes the request headers and the request body are divided into 2 separate TCP packets.

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:url]]; [request setTimeoutInterval:3]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-type"]; [request setHTTPBody:postData]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler: ^(NSURLResponse *response, NSData *POSTReply, NSError *error) { }]; 

The problem is that sometimes headers are sent to the server, which opens a connection to our API, and then after a few seconds the body packet is sent. We see a 1 second delay between the headers and the body, randomly every hundreds of server-side requests. This is the biggest source of latency in our API.

For most requests, the headers and body are the same size (200 bytes each).

Has anyone seen this before?

+6
source share
1 answer

I do not have specific information about fast APIs (NSUrlConnection, etc.), but in general, while HTTP data is sent in large chunks (which can accommodate 200 bytes in one packet), more granular decisions are made on the base TCP layer, which may decide to split them into smaller pieces.

I observed this in node (the sending side as well as the receiving side) on certain platforms (such as AIX), where packets are broken at illogical boundaries through TCP. According to the TCP specification, applications should not rely on a specific order or size of low-level data transport, this ensures data integrity at the final stage.

One suspect will be the presence of the Nagile algorithm in TCP.

I would also recommend changing the client to another platform (e.g. Linux) and comparing the behavior if it is easy to port it.

Hope this helps.

0
source

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


All Articles