I have a “Queuing Theory” problem where following are to be done:
- Develop a CLIENT to send continuous packets of fixed size to SERVER at fixed rate
- SERVER has to queue these packets and SORT them before handling these packets
- Then we need to prove (for some packet size ‘n’ bytes and rate ‘r’ MBps) the theoretical observation that sorting(n log n / CPU_FREQ) happens faster than queuing (n / r), and thus the QUEUE should not build up at all.
However, I find that Queue is always building up (running on two systems – client and server PCs/Laptops),
Note: When I run the processes on the same system, then Queue doesnt build and most of the time, it is down close to 1 – 20 packets.
Need someone to check/review my code.
Code is pasted here:
-
Client (Single Class):
-
Server (Multiple Class files Package: serverClasses:
- Main: http://pastebin.com/embed_iframe.php?i=BgZzfiTQ
- Sorting: http://pastebin.com/embed_iframe.php?i=mPh8zgqC
- ServerThreadPerClient: http://pastebin.com/embed_iframe.php?i=ZpTqpHnX
- GlobalStatistics: http://pastebin.com/embed_iframe.php?i=Q2DJLvaV
-
Sample Graph for “QUEUE_LEN Vs. #PACKETS” for 10MBps and 10000 Byte sized packets for a duration of 30 – 35 secs

On the client it looks to me that the
timeintervalis always going to be 0. Was that the intension? You say seconds in the code but you are missing the* 1000.And then you call
Thread.sleep((long) timeinterval). Sincesleep()takeslongthen this will at most sleep 1ms and usually (I suspect) sleep 0ms. Sleep only has a millisecond resolution. If you want nanoseconds resolution then you’ll have to do something like:I suspect that your CPU is limiting your runs when both the client and the server are on the same box. When they are on different boxes then things back up because the client is in effect flooding the server because of the improper sleep times.
That’s my best guess at least.