博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
emysql: ping VS without ping
阅读量:6466 次
发布时间:2019-06-23

本文共 4066 字,大约阅读时间需要 13 分钟。

emysql默认每次执行sql前,会ping一次数据库, 很奇怪! 不知道为什么。

 

下面是粗略做了一下效率测试:

 

表如下:

mysql> show create table just_test\G;
*************************** 1. row ***************************
Table: just_test
Create Table: CREATE TABLE `just_test` (
`id` bigint(20) unsigned NOT NULL,
`data` int(11) NOT NULL,
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_T
IMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
1 row in set (0.02 sec)

 

 

在64位win7系统下(CPU: Intel(R) Core(TM) i3 cpu   530@2.93GHz  2.93GHz,     内存:8G),

创建该表,然后插入一条记录, 然后重复执行update该表的data字段为某个值(sql如: update just_test set data = 456),

结果: 

 

========with ping(每次update前都ping一次)的测试结果:========

fg_sql_inf:prof(100).

100 loops, using time: 63ms
ok
2> fg_sql_inf:prof(100).
100 loops, using time: 94ms
ok
3> fg_sql_inf:prof(100).
100 loops, using time: 125ms
ok
4> fg_sql_inf:prof(100).
100 loops, using time: 78ms
ok
5> fg_sql_inf:prof(10000).
10000 loops, using time: 4010ms
ok
6> fg_sql_inf:prof(10000).
10000 loops, using time: 3978ms
ok
7> fg_sql_inf:prof(10000).
10000 loops, using time: 3838ms
ok
8> fg_sql_inf:prof(10000).
10000 loops, using time: 3994ms
ok
9> fg_sql_inf:prof(10000).
10000 loops, using time: 4009ms
ok
10> fg_sql_inf:prof(10000).
10000 loops, using time: 3853ms
ok
11> fg_sql_inf:prof(10000).
10000 loops, using time: 3838ms
ok
12> fg_sql_inf:prof(10000).
10000 loops, using time: 3947ms
ok
13> fg_sql_inf:prof(10000).
10000 loops, using time: 4025ms
ok
14> fg_sql_inf:prof(10000).
10000 loops, using time: 4025ms
ok
15> fg_sql_inf:prof(10000).
10000 loops, using time: 3869ms
ok
16> fg_sql_inf:prof(10000).
10000 loops, using time: 3993ms
ok
17> fg_sql_inf:prof(10000).
10000 loops, using time: 3853ms
ok
18> fg_sql_inf:prof(10000).
10000 loops, using time: 3947ms
ok
19> fg_sql_inf:prof(100000).
100000 loops, using time: 39359ms
ok
20> fg_sql_inf:prof(100000).
100000 loops, using time: 39328ms
ok
21> fg_sql_inf:prof(100000).
100000 loops, using time: 39187ms
ok
22> fg_sql_inf:prof(100000).
100000 loops, using time: 39406ms
ok
23> fg_sql_inf:prof(100000).
100000 loops, using time: 39265ms
ok
24> fg_sql_inf:prof(100000).
100000 loops, using time: 39515ms
ok

 

 

 

======== without ping(不包含ping操作)的测试结果========

 

2> fg_sql_inf:prof(100).

100 loops, using time: 46ms
ok
3> fg_sql_inf:prof(10000).
10000 loops, using time: 2308ms
ok
4> fg_sql_inf:prof(10000).
10000 loops, using time: 2402ms
ok
5> fg_sql_inf:prof(10000).
10000 loops, using time: 2418ms
ok
6> fg_sql_inf:prof(10000).
10000 loops, using time: 2419ms
ok
7> fg_sql_inf:prof(10000).
10000 loops, using time: 2417ms
ok
8> fg_sql_inf:prof(10000).
10000 loops, using time: 2419ms
ok
9> fg_sql_inf:prof(10000).
10000 loops, using time: 2294ms
ok
10> fg_sql_inf:prof(10000).
10000 loops, using time: 2417ms
ok
11> fg_sql_inf:prof(10000).
10000 loops, using time: 2479ms
ok
12> fg_sql_inf:prof(10000).
10000 loops, using time: 2433ms
ok
13> fg_sql_inf:prof(10000).
10000 loops, using time: 2403ms
ok
14> fg_sql_inf:prof(100000).
100000 loops, using time: 23540ms
ok
15> fg_sql_inf:prof(100000).
100000 loops, using time: 23556ms
ok
16> fg_sql_inf:prof(100000).
100000 loops, using time: 23759ms
ok
17> fg_sql_inf:prof(100000).
100000 loops, using time: 23510ms
ok
18> fg_sql_inf:prof(100000).
100000 loops, using time: 23667ms
ok
19> fg_sql_inf:prof(100000).
100000 loops, using time: 26786ms
ok
20> fg_sql_inf:prof(100000).
100000 loops, using time: 23618ms
ok
21> fg_sql_inf:prof(100000).
100000 loops, using time: 23525ms
ok

 

 

可见,ping的操作还是有一定影响, 去掉ping之后, 大概会加快80%

 

 

附:   

update_test_tbl(_NewVal) ->

        Table = just_test,
        TableBin = atom_to_binary(Table, latin1),

        Cmd = <<"update ", TableBin/binary, " set data = 456">>,

        execute(Cmd).     % 会调用emysql:execute(?POOL, Cmd)

 

prof(Times) ->

        F = fun() ->
                      update_test_tbl(1)
              end,
        run(F, Times).

run(Fun, Loop) ->
        statistics(wall_clock),
        for(1, Loop, Fun),
        {_, T1} = statistics(wall_clock),
        io:format("~p loops, using time: ~pms~n", [Loop, T1]),
        ok.

 

for(Max, Max , Fun) ->

        Fun();
for(I, Max, Fun) ->
        Fun(),  

        for(I + 1, Max, Fun).

 

转载于:https://www.cnblogs.com/kamfon/p/4301581.html

你可能感兴趣的文章
[CareerCup] 17.3 Factorial Trailing Zeros 求阶乘末尾零的个数
查看>>
Security updates and resources
查看>>
深入理解JavaScript系列(25):设计模式之单例模式
查看>>
DNS为什么通常都会设置为14.114.114.114
查看>>
给定一个序列,判断该序列是否为二叉树查找树的后序遍历序列
查看>>
Sqoop架构(四)
查看>>
golang copy函数
查看>>
《你有多少问题要请示》精华集粹
查看>>
深度 | 机器学习敲门砖:任何人都能看懂的TensorFlow介绍【转】
查看>>
leveldb学习:DBimpl
查看>>
MySQL存储引擎--MYSIAM和INNODB引擎区别
查看>>
[Recompose] Stream Props to React Children with RxJS
查看>>
打印图片
查看>>
SHOW CREATE DATABASE Syntax
查看>>
rsync常见问题及解决办法
查看>>
AKM项目轶事之GBS同事转入GDC
查看>>
MySQL日期 专题
查看>>
C#中禁止程序多开
查看>>
分布式缓存Redis使用以及原理
查看>>
[LeetCode] Number of 1 Bits 位操作
查看>>