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. Load balancing between several Threads

Load balancing between several Threads

Scheduled Pinned Locked Moved Solved General and Desktop
qthreadqthreadpool
6 Posts 4 Posters 844 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.
  • C Offline
    C Offline
    Cocojambo
    wrote on last edited by
    #1

    Let's imagine that we have two cores (1 physical CPU).
    For example, we have some WorkerOne pushed to thread#1. Also we have WorkerTwo into thread#2.
    Then we add some heavy loading for WorkerOne. So in result we will have one fully loaded core (50-100%) and one almost spare.
    So if I want to balance this heavy loading between these two cores do I need to create an exact number of threads as number of cores?
    If it's true then should I store these threads in some threads list and pass a new job to free/random thread?
    I'm aware about QThreadPool but in my case I need threads to be persistent.

    jsulmJ 1 Reply Last reply
    0
    • C Cocojambo

      Let's imagine that we have two cores (1 physical CPU).
      For example, we have some WorkerOne pushed to thread#1. Also we have WorkerTwo into thread#2.
      Then we add some heavy loading for WorkerOne. So in result we will have one fully loaded core (50-100%) and one almost spare.
      So if I want to balance this heavy loading between these two cores do I need to create an exact number of threads as number of cores?
      If it's true then should I store these threads in some threads list and pass a new job to free/random thread?
      I'm aware about QThreadPool but in my case I need threads to be persistent.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Cocojambo said in Load balancing between several Threads:

      I'm aware about QThreadPool but in my case I need threads to be persistent

      They are persistant with QThreadPool also, see "QThreadPool manages and recyles individual QThread objects" in the documentation.
      "should I store these threads in some threads list and pass a new job to free/random thread?" - yes, you can do this.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • C Offline
        C Offline
        Cocojambo
        wrote on last edited by
        #3

        @jsulm
        How we can be sure that when I create 4 new threads each of them will be placed in different core?
        I mean that all 4 new threads may be created in one core and we won't get any benefit of such multi threading.

        JonBJ Christian EhrlicherC 2 Replies Last reply
        0
        • C Cocojambo

          @jsulm
          How we can be sure that when I create 4 new threads each of them will be placed in different core?
          I mean that all 4 new threads may be created in one core and we won't get any benefit of such multi threading.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @Cocojambo said in Load balancing between several Threads:

          How we can be sure that when I create 4 new threads each of them will be placed in different core?

          Does https://doc.qt.io/qt-5/thread-basics.html#using-threads help:

          The QtConcurrent module provides an easy interface for distributing work to all of the processor's cores. The threading code is completely hidden in the QtConcurrent framework, so you don't have to take care of the details. However, QtConcurrent can't be used when communication with the running thread is needed, and it shouldn't be used to handle blocking operations.

          Does bolded help your situation? Otherwise wait for @jsulm , because both he & you probably know more than I do!

          C 1 Reply Last reply
          0
          • JonBJ JonB

            @Cocojambo said in Load balancing between several Threads:

            How we can be sure that when I create 4 new threads each of them will be placed in different core?

            Does https://doc.qt.io/qt-5/thread-basics.html#using-threads help:

            The QtConcurrent module provides an easy interface for distributing work to all of the processor's cores. The threading code is completely hidden in the QtConcurrent framework, so you don't have to take care of the details. However, QtConcurrent can't be used when communication with the running thread is needed, and it shouldn't be used to handle blocking operations.

            Does bolded help your situation? Otherwise wait for @jsulm , because both he & you probably know more than I do!

            C Offline
            C Offline
            Cocojambo
            wrote on last edited by
            #5

            @JonB
            Well, only partially)

            https://doc.qt.io/qt-5/qtconcurrent.html
            "The QtConcurrent namespace provides high-level APIs that make it possible to write multi-threaded programs without using low-level threading primitives."
            I assume that if we work with low-level QThread we should have not less abilities that high-level API. But QThread doesn't offer any methods to do it.

            1 Reply Last reply
            0
            • C Cocojambo

              @jsulm
              How we can be sure that when I create 4 new threads each of them will be placed in different core?
              I mean that all 4 new threads may be created in one core and we won't get any benefit of such multi threading.

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by Christian Ehrlicher
              #6

              @Cocojambo said in Load balancing between several Threads:

              I mean that all 4 new threads may be created in one core and we won't get any benefit of such multi threading.

              You can't with Qt. But the OS will for sure not put all four threads on one core and leave the other three idle when the four have something to do.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              1

              • Login

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