Results 1 to 17 of 17

Thread: How to achieve fastest database insertion

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to achieve fastest database insertion

    Maybe a solution is to write the samples to a regular file and upload them to the database in the other thread. In this way, You are immune to changes in the instantaneous performance of the server. For example, one minute records are going to the first file. After a minute, the records are going to a new file and the previous one is pushed to the database. And so on...

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to achieve fastest database insertion

    You are receiving 12000 records in 1.0 second.
    You are inserting 12000 records in 0.8 seconds.
    Seems to me to me are keeping up just fine although I do wonder why your figure is 3 times longer than mine (Especially given your super-duper MySql backend vs my general MyISAM tables).

    Here are some more questions to answer for your own benefit:
    Where is the bottleneck? You still have not identified that. If you marshal the data into the query without actually executing it: how long does it take? What portion of the total time is this?
    Does this data need to be stored in an RDBMS at all?
    Is text the most efficient method of storing a date or time?
    Can data be aggregrated on-the-fly and only the aggregrate data stored?
    Can Lesiok's approach work for your application?
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  3. The following user says thank you to ChrisW67 for this useful post:

    karankumar1609 (20th November 2013)

  4. #3
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to achieve fastest database insertion

    Hello ChrisW67

    I have implemented the same code as yours and its the total time of insertion of record into the table.
    Where is the bottleneck? You still have not identified that. If you marshal the data into the query without actually executing it: how long does it take? What portion of the total time is this?
    Problem is why my code takes ~0.8 second for insertion.
    Before execution of query it hardly takes ~0-1 millisecond.
    ~0.8 second is the total time

    Qt Code:
    1. QTime time;
    2. time.start();
    3.  
    4. QSqlQuery query;
    5. database_manager_.transaction();
    6. for(int i = 0; i < queue.size(); ++i) {
    7. ...
    8. ...
    9. query.exec();
    10. }
    11. database_manager_.commit();
    12.  
    13. qDebug() << ">> " << time.elapsed();
    To copy to clipboard, switch view to plain text mode 

    Does this data need to be stored in an RDBMS at all?
    Yes data need to be stored in RDBMS

    Is text the most efficient method of storing a date or time?
    I will change these variables from string to date, time. It dosn't matter to me.

    Can data be aggregrated on-the-fly and only the aggregrate data stored?
    Data will be aggregated on-the-fly

    Can Lesiok's approach work for your application?
    Yes it works, but execution time is little high, Should i need any compiler optimization?
    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

  5. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to achieve fastest database insertion

    Quote Originally Posted by karankumar1609 View Post
    Yes it works, but execution time is little high, Should i need any compiler optimization?
    What does it mean "execution time is little high" ? Maybe your computer is too weak for this job or misconfigured ?

  6. The following user says thank you to Lesiok for this useful post:

    karankumar1609 (20th November 2013)

  7. #5
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to achieve fastest database insertion

    Thanks for your help i have changed the way i am inserting data into table.
    Now i have to insert 300 records per second which is quite less as compared to 12000.
    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

Similar Threads

  1. How to achieve Alt+Tab effect ?
    By y.s.bisht in forum Newbie
    Replies: 0
    Last Post: 11th November 2011, 13:22
  2. How can i achieve an auto-resizing QStackedWidget?
    By truefusion in forum Qt Programming
    Replies: 2
    Last Post: 17th May 2010, 02:31
  3. How to achieve showAll ?
    By Gopala Krishna in forum Qt Programming
    Replies: 5
    Last Post: 5th October 2007, 14:26
  4. How to achieve Uniformity...!!!
    By deepusrp in forum Qt Programming
    Replies: 9
    Last Post: 7th May 2007, 09:11
  5. Insertion of unicode characters into database oracle through pro c
    By hemananda choudhuri in forum Qt Programming
    Replies: 1
    Last Post: 8th January 2007, 10:42

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.