Results 1 to 6 of 6

Thread: Thread programming without sleep or WaitFor events

  1. #1

    Thread programming without sleep or WaitFor events

    We need very high performance to process UDP Socket messages. If we use sleep(0) or sleep(1) or WaitForSingleObject (Event based) it works but sometime we get 15-16ms latency.
    If we don't use these it works perfectly but in this case the blocks other operations.
    Is there any way to use Threads without any latency in Delphi? Maybe by dedicating one of core to this thread.

  2. #2
    Stijn Sanders develyoy's Avatar
    Join Date
    Jun 2008
    Location
    GentBrugge, Belgi?½
    Posts
    1,046
    Setting affinity on a dedicated thread sure is an idea that might work. I would suggest tring SwitchToThread instead of Sleep(0), but that still might give you 'hops' of around 12 to 16 millliseconds it typically takes to get control back to your thread. What are you using to read the UDP packets? If you use the correct WSA calls in the right way, the system should have the information about a thread of yours to 'wake' when a packet comes in...

  3. #3
    mov rax,marcov; push rax marcov's Avatar
    Join Date
    Apr 2004
    Location
    Ehv, Nl
    Posts
    10,357
    Purely from theory:

    As far as I know the fastest way to use asynchronous programming is to use "completion ports". But it is Windows NT+ only (so only NT4,2000,XP etc, not Win95,98,ME), so historically underused.

    Maybe combined with lightweight threads called "Fibers". Indy tried to implement them once.

    Just google the terms in quotes.

    Or use a waitfor with a timeout. Then you need no sleep. Or a waitformultiple with a long timeout and an tevent to quickly exit it if needed.

  4. #4
    Forget UDP Port.
    I have a list to handle without delay. Using sleep or waitforsingleobject affects 16ms latency while switching windows messages.

    I can't use IOCP because i have to process the list in an order FIFO.

    I'm not sure which approch is the right way or any other approch to do this.
    My first approch is not to use sleep or any other waiting objects. In this case CPU will use %20.

    My second idea is setting one thread for this job by using SetThreadAffinityMask. This thread will use allways one CORE witout balancing with other Core's. It also use %20 of Total CPU but the differences is it's not going to switch between other CPU's.

    Which one is the best approch? Or do you have an idea?

    Note: There are same third-party tools to dedicate a core to a specific actions but i don't wan't to use them without source code.

  5. #5
    mov rax,marcov; push rax marcov's Avatar
    Join Date
    Apr 2004
    Location
    Ehv, Nl
    Posts
    10,357
    Oh, and don't forget to disable NAGLE on the UDP port.

    In indy it is binding.usenagle:=false.

  6. #6
    FYI, deze vraag is gisteren wereldwijd gecrosspost op StackOverflow en talloze fora en als reactie op blogs. Niet alleen de vraag, maar ook de reactie. Daarom gaat deze maar even op slot.
    1+1=b

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •