c++ - pselect blocks even though data is available for read on socket -


I am experiencing an intermittent delay while reading from POSIS Socket (RHEL 6x86_64C ++ ICPC).

My code is designed so that the user can provide a full time-limit (a relative timeout) that Many call can be used for recv. I ask PECEL to make sure that the data is available for reading before reading.

This usually works as expected (waiting for data, but not exceeding the deadline, no noticeable delay can be offered when available to retrieve the data ). However, I have a user who can get his application from time to time (~ 50% of the time) in a state where ~ 400-500 ms for selection block though data is available on the socket. If I look at / proc / net / tcp, then I can see that the data is available in the RX queue and I can slowly read the queued data after seeing the application. If I leave to choose the call and only call books, then the behavior is the same (but at least delay indicates that RRV is also blocking unnecessarily) When the application comes in this situation It stays in this way (experiences constant delay in each Pse Strait / REV).

I have spent many hours here and on other sites. This is the closest problem I could have found, but there was no resolution ...

Has anyone played this kind of behavior before? What I'm at a loss to do is I used the code to confirm that this is where the delay is happening (EDIT: We have actually validated that the whole method below was slow, someone There was no special system call.) It seems that there is a kernel / OS problem but I'm not sure where to see me. Here's the code ...

  // Protected Balls Message: Wait (int socket, constant timepak and deadline) {// If deadline has not been provided (deadline.tv_sec = = 0 & amp; amp; amp; amp; & amp; deadline.tv_nsec == 0) {back true; } // Make sure that we have not already crossed the timeline deadline; Clock_gettime (CLOCK_REALTIME, and current time); If (VirtualClock :: Semietime (current time, deadline)> = 0) {LOG_WARNING ("Waiting for data to finish waiting"); M_timedOut = True; return false; } // Get timeout timespec get timeout; Mmateset (& amp; expiration, 0, size (timeout)); Timeout.tv_nsec = VirtualClock :: nsecs (current time, deadline); VirtualClock :: fixtime (timeout); // Wait for data fs_set descSet; FD_ZERO (& descSet); FD_SET (socket, and disassetset); Favored Results = Pixels (socket + 1, and disassette, faucet, tap, and timeout, tap); If (result == -1) {m_error = errno; LOG_ERROR ("Failed to wait for data:% d,% s", m_error, strerror (m_error)); return false; } And if (Results == 0 ||! FD_ISSET (socket, and disassette)) {LOG_WARNING ("Time to wait for data to be found"); M_timedOut = True; return false; } Back true; }  

VirtualClock is a time-related utility class that is used to compare here / fix-up times (i.e. not starting any delays). I appreciate any information on this behavior.

This was actually not a problem with any system call. We used the strokes to find out and were seeing multiple calls for clock_gettime, a programming error was seen in another (third) review of the calling code, which resulted in the result of the code called in the context of corrupt stack data. This helps by a faulty API design on my behalf, which results in corruption of timeframe.

I was allowing the user to pass in the context of configuring the server configured config (including the last time related data). My server was saving the reference instead of copying the class object. The user made an example of his server class on the heap, a server on the stack was passed in conferencing (in context), resulting in non-determining garbage in the configuration when the method exits and ServerConfig exits from the scope. This is the old code and I have prevented this type of thing from burning at other places, but it has slipped through one.

Then the lesson for me has been learned: For references provided by the user, from time to time reconsidering optimization (instead of just making a copy, I was hanging on a reference, the whole reason) , And when you see non-deterministic behaviors like this (I think that when I suspect the builds have been lifted but this time it has not happened). Besides, Strace is a great tool ... I've seen others use it, but now I'm comfortable using it myself.

Thanks for the comment and sorry for the false alarms.


Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -