Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Question about selector speed.  (Read 2972 times)

0 Members and 1 Guest are viewing this topic.

Shimajda

  • Newbie
  • *
  • Posts: 17
    • View Profile
Question about selector speed.
« on: December 14, 2010, 12:53:18 pm »
Does anyone knows how selector works?
Lets say that our selector can handle 64 sockets, and we have 640 connections to handle. So we have 10 selectors, 64 sockets for each and we check each selector for ready sockets.
Is that faster than iterating through simple socket array (or container)?

In http://www.sfml-dev.org/forum/viewtopic.php?t=1977&highlight=selector
Quote from: "Laurent"
Actually, the number of sockets that a selector can hold is OS-dependent. And it may perfectly be as low as 64.

How do i know how much sockets selector can handle in system that program is running?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Question about selector speed.
« Reply #1 on: December 14, 2010, 01:36:03 pm »
Quote
Lets say that our selector can handle 64 sockets, and we have 640 connections to handle. So we have 10 selectors, 64 sockets for each and we check each selector for ready sockets.
Is that faster than iterating through simple socket array (or container)?

This doesn't produce the same results.
If you use more than one selector, you will have to wait until the first one receives data (or timeout) to proceed with the second one, etc.
If you use multiple sockets it's exactly the same, replace "selector" with "socket". Unless the sockets are in non-blocking mode, which would be the only good solution in this context. But this is a totally different approach.

Quote
How do i know how much sockets selector can handle in system that program is running?

I don't know if there's a standard constant/macro that defines it. It could be a good idea to check that :)
Laurent Gomila - SFML developer

Shimajda

  • Newbie
  • *
  • Posts: 17
    • View Profile
Question about selector speed.
« Reply #2 on: December 14, 2010, 02:01:03 pm »
Sorry forgot about some details:
For each selector we have timeout: 0.01
In second case all sockets are in non-blocking code (blocking mode would be suicide :) )

I forgot becouse I have no idea how can i handle multiple clients in case where they send data only if they need and server have other things to do than just waiting for clients. Another thing is that I can't use threads.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Question about selector speed.
« Reply #3 on: December 14, 2010, 02:11:46 pm »
There's no need to use selectors, especially if you would need several of them, if you can use non-blocking sockets.

Quote
I forgot becouse I have no idea how can i handle multiple clients in case where they send data only if they need and server have other things to do than just waiting for clients. Another thing is that I can't use threads.

Non-blocking mode is definitely the only solution in this context. Everything else would block the thread.
Laurent Gomila - SFML developer

Shimajda

  • Newbie
  • *
  • Posts: 17
    • View Profile
Question about selector speed.
« Reply #4 on: December 14, 2010, 02:44:48 pm »
For my second question answer is here:
http://stackoverflow.com/questions/411295/alternatives-to-winsock2-with-example-server-source-in-c
Brian R. Bondy describes why select() is limited to 64 in some os, and how to check it.
There was mentioned about "Input/output completion port (IOCP)" but its Windows NT solution.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Question about selector speed.
« Reply #5 on: December 14, 2010, 03:02:15 pm »
Thanks :)
Laurent Gomila - SFML developer

 

anything