Mysql-udf-http efficiency test under Mysql _mysql

Source: Internet
Author: User
See Zhang Yi Blog on the "Http/rest client article", how to install what the direct skip, the following directly into the test phase, test environment: virtual machine
Copy Code code as follows:

[Root@localhost ~]# Uname-a
Linux sunss 2.6.18-128.el5 #1 SMP Wed 10:44:23 EST 2009 i686 i686 i386 gnu/linux

Memory and Swap partitions:
Copy Code code as follows:

[Root@localhost ~]# Free-m
Total used free shared buffers Cached
mem:376 363 13 0 23 105
-/+ buffers/cache:233 142
SWAP:1023 133 890
Mysql:
[Root@localhost ~]# mysql-u root-p
Enter Password:
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 57
Server Version:5.1.26-rc-log Source Distribution
Type ' help, ' or ' \h ' for help. Type ' \c ' to clear the buffer.
Mysql>

Table structure to use:
Copy Code code as follows:

DROP TABLE IF EXISTS ' mytable ';
CREATE TABLE ' MyTable ' (
' ID ' int (a) not NULL auto_increment,
' Addtime ' int (a) not NULL,
' title ' varchar (255) Not NULL,
PRIMARY KEY (' id ')
) Engine=myisam DEFAULT Charset=utf8;

PHP operating the MySQL program:
Copy Code code as follows:

