Performance comparison of various databases (preliminary)

// A little time recently to test the performance issues of nosql (reids, mongdb) and mysql

// The most common redis non-relational database in use today

// Loop 100,000 times and a million times (the simplest data insertion):

 $redis=new Redis();

 $redis->connect('127.0.0.1',6379); // Local IP, etc. (install redis service and dll extension first)

 $redis->auth('123456'); // password

 

 $StartTime = microtime(true);  

 for($i=1;$i<= 1000001;$i++){

    $redis->set($i,$i);

 }

 $StopTime = microtime(true);  

 $TimeSpent=$StopTime-$StartTime;

 echo number_format($TimeSpent*1000, 4).'milliseconds';  

 // 100,000 times 100001 8,050.7162 milliseconds

 // 1 million times 1000001 78,719.3971 milliseconds



 

// The efficiency of mysql batch insert is as follows:

$link = mysql_connect('127.0.0.1','root',''); 

if (!$link) { 

die('Could not connect to MySQL: ' . mysql_error()); 

}

mysql_select_db('test');

 

$StartTime = microtime(true);  

 

$str = '';

for($i=1;$i<=100000;$i++){

$ str. = '('. $ i. '),';

}

$sql1 ="insert into test(val) values".$str;

$sql2 = rtrim($sql1, ",").';'; // It may not be good to concatenate sql strings that are too long

mysql_query($sql2,$link); 

 

/*

for($i=1;$i<=1000000;$i++){

$sql1 ="insert into test(val) values($i)";

mysql_query($sql1,$link); 

}*/

$StopTime = microtime(true);

 

$TimeSpent=$StopTime-$StartTime;

echo number_format($TimeSpent*1000, 4).'milliseconds';  

exit;

// In the case of sql value splicing

// 100000 => 1,960.1121ms/1,662.9341ms

// 10000000 => Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 98888926 bytes) in D:\wamp_php\wamp\www\testmysql.php on line 14

// 5000000 => Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 48888924 bytes) in D:\wamp_php\wamp\www\testmysql.php on line 15

// 3000000 => Warning: Error while sending QUERY packet. PID=2928 in D:\wamp_php\wamp\www\testmysql.php on line 16

// 1000000 => 

//Warning: mysql_query(): MySQL server has gone away in D:\wamp_php\wamp\www\testmysql.php on line 16

//Warning: mysql_query(): Error reading result set's header in D:\wamp_php\wamp\www\testmysql.php on line 16

 

// loop

// 1000000 It took 122 seconds and 03 milliseconds to actually insert 1627 entries into the table

It can be seen that the efficiency of mysql's large data splicing form of inserting data is far greater than the efficiency of circular insertion, but my own notebook may be configured for a long time and low, and the actual efficiency on the server should be much higher.

 

 Mongdb batch insertion efficiency: In March, 10 million records (including three fields of ID, name, and age) were inserted into mongdb on the company computer, which took 43 minutes and less than an hour. This efficiency should be similar to redis;

 

Summary: Non-relational databases are much more efficient than relational databases. . .

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326987795&siteId=291194637