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. QSharedPointer and... self reference?
QtWS25 Last Chance

QSharedPointer and... self reference?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qsharedpointer
21 Posts 4 Posters 3.1k 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 Christian Ehrlicher
    17 May 2021, 18:30

    QPointer

    D Offline
    D Offline
    Dariusz
    wrote on 17 May 2021, 18:33 last edited by
    #12

    @Christian-Ehrlicher so I can emit as QPointer<objectX>(this) to wrap self into QPointer? Interesting thank you! This could work I think o.o

    1 Reply Last reply
    0
    • C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 17 May 2021, 18:35 last edited by Christian Ehrlicher
      #13

      Why would you emit yourself instead using sender()?

      /edit: ah - thread boundaries... still don't see why the pointer should be invalid on the receiver side.

      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
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 17 May 2021, 18:37 last edited by
        #14

        You know that at some points you might be doing too much threading ?

        The validation part being pushed on a stack and handled by a different thread while the original might be dying in between looks a bit strange. Can you explain why do you need to delegate credential validation to a different thread ? How long do you expect that validation to take ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        C D 2 Replies Last reply 17 May 2021, 18:39
        1
        • S SGaist
          17 May 2021, 18:37

          You know that at some points you might be doing too much threading ?

          The validation part being pushed on a stack and handled by a different thread while the original might be dying in between looks a bit strange. Can you explain why do you need to delegate credential validation to a different thread ? How long do you expect that validation to take ?

          C Online
          C Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 17 May 2021, 18:39 last edited by
          #15

          @SGaist exactly my impression - the workflow is wrong. Normally a socket stays in it's thread and all the work is done there. Not one socket in many threads. This is just slow due to the thread context switches and cries for problems as we can see here.

          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
          0
          • S SGaist
            17 May 2021, 18:37

            You know that at some points you might be doing too much threading ?

            The validation part being pushed on a stack and handled by a different thread while the original might be dying in between looks a bit strange. Can you explain why do you need to delegate credential validation to a different thread ? How long do you expect that validation to take ?

            D Offline
            D Offline
            Dariusz
            wrote on 17 May 2021, 18:40 last edited by Dariusz
            #16

            @SGaist Say I get 30-40k connections, it takes about 800ms to decrypt the packet, even when I run 50 threads that is 700 connections per thread that's 700ms per login packet etc etc. With so much data it takes few seconds to get it "rolling" and validation can take some time too. As he has to check login attempts/etc/etc flag bad connections/etc/etc.

            K 1 Reply Last reply 18 May 2021, 10:36
            0
            • C Online
              C Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 17 May 2021, 18:45 last edited by
              #17

              As I already said - don't move the sockets around but put them into different worker threads which are responsible for the handling. Load-balacing is not easy that's why apache or any other webserver exists.

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

              D 1 Reply Last reply 17 May 2021, 18:54
              0
              • C Christian Ehrlicher
                17 May 2021, 18:45

                As I already said - don't move the sockets around but put them into different worker threads which are responsible for the handling. Load-balacing is not easy that's why apache or any other webserver exists.

                D Offline
                D Offline
                Dariusz
                wrote on 17 May 2021, 18:54 last edited by Dariusz
                #18

                @Christian-Ehrlicher yee... I think we miss understood each other. I have a set of threads and each thread has a set of sockets. So its not 1 socket in many threads. its many threads for many sockets. This is my profile snapshot >
                8ef768ee-18e5-48a2-8319-bdee44fd6534-image.png
                The selected are is clean up function that removed dead sockets, if I can have them as smart pointers I no longer have to check their live/clean them up.

                The top "wide" pink are - that is busy are socket jobs that I perform when new client connects - this is about 20k connection test. the sockets down below are pragma omp sockets that perform clean notification. That notification could be removed/optimized further if I can use shared ptrs and remove the wait times entirely.

                In general its a training exercise to see if I can build efficient server/socket system using many threads. I've already learned A LOT about threads and connections using different queued/direct connections methods.

                The entire width is about 80 seconds, 40s of which are 2 mutex wait events for clean ups.

                1 Reply Last reply
                0
                • C Online
                  C Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 17 May 2021, 18:59 last edited by
                  #19

                  I only said that in a webserver-concept you do not move the sockets around in the threads but assign a socket to a dedicated thread. Everything else will be too slow. Even using Qt for such a task is imho a too big overhead for 30k sockets.

                  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
                  0
                  • C Christian Ehrlicher
                    17 May 2021, 18:13

                    Don't put QObjects into QSharedPointers when you use parent/child relationships.

                    I don't see what's wrong using a raw pointer here.

                    K Offline
                    K Offline
                    kshegunov
                    Moderators
                    wrote on 17 May 2021, 22:16 last edited by kshegunov
                    #20

                    @Christian-Ehrlicher said in QSharedPointer and... self reference?:

                    Don't put QObjects into QSharedPointers when you use parent/child relationships.

                    Or ever, really. QObjects are never "shared", and they already have the "weak" pointer machinery facilitating QPointer. If one ever does (which one never should), it's imperative that the deleter is calling deleteLater.

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    2
                    • D Dariusz
                      17 May 2021, 18:40

                      @SGaist Say I get 30-40k connections, it takes about 800ms to decrypt the packet, even when I run 50 threads that is 700 connections per thread that's 700ms per login packet etc etc. With so much data it takes few seconds to get it "rolling" and validation can take some time too. As he has to check login attempts/etc/etc flag bad connections/etc/etc.

                      K Offline
                      K Offline
                      kshegunov
                      Moderators
                      wrote on 18 May 2021, 10:36 last edited by
                      #21

                      @Dariusz said in QSharedPointer and... self reference?:

                      @SGaist Say I get 30-40k connections, it takes about 800ms to decrypt the packet, even when I run 50 threads that is 700 connections per thread that's 700ms per login packet etc etc.

                      Btw, do you have a 50 core machine? If you don't, then just don't.
                      Threads don't materialize performance out of thin air!

                      Simply run a few threads instead of wasting all the time in context switches.

                      Read and abide by the Qt Code of Conduct

                      1 Reply Last reply
                      3

                      21/21

                      18 May 2021, 10:36

                      • Login

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