emysql: ping VS without ping

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   [email protected]  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).

时间: 2024-11-19 01:35:09

emysql: ping VS without ping的相关文章

Linux禁止ping以及开启ping的方法

Linux默认是允许Ping响应的,系统是否允许Ping由2个因素决定的:A.内核参数,B.防火墙,需要2个因素同时允许才能允许Ping,2个因素有任意一个禁Ping就无法Ping. 具体的配置方法如下: A.内核参数设置 1.允许PING设置 A.临时允许PING操作的命令为:#echo 0 >/proc/sys/net/ipv4/icmp_echo_ignore_all B.永久允许PING配置方法. /etc/sysctl.conf 中增加一行            net.ipv4.ic

CentOS下禁止ping和允许ping的方法

一.系统禁止ping [[email protected]黑客联盟~]# echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all 二.系统允许ping [[email protected]黑客联盟 ~]# echo 0 >/proc/sys/net/ipv4/icmp_echo_ignore_all 此上两条命令的效果实时生效,可以用另外的机器ping来测试是否生效. ———————————————————————————————————- /etc/r

linux禁ping和允许ping的方法

一.系统禁止ping [[email protected] ~]# echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all 二.系统允许ping [[email protected] ~]# echo 0 >/proc/sys/net/ipv4/icmp_echo_ignore_all 此上两条命令的效果实时生效,可以用另外的机器ping来测试是否生效. --------------------------------------------------

Linux禁止ping和开启ping的方法

Linux默认是允许Ping响应的,系统是否允许Ping由2个因素决定的:A.内核参数,B.防火墙,需要2个因素同时允许才能允许Ping,2个因素有任意一个禁Ping就无法Ping. 一.通过修改配置文件实现: 具体的配置方法如下: 1.设置临时允许或禁止ping: 1).临时允许ping的命令为: #echo 0 >/proc/sys/net/ipv4/icmp_echo_ignore_all 2).临时j禁止ping的命令为: #echo 1 >/proc/sys/net/ipv4/icm

防火墙禁ping:虚拟机ping不通主机,但主机可以ping虚拟机

现象:刚装的centos6.6,配置好网络却发现ping不通主机,主机却ping通虚拟机: 解决方法: 1.最简单的方法就是:关闭防火墙.但一直关闭防火墙也不是个办法,会遇到很多安全问题,建议下一个方案: 2.Windows的防火墙有个:ICMPv4-in这个规则,这个才是主要出问题的地方.只要找到这个开启,就不会被禁ping了: 打开方法: 1. 打开windo防火墙: 2. 选择高级设置: 3.入站规则: 4. 找到“公用”的“文件和打印共享(回显请求 – ICMPv4-In)”规则,右击启

ping域名和ping IP时速度不同的原因

不知道大家在ping的时候有没有遇到过这样的问题:当你ping一个域名的时候,ping结果返回得很慢,但是如果直接ping这个域名的ip,结果却快很多. 直接ping ip的时候,每两次发包之间没有明显的能感知出来的延迟: PING www.example.com (xxx.xxx.xxx.xxx) 56(84) bytes of data. 64 bytes from xxx.xxx.xxx.xxx: icmp_req=1 ttl=50 time=3.71 ms 64 bytes from x

【BAT批处理】根据计算机名批量自动ping,并给出ping结果(ping通还是ping不通)

@echo off (for /f "tokens=1*" %%a in (ipTable.txt) do ( ping %%a >nul && echo %%a OK||echo %%a Failed ))>result.txt 会读取ipTable.txt中的内容,ipTable示例: testComputerName1 testComputerName2 testComputerName3 ..... 此外,如果ipTable.txt中有多列,列与列中

linux服务器禁ping和开启ping功能

centos7系统 临时修改 echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all 1 表示禁ping 0 表示开启ping 或者: sysctl -w net.ipv4.icmp_echo_ignore_all=1 1 表示禁ping 0 表示开启ping 永久生效 修改配置文件/etc/sysctl.conf vim /etc/sysctl.conf net.ipv4.icmp_echo_ignore_all=1 保存退出,sysctl -p

网络状态都正常,ping 网关能ping通,但不正常,出现“?”,并且不能进行域名解析

C:\Documents and Settings\Administrator>ping 192.168.1.1 Pinging ? with 32 bytes of data: Reply from 192.168.1.1: bytes=32 time<1ms TTL=128 Reply from 192.168.1.1: bytes=32 time<1ms TTL=128 Reply from 192.168.1.1: bytes=32 time<1ms TTL=128 Rep