Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Timing Issues using a loop and Indy TCPIP components

  1. #1

    Timing Issues using a loop and Indy TCPIP components

    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?
    http://www.c5software.co.uk (site is being developed at the moment)

  2. #2

    Timing Issues using a loop and Indy TCPIP components

    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

  3. #3

    Timing Issues using a loop and Indy TCPIP components

    Thanks, I was hoping to avoid threads

    Does anyone know anything about the Indy TCPIP Server Socket that I could use? Some miracle method...
    http://www.c5software.co.uk (site is being developed at the moment)

  4. #4

    Timing Issues using a loop and Indy TCPIP components

    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

  5. #5

    Timing Issues using a loop and Indy TCPIP components

    Quote Originally Posted by lucky
    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?
    http://www.c5software.co.uk (site is being developed at the moment)

  6. #6

    Timing Issues using a loop and Indy TCPIP components

    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

  7. #7

    Timing Issues using a loop and Indy TCPIP components

    Quote Originally Posted by lucky
    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
    http://www.c5software.co.uk (site is being developed at the moment)

  8. #8

    Timing Issues using a loop and Indy TCPIP components

    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

  9. #9

    Timing Issues using a loop and Indy TCPIP components

    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?
    http://www.c5software.co.uk (site is being developed at the moment)

  10. #10

    Timing Issues using a loop and Indy TCPIP components

    put the indy thing into a thread and set its priority onto high.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •