Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTcpServer : Maximum number of sockets ?
Forum Updated to NodeBB v4.3 + New Features

QTcpServer : Maximum number of sockets ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    k.gaitanis
    wrote on last edited by
    #1

    I'm writing a TCP Server web service which would need to have about 10000 simultaneous open connections. When running my tests it seems that the maximum number of allowed connections is somewhere near 1024.

    I have written a minimal server example which simply accepts the incoming connections and a minimal client test app which creates 400 clients and connects to the server (no data exchange). The client test app is launched several times (even from different computers) to see how many clients will manage to connect. The server is always limited in the number of connections without producing any easily catchable errors. This has been tested on Mac and Linux with almost the same results.

    On Mac there is an error printed repeatedly on the screen : "select: Invalid argument" and the server stops responding. On Linux there is nothing printed on the screen but the server also stops responding. The exact number of maximum connections depends on which computer I'm running the server (997 on my mac laptop, 1013 on my linux remote server) and is exactly the same every time I run the test.

    My question is : Is this limitation coming from Qt or from somewhere else? Have you tested QTcpServer with thousands of connections? If so, where can I find an example of that ?

    My test code is really minimal but if you think I'm doing something wrong I can post it.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by mcosta
      #2

      HI,

      the problem is inside the EventDispatcher implementation.

      On Mac is by default the class QEventDispatcherUNIX that uses select() to monitor activities of sockets and other file descriptor and select() doesn't not support more than 1024 file descriptors (actually doesn't support a fd ID higher than 1024)

      On Linux by default the event dispatcher is implemented using glib and IIUC it uses poll(). In that case the limit is higher (about 10240 fd) but with thousands of connections is very slow. (in case glib is not available it uses select())

      Possible solutions??

      1. Don't use a single process to handle all the sockets
      2. Write your own event dispatcher (best solution is to use kevent for Mac and epoll for Linux)
      3. Don't use Qt for that

      NOTE: We had the same problem and the solution was:

      1. Use an external process to handle all connections without using Qt (we used ZeroMQ)
      2. Share information with the Qt process using a single connection

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved