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. Strategy for Asynchronous database access
QtWS25 Last Chance

Strategy for Asynchronous database access

Scheduled Pinned Locked Moved Solved General and Desktop
multithreadingsql databaseasynchronousnetworking
2 Posts 2 Posters 1.3k Views
  • 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.
  • nooneN Offline
    nooneN Offline
    noone
    wrote on last edited by noone
    #1

    I need to create a server in Qt C++ with QTcpServer which can handle so many requests at the same time. nearly more than 1000 connections and all these connection will constantly need to use database which is MariaDB.

    Before it can be deployed on main servers, It needs be able to handle 1000 connections with each connection Querying data as fast it can on 4 core 1 Ghz CPU with 2GB RAM Ubuntu virtual machine running on cloud. MySQL database is hosted on some other server which more powerful

    So how can I implement this ? after googling around, I've come up with following options

    1. Create A new QThread for each SQL Query

    2. Use QThreadPool for new SQL Query

    For the fist one, it might will create so many Threads and it might slow down system cause of so many context switches.

    For second one,after pool becomes full, Other connections have to wait while MariaDB is doing its work on other server. So what is the best strategy ?

    kshegunovK 1 Reply Last reply
    0
    • nooneN noone

      I need to create a server in Qt C++ with QTcpServer which can handle so many requests at the same time. nearly more than 1000 connections and all these connection will constantly need to use database which is MariaDB.

      Before it can be deployed on main servers, It needs be able to handle 1000 connections with each connection Querying data as fast it can on 4 core 1 Ghz CPU with 2GB RAM Ubuntu virtual machine running on cloud. MySQL database is hosted on some other server which more powerful

      So how can I implement this ? after googling around, I've come up with following options

      1. Create A new QThread for each SQL Query

      2. Use QThreadPool for new SQL Query

      For the fist one, it might will create so many Threads and it might slow down system cause of so many context switches.

      For second one,after pool becomes full, Other connections have to wait while MariaDB is doing its work on other server. So what is the best strategy ?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      None of the above. Pool your TCP connections on top of a few threads, and independently pool your few database connections on top of another set of threads. Make the actual queries asynchronous by queuing them through the tread pool.
      The solution's rather complex, though, and 1000 connections ain't that much, so you may be able to get away with a single thread for the TCP stack and a single thread for the SQL stack.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      4

      • Login

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