is it normal for mysql to take 14+ seconds to do 10k inserts?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Myst
    Confirmed User
    • Feb 2004
    • 4708

    #1

    is it normal for mysql to take 14+ seconds to do 10k inserts?

    is it normal for mysql to take 14+ seconds to do something simple like (pseudecode) for x = 10000 to 20000; mysql_query(insert into users (muser) values ($x)) ???

    muser is varchar, length 5, non primary (it is the only column in the table)

    I am on a AMD Athlon 64 3500+ PC with 1gb ram.. this is all being done locally

    the exact code im using is below

    Code:
    $dbcnx = mysql_connect('localhost','xxxxx', 'xxxxx'); 
    mysql_select_db("testtable", $dbcnx); 
    for ($i = 10000; $i <= 20000; $i++) { 
    mysql_query("insert into users (muser) values ('$i')"); 
    }
    ICQ: 298-523-037
  • spasmo
    Confirmed User
    • Dec 2005
    • 2678

    #2
    You have to think spindles. What is your disk IO while doing this?

    Surfers: Go here for hot babes.

    Comment

    • Myst
      Confirmed User
      • Feb 2004
      • 4708

      #3
      about 400KB while its inserting
      the cpu mysql uses is around 30&#37; during the inserts..

      ICQ: 298-523-037

      Comment

      • spasmo
        Confirmed User
        • Dec 2005
        • 2678

        #4
        I'm a bit stymied on this one. It usually points to disk IO.

        Anyone else with ideas out there? I must be missing something obvious.

        Surfers: Go here for hot babes.

        Comment

        • Myst
          Confirmed User
          • Feb 2004
          • 4708

          #5
          is it normally much faster?
          ICQ: 298-523-037

          Comment

          • WiredGuy
            Pounding Googlebot
            • Aug 2002
            • 34516

            #6
            I'm guessing by the code you're doing this in perl. Perl has always been very slow for me in doing basic sql operations such as adds/deletions. It's extremely fast to use mysql directly to import the data from a file if this is possible in your application.
            WG
            I play with Google.

            Comment

            • Myst
              Confirmed User
              • Feb 2004
              • 4708

              #7
              wow.. it takes <2 seconds on a linux server

              im using windows, and i am desperately trying to figure out why mysql is so 700&#37; slower using the same code..
              ICQ: 298-523-037

              Comment

              • darksoul
                Confirmed User
                • Apr 2002
                • 4997

                #8
                Originally posted by WiredGuy
                I'm guessing by the code you're doing this in perl. Perl has always been very slow for me in doing basic sql operations such as adds/deletions. It's extremely fast to use mysql directly to import the data from a file if this is possible in your application.
                WG
                thats php
                1337 5y54|)m1n: 157717888
                BM-2cUBw4B2fgiYAfjkE7JvWaJMiUXD96n9tN
                Cambooth

                Comment

                • WiredGuy
                  Pounding Googlebot
                  • Aug 2002
                  • 34516

                  #9
                  Originally posted by darksoul
                  thats php
                  Perl too. Maybe its Windows that really makes it all slow
                  WG
                  I play with Google.

                  Comment

                  • darksoul
                    Confirmed User
                    • Apr 2002
                    • 4997

                    #10
                    the problem is mysql commits after each insert so you're better running a combined insert:

                    Code:
                    $dbcnx = mysql_connect('localhost','xxxxx', 'xxxxx'); 
                    mysql_select_db("testtable", $dbcnx); 
                    $cmd = "insert into users (muser) values ";
                    for ($i = 10000; $i <= 20000; $i++) { 
                    $cmd .= "($i),"
                    }
                    $cmd .= "(20001)"
                    mysql_query($cmd);
                    should be blazing fast.
                    1337 5y54|)m1n: 157717888
                    BM-2cUBw4B2fgiYAfjkE7JvWaJMiUXD96n9tN
                    Cambooth

                    Comment

                    • darksoul
                      Confirmed User
                      • Apr 2002
                      • 4997

                      #11
                      Originally posted by WiredGuy
                      Perl too. Maybe its Windows that really makes it all slow
                      WG
                      I meant the code he posted is php
                      1337 5y54|)m1n: 157717888
                      BM-2cUBw4B2fgiYAfjkE7JvWaJMiUXD96n9tN
                      Cambooth

                      Comment

                      • Myst
                        Confirmed User
                        • Feb 2004
                        • 4708

                        #12
                        figured it out =)
                        looks like it was the table structure..
                        INNODB is 7-8x faster than InnoDB (at least on windows anyway)
                        Last edited by Myst; 02-18-2007, 01:27 AM.
                        ICQ: 298-523-037

                        Comment

                        • WiredGuy
                          Pounding Googlebot
                          • Aug 2002
                          • 34516

                          #13
                          Nice sig darksoul, lol.
                          WG
                          I play with Google.

                          Comment

                          • 2012
                            So Fucking What
                            • Jul 2006
                            • 17189

                            #14
                            windowz ?

                            edit ...
                            Last edited by 2012; 02-18-2007, 01:33 AM. Reason: i like big tits
                            best host: Webair | best sponsor: Kink | best coder: 688218966 | Go Fuck Yourself

                            Comment

                            • tical
                              Confirmed User
                              • Feb 2002
                              • 6504

                              #15
                              try this query instead, should be WAY faster... only hits MySQL once with a large insert

                              (note: that last substr just removes the trailing "," from the query so its valid)

                              Code:
                              	$dbcnx = mysql_connect('localhost','xxxxx', 'xxxxx'); 
                              	mysql_select_db("testtable", $dbcnx); 
                              	$query = "";
                              	for ($i = 10000; $i <= 20000; $i++) {
                              		$query = $query . "('" . $i . "'),";
                              	}
                              	$query = "insert into users (muser) values " . substr($query, 0, strlen($query) - 1);
                              	mysql_query($query);
                              i think thats right, but you get the idea... you can do multiple inserts in one query w/ MySQL so handle the processing beforehand and eliminate all the redundant connections, etc.
                              112.020.756

                              Comment

                              • tical
                                Confirmed User
                                • Feb 2002
                                • 6504

                                #16
                                Originally posted by darksoul
                                the problem is mysql commits after each insert so you're better running a combined insert:

                                Code:
                                $dbcnx = mysql_connect('localhost','xxxxx', 'xxxxx'); 
                                mysql_select_db("testtable", $dbcnx); 
                                $cmd = "insert into users (muser) values ";
                                for ($i = 10000; $i <= 20000; $i++) { 
                                $cmd .= "($i),"
                                }
                                $cmd .= "(20001)"
                                mysql_query($cmd);
                                should be blazing fast.
                                blah crap i didnt even see this haha... ah well
                                112.020.756

                                Comment

                                • rotterdammer
                                  Confirmed User
                                  • Feb 2006
                                  • 1523

                                  #17
                                  Bump for you lol

                                  Comment

                                  • Myst
                                    Confirmed User
                                    • Feb 2004
                                    • 4708

                                    #18
                                    the thing is i will be doing many many single inserts, so i set it to do one at a time on purpose

                                    the problem was the table structure

                                    INNODB is 7-8x faster than InnoDB (at least on windows anyway)
                                    ICQ: 298-523-037

                                    Comment

                                    Working...