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. How long does the write operation of the database take
Forum Updated to NodeBB v4.3 + New Features

How long does the write operation of the database take

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 5 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.
  • tovaxT tovax

    @jsulm

    QElapsedTimer timer;
    timer.start();
    model->setData(index, value, role);
    qDebug() << __FUNCTION__ << timer.elapsed();
    

    I have no experience with the read and write speed of the database. I don't know if "80ms" is a normal level.

    J.HilkJ Offline
    J.HilkJ Offline
    J.Hilk
    Moderators
    wrote on last edited by
    #6

    @tovax store the elapsed time in a variable beforehand, that qDebug() call may take forever


    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    tovaxT 1 Reply Last reply
    3
    • J.HilkJ J.Hilk

      @tovax store the elapsed time in a variable beforehand, that qDebug() call may take forever

      tovaxT Offline
      tovaxT Offline
      tovax
      wrote on last edited by
      #7

      @J-Hilk Hi, thanks!

      QElapsedTimer timer;
      timer.start();
      model->setData(index, value, role);
      int64_t elapsedBuffer = timer.elapsed();
      qDebug() << __FUNCTION__ << elapsedBuffer;
      
      JonBJ 1 Reply Last reply
      0
      • tovaxT tovax

        @J-Hilk Hi, thanks!

        QElapsedTimer timer;
        timer.start();
        model->setData(index, value, role);
        int64_t elapsedBuffer = timer.elapsed();
        qDebug() << __FUNCTION__ << elapsedBuffer;
        
        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by JonB
        #8

        @tovax
        I assume by the way that you have timed this many times in several different places, and taken averages? For example, timing one operation which is, say, the first write to a database/file can be very far from "typical" of your overall throughput rate.

        Depending on what timings/operations you want, you may, or may not be interested, in timing multiple writes, and/or writes separated by time, and so on.

        If you really want to know what's going, if profiling is available to you fro Creator you could try using that to instrument behaviour.

        1 Reply Last reply
        3
        • tovaxT Offline
          tovaxT Offline
          tovax
          wrote on last edited by
          #9

          Source code:

          void CentralMachiningInfo::setValue(const MachiningInfoRow::T row, const QVariant value, int32_t role)
          {
              QWriteLocker locker(&modelLock);
              QModelIndex index = model->index(row, MachiningInfoColumn::Value);
              if (model->data(index, role) != value) {
                  QElapsedTimer timer;
                  timer.start();
                  model->setData(index, value, role);
                  int64_t elapsedBuffer = timer.elapsed();
                  qDebug() << __func__ << elapsedBuffer;
              }
          }
          

          Debug output:

          setValue 92
          setValue 67
          setValue 77
          setValue 72
          setValue 82
          setValue 69
          setValue 74
          setValue 76
          setValue 71
          setValue 72
          setValue 69
          setValue 71
          setValue 82
          setValue 69
          setValue 71
          setValue 72
          setValue 76
          setValue 69
          setValue 72
          setValue 82
          setValue 76
          setValue 71
          setValue 81
          setValue 84
          setValue 91
          setValue 84
          
          JonBJ 1 Reply Last reply
          0
          • tovaxT tovax

            Source code:

            void CentralMachiningInfo::setValue(const MachiningInfoRow::T row, const QVariant value, int32_t role)
            {
                QWriteLocker locker(&modelLock);
                QModelIndex index = model->index(row, MachiningInfoColumn::Value);
                if (model->data(index, role) != value) {
                    QElapsedTimer timer;
                    timer.start();
                    model->setData(index, value, role);
                    int64_t elapsedBuffer = timer.elapsed();
                    qDebug() << __func__ << elapsedBuffer;
                }
            }
            

            Debug output:

            setValue 92
            setValue 67
            setValue 77
            setValue 72
            setValue 82
            setValue 69
            setValue 74
            setValue 76
            setValue 71
            setValue 72
            setValue 69
            setValue 71
            setValue 82
            setValue 69
            setValue 71
            setValue 72
            setValue 76
            setValue 69
            setValue 72
            setValue 82
            setValue 76
            setValue 71
            setValue 81
            setValue 84
            setValue 91
            setValue 84
            
            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #10

            @tovax
            Don't forget: setData() may be doing more than just writing a value to the database. For example, it raises a dataChanged() signal, and if you have a view slotted to that (and using the default DirectConnection) you will be timing the whole of the view's response code here.... At minimum you might disable Qt signals for the duration. That's why I said profiling would be the best way to see what is really going on.

            tovaxT 1 Reply Last reply
            4
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #11

              @tovax said in How long does the write operation of the database take:

              QWriteLocker locker(&modelLock);

              This looks fishy...

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

              JonBJ 1 Reply Last reply
              4
              • Christian EhrlicherC Christian Ehrlicher

                @tovax said in How long does the write operation of the database take:

                QWriteLocker locker(&modelLock);

                This looks fishy...

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by
                #12

                @Christian-Ehrlicher
                Oh yes I didn't notice that! Could be making a huge difference!

                @tovax
                Comment that out for a start and see whether it is making any difference?

                tovaxT 1 Reply Last reply
                1
                • JonBJ JonB

                  @Christian-Ehrlicher
                  Oh yes I didn't notice that! Could be making a huge difference!

                  @tovax
                  Comment that out for a start and see whether it is making any difference?

                  tovaxT Offline
                  tovaxT Offline
                  tovax
                  wrote on last edited by
                  #13

                  @JonB
                  There is no difference after commenting out "QWriteLocker".

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

                    @tovax said in How long does the write operation of the database take:

                    There is no difference after commenting out "QWriteLocker".

                    I don't see why you need it at all - that's why I pointed it out.

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

                    tovaxT 1 Reply Last reply
                    1
                    • Christian EhrlicherC Christian Ehrlicher

                      @tovax said in How long does the write operation of the database take:

                      There is no difference after commenting out "QWriteLocker".

                      I don't see why you need it at all - that's why I pointed it out.

                      tovaxT Offline
                      tovaxT Offline
                      tovax
                      wrote on last edited by
                      #15

                      @Christian-Ehrlicher Hi, thank you very much, this class was a singleton class in the previous version, and the current version does not require a read-write lock.

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

                        So your previous implementation was wrong - you must not access the gui from without the main thread :)

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

                        tovaxT 1 Reply Last reply
                        2
                        • Christian EhrlicherC Christian Ehrlicher

                          So your previous implementation was wrong - you must not access the gui from without the main thread :)

                          tovaxT Offline
                          tovaxT Offline
                          tovax
                          wrote on last edited by
                          #17

                          @Christian-Ehrlicher Thank you very much for your reply :)

                          1 Reply Last reply
                          0
                          • JonBJ JonB

                            @tovax
                            Don't forget: setData() may be doing more than just writing a value to the database. For example, it raises a dataChanged() signal, and if you have a view slotted to that (and using the default DirectConnection) you will be timing the whole of the view's response code here.... At minimum you might disable Qt signals for the duration. That's why I said profiling would be the best way to see what is really going on.

                            tovaxT Offline
                            tovaxT Offline
                            tovax
                            wrote on last edited by
                            #18

                            @JonB I have checked the signals and slots of the database and there is no connection during the reading and writing test.

                            jsulmJ JonBJ 2 Replies Last reply
                            0
                            • tovaxT tovax

                              @JonB I have checked the signals and slots of the database and there is no connection during the reading and writing test.

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

                              @tovax To find out whether the write itself is slow you should omit the model and write directly using QSqlQuery.

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

                              1 Reply Last reply
                              3
                              • tovaxT tovax

                                @JonB I have checked the signals and slots of the database and there is no connection during the reading and writing test.

                                JonBJ Online
                                JonBJ Online
                                JonB
                                wrote on last edited by
                                #20

                                @tovax
                                Well I'm not sure what you want us to say here? At your timings you can achieve ~15 write operations per second. I would not be very happy with this!

                                Try:

                                        timer.start();
                                        for (int = 0; i < 10; i++)
                                        {
                                            model->setData(index, value, role);
                                            // change `index` and/or `value`
                                        }
                                        int64_t elapsedBuffer = timer.elapsed();
                                

                                Does this take 10x as long??

                                I have checked the signals and slots of the database and there is no connection during the reading and writing test.

                                So you have no views at all attached to the model?

                                tovaxT 1 Reply Last reply
                                1
                                • JonBJ JonB

                                  @tovax
                                  Well I'm not sure what you want us to say here? At your timings you can achieve ~15 write operations per second. I would not be very happy with this!

                                  Try:

                                          timer.start();
                                          for (int = 0; i < 10; i++)
                                          {
                                              model->setData(index, value, role);
                                              // change `index` and/or `value`
                                          }
                                          int64_t elapsedBuffer = timer.elapsed();
                                  

                                  Does this take 10x as long??

                                  I have checked the signals and slots of the database and there is no connection during the reading and writing test.

                                  So you have no views at all attached to the model?

                                  tovaxT Offline
                                  tovaxT Offline
                                  tovax
                                  wrote on last edited by tovax
                                  #21

                                  @JonB Hi, thank you very much for your patience.

                                  1. It takes 10x time.
                                  2. no views attached to the model.
                                  3. My purpose is to know how many milliseconds it takes for the database to read and write normally, ~ 80ms seems to be too long, I doubt my program.
                                  4. I created a demo program separately, and the reading and writing speed is very fast. I will reply to the final test results later.
                                  1 Reply Last reply
                                  0
                                  • tovaxT Offline
                                    tovaxT Offline
                                    tovax
                                    wrote on last edited by
                                    #22

                                    @Christian-Ehrlicher @JonB @J-Hilk @jsulm
                                    Thank you for your help. The reason for the slow speed should be the hard disk. The same demo takes about 80 ms for HDD and about 4 ms for SSD.

                                    1 Reply Last reply
                                    2

                                    • Login

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