<?php
$type = $_get[' type '];
Print_r ($_get);
Include_once ("gettime.php");
$btime = Getmicrotime ();
$loop _cnt= 1000; Number of Cycles
$db _host = ' 127.0.0.1 '; //
$db _user = ' sunss '; //
$db _pass = ' 123456 '; //
$db _name = ' Test '; //
$db _link = mysql_connect ($db _host, $db _user, $db _pass) or Die ("Connected failed:". Mysql_error (). " \ n ");
mysql_query (' Set names UTF8 ');
Mysql_db_query ($db _name, $db _link);
if ("put" = = $type) {//Modify
$i = 1;
while ($i <= $loop _cnt) {
$title = "JKJKJKJKJKJKJKJKJKJKJKJKJK";
$tt = time ();
$sql = "Update mytable set Addtime=". $tt. ", title= '". $title. "' Where id= '". $i. "';
$res = mysql_query ($sql);
if (FALSE = = $res) {
echo "Update failed!\n";
}
$i + +;
}
else if ("delete" = $type) {//delete
$i = 1;
while ($i <= $loop _cnt) {
$sql = "Delete from mytable where id= '". $i. "'";
echo "Delete sql:". $sql. " <br> ";
$res = mysql_query ($sql);
if (FALSE = = $res) {
echo "Delete failed!\n";
}
$i + +;
}

else if ("post" = $type) {//Add
$i = 0;
while ($i < $loop _cnt) {
$title = "Hahahahahahahahahahahahahahahahahaha";
$tt = time ();
$sql = "INSERT INTO MyTable (Addtime, title) VALUES ($tt, '". $title. ")";
Print "SQL:". $sql. " <br> ";
$res = mysql_query ($sql);
if (FALSE = = $res) {
echo "Insert failed!\n";
}
$i + +;
}
}
Mysql_close ();
$etime = Getmicrotime ();
$runTime = Round ($etime-$btime, 4);
echo "RunTime:". $runTime. " \r\n<br> ";
?>

Separate PHP connection to the MySQL, a single connection add 1000 records need to: 0.9s or so
PHP Operation Memcache Program:
Copy Code code as follows:

<?php
Include_once ("gettime.php");
$btime = Getmicrotime ();
Ma 炴 帴
$mem _host = "192.168.0.134";
$mem _port = "11311";
$timeout = 3600;
$i = 0;
$cnt = 1000;
while ($i < $cnt) {
$mem = new Memcache;
$mem->connect ($mem _host, $mem _port) or die ("could not connect!");
$ret = $mem->set ($i, "11111111111", 0, $timeout);
if (false = = $ret) {
File_put_contents ("Insert_failed.log", "Post failed!\n", file_append);
}
$mem->close ();
$i + +;
}

鍏 pumping 棴 ma 炴 帴
$etime = Getmicrotime ();
$runTime = Round ($etime-$btime, 4);
echo "RunTime:". $runTime. " \r\n<br> ";
?>

A single connection to add 1000 records, need about 0.8s,
To create a trigger:
Copy Code code as follows:

DELIMITER $$
DROP TRIGGER/*!50032 IF EXISTS */' test '. ' Mytable_insert ' $$
CREATE
/*!50017 definer = ' root ' @ ' localhost ' *
TRIGGER ' Mytable_insert ' after inserts on ' MyTable '
For each ROW BEGIN
SET @tt_resu = (SELECT http_put CONCAT (' http://192.168.0.134/mem_ss.php?type=post&id= ', new.id, "&data=", New.addtime), 11);
End;
$$

Write a PHP update memcache for the trigger, with the following code:
Copy Code code as follows:

<?php
$id = $_get[' id '];
$type = $_get[' type '];
$json _data = $_get[' data '];
Var_dump ($_get);
Ma 炴 帴
$mem _host = "192.168.0.134";
$mem _port = "11211";
$timeout = 3600;
$mem = new Memcache;
$mem->connect ($mem _host, $mem _port) or die ("could not connect!");
if ("get" = = $type) {
$val = $mem->get ($id);
Echo $val;
$arr = Jsondecode ($val, ' utf-8 ');
Print_r ($arr);
else if ("put" = $type) {
$ret = $mem->replace ($id, $json _data, 0, $timeout);
if (false = = $ret) {
File_put_contents ("Replace_failed.log", "Replace failed!\n", file_append);
}
else if ("delete" = $type) {
$ret = $mem->delete ($id);
if (false = = $ret) {
File_put_contents ("Delete_failed.log", "Delete failed!\n", file_append);
}
else if ("post" = $type) {
$ret = $mem->set ($id, $json _data, 0, $timeout);
if (false = = $ret) {
File_put_contents ("Post_failed.log", "Post failed!\n", file_append);
}
}
$mem->close ();
?>

Use PHP to trigger MySQL to add 1000 records, and triggers to touch PHP update memcache, the use of time around 9s,
Because every time you close the link memcache, see if the link is closed cause slow, and write a program:
Copy Code code as follows:

<?php
Include_once ("gettime.php");
$btime = Getmicrotime ();
Connection
$mem _host = "192.168.0.134";
$mem _port = "11311";
$timeout = 3600;
$i = 0;
$cnt = 1000;
while ($i < $cnt) {
$mem = new Memcache;
$mem->connect ($mem _host, $mem _port) or die ("could not connect!");
$ret = $mem->set ($i, "11111111111", 0, 3600);
if (false = = $ret) {
File_put_contents ("Insert_failed.log", "Post failed!\n", file_append);
}
$mem->close ();
$i + +;
}
Close connection
$etime = Getmicrotime ();
$runTime = Round ($etime-$btime, 4);
echo "RunTime:". $runTime. " \r\n<br> ";
?>

It takes about 0.9s, not much slower than a connection.
To locate whether the trigger is slow or http_put slow, create a temporary table
Tmp_mytable, the table structure is as follows:
Copy Code code as follows:

CREATE TABLE ' MyTable ' (
' ID ' int (a) not NULL auto_increment,
' Addtime ' int (a) not NULL,
' title ' varchar (255) Not NULL
) Engine=myisam DEFAULT Charset=utf8;

Modify the trigger again as follows:
Copy Code code as follows:

DELIMITER $$
DROP TRIGGER/*!50032 IF EXISTS */' test '. ' Mytable_insert ' $$
CREATE
/*!50017 definer = ' root ' @ ' localhost ' *
TRIGGER ' Mytable_insert ' after inserts on ' MyTable '
For each ROW BEGIN
INSERT into tmp_mytable values (new.id,new.addtime,new.title);
End;
$$

Again with PHP to add 1000 records to MySQL, consumption time of 0.7s or so, proving the efficiency of consumption in http_put, that is, mysql-udf-http slow.
Don't know if my test was wrong? Also please be using Mysql-udf-http master, or to Mysql-udf-http have the master of the study advice.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.