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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #9

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

    I'm just looking for a way to have "valid" pointer.

    When do you need this 'valid pointer'?

    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
    • D Offline
      D Offline
      Dariusz
      wrote on last edited by
      #10

      Well say a client connects, a log/ credentials/ information is required so the credential/connection manager waits for them. Say it received them push them to stack for processing in another thread and when other thread-validator get to it will validate the details. In meantime, the client can disconnect and die off. Now atm I send data back to server and use it as "validator" if object still exists(socket/client), but it would be much more efficient to just do... toStrongRef().isValid() to see if its ok to send data to it...if I had a weakref of it/ sharedPtr. could save me a mutex in logic and speed up the process by a lot. I have then "self" governing objects without the need for manager oversight.

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #11

        QPointer

        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
        1
        • Christian EhrlicherC Christian Ehrlicher

          QPointer

          D Offline
          D Offline
          Dariusz
          wrote on 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
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 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
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on 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

              Christian EhrlicherC D 2 Replies Last reply
              1
              • SGaistS SGaist

                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 ?

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 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
                • SGaistS SGaist

                  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 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.

                  kshegunovK 1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 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
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      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 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
                      • Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on 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
                        • Christian EhrlicherC Christian Ehrlicher

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

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

                          kshegunovK Offline
                          kshegunovK Offline
                          kshegunov
                          Moderators
                          wrote on 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

                            @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.

                            kshegunovK Offline
                            kshegunovK Offline
                            kshegunov
                            Moderators
                            wrote on 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

                            • Login

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