View Full Version : Timing Issues using a loop and Indy TCPIP components
Gadget
22-08-2003, 09:54 AM
I have a main processing loop that updates creature actions that is hogging the CPU, thus stopping the Indy Server socket from processing incoming packets when the main loop is busy with 20+ creatures. Is it simply a case of putting loads of Application.ProcessMessages everywhere in the mainloop, or does anyone know of a better way of handling this problem? Is there anyway inside my main loop I can force some CPU onto the Server Socket?
wilbur989
22-08-2003, 02:17 PM
While application.processmessages would help in alowing other events to be fired while you were in the Creature processing loop it would slow down the creature processing. What your getting into at this point is the need to start looking into threading.
While threading can get very complex if you split your work up right it can be very easy to impliment. My suggestion would be if you have so much creature processing, start by moving all creature processing into a thread and see how that helps the speed of your main loop.
The unfortunate thing here is that you cannot assign cpu time to a task in your program unless it is a thread. When in a thread you can assign priortys to the threads giving one more priority over another. Then it becomes a balancing act as to which process should get more cpu time then another.
Hope this LONG winded explination helps. I suggest that if you want ot start looking at threads look at the JVCL thread component. It encapsulates a TThread and makes it a bit easer to use, athough there implimentation does have some drawbacks.
-Jeremy
Gadget
22-08-2003, 07:01 PM
Thanks, I was hoping to avoid threads :(
Does anyone know anything about the Indy TCPIP Server Socket that I could use? Some miracle method...
lucky
23-08-2003, 05:42 PM
With only 20 characters it's surprising that you're running into performance problems.
What kind of calculations are you doing? (maybe you could post the code)
luck
Gadget
24-08-2003, 02:24 PM
With only 20 characters it's surprising that you're running into performance problems.
What kind of calculations are you doing? (maybe you could post the code)
luck
To be honest I don't think the creatures are the problem it's the fact its a loop.
It more or less goes like this:-
while not bStopLoop do
begin
If {time to do regen} do hp regen;
If {time to do creature actions} do creature actions;
If {time to do remove corpses} do remove corpses;
end;
The creatures themselves are processed very quickly, I assume that it's this continuous evalation of the conditionals that's eating up the CPU?
lucky
27-08-2003, 01:40 AM
Profile!
I have some really simple performance monitor profiling code that I wrote for a project that I could send you.
It can be a godsend, and it sounds like it'd be helpful.
luck
Gadget
27-08-2003, 07:51 AM
Profile!
I have some really simple performance monitor profiling code that I wrote for a project that I could send you.
It can be a godsend, and it sounds like it'd be helpful.
luck
Thanks, that might be usefull!
I discovered the cause of the problem! Threads! The Indy server socket creates a thread for each client socket. Whilst the main loop is going round and round the threads don't get allocated much processing time at all. By adding in either a Sleep(n) or say a 250ms loop of application.processmessages the problem is solved.
I need to think more about this to optimize it. One pass through the main loop with around 20 creatures takes 0ns! 0 ticks LOL! One loop through the main loop with 40 (20 of them on one screen) creatures takes 42ns! So that isn't bad... That's also whilst running the message server, login server, AND client @ 100fps LOL
wilbur989
27-08-2003, 03:00 PM
oops ok so the reverse was the issue. I wounder... Are you useing an antifreeze component on your project where the tcp/ip socet is? The reason I ask is that when an indy component finds the antifreeze component it uses it for it's thread blocking. In effect it is suppose to give youre application a layer of processing insulation from the threading of the socket.
-Jeremy
Gadget
08-09-2003, 11:07 AM
I still haven't resolved this... I can't work out how to force some CPU onto the sockets.
What I need to do in the main loop is:-
while not bStopLoop do
begin
If {time to do regen} do hp regen;
If {time to do creature actions} do creature actions;
If {time to do remove corpses} do remove corpses;
Force some CPU time onto Indy Sockets;
end;
But there is no method? How can I increase the socket priorities? There is a ThreadManager component, has anyone used that?
put the indy thing into a thread and set its priority onto high.
Gadget
10-09-2003, 06:22 PM
put the indy thing into a thread and set its priority onto high.
That won't work because the Indy stuff use threads themselves. A thread per client apparently?? If you increase the thread priority of the application the socket threads process even slower =/
I need someway of working out how to use the TThreadManager...
what about direct play as an option then?
Gadget
11-09-2003, 08:38 AM
what about direct play as an option then?
Nice idea! Will have a look at that...
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.