Now i am more confused than before, sorry.
You did not explain what is going on, as you still abusing
Indy and its threads !
1) Your server is using multithread to
handle UDP connections, that is fine and is in fact the right way, BUT as you did again miss the explaining what exactly and how you
handle these received UDP packets, i will assume you are handling them all in the main thread and enforcing this by these
Delphi-Quellcode:
//Synchronize(MeineFunktion);
//Queue(Nil, MeineFunktion);
//ForceQueue(Nil, MeineFunktion);
Congratulations, you defeated the whole purpose of using multithread server to
handle connections, and you are better to switch to event based server and
handle everything in the main thread.
The whole approach of using or receiving packets and handling in the main thread, is to not block packet handling and absolve the main thread to
handle UI.
But this is based on what i see from the code you pasted, the same code without more details, like where the UDP packers read is happening.
2) What on earth this WaitForsingleObject is used for ?, what the idea of it ? purpose ? and it is inside the thread execution loop ? that can't be more wrong on so many level, it is like you have one wheel but only interacting with it with stick(s).
3) You confirming the TC, yet i still see TC2, and don't see where these variables declared are they all local to this thread ? how are you logging ?
4) you mentioned PostThreadMessage, how this fit in all of this, you either use PostThreadMessage or one of these
Delphi-Quellcode:
//Synchronize(MeineFunktion);
//Queue(Nil, MeineFunktion);
//ForceQueue(Nil, MeineFunktion);
never together, well you can, but nothing good is coming out of it.
5) OnIdle is taking 7 seconds, is clear evidence of you killing the main thread, now you said the CPU is not high or no CPU usage, so let me explain how modern CPU(s) work, one thread will run on one core at any moment, so main thread is hugged or and on full job, then one core will go 100%, if you look on you overall CPUusage and it is 4 cores, then it will show 25%, if you CPU 8 then it will show %12 ....
So look again how much your main thread is utilizing.
6) THe fact
Process Explorer showing too much red, and from your screenshot, i pointed that kernel time is multiple over user time, is clear that main thread is put to
handle IO or something has to do with kernel operation, what is it ?
Here an example on how to
handle UDP, it is this simple and don't complicate things,
https://stackoverflow.com/questions/...simple-strings
Know this : You can receive thousands of packets of hundreds clients per seconds on main thread and it will not glitch for fraction of seconds, as you don't
handle or
process these packets just receive, so either receive everything in main thread then signal few threads to
process, or receive in background thread and
handle them there, never in main thread.
Main thread is not super thread or faster than any other threads, on contrary it is burdened with UI handling, so less job for it,
ps :
7) are you logging in main thread ? how many operation per second ? also how many packets you do receive per seconds ?