Skip to content

Commit 8d80ba7

Browse files
Added: script simulating a slow MySQL server
1 parent 41929b0 commit 8d80ba7

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,16 @@ using red in reverse video.
4141

4242
Same as debug.lua, but without shell colors.
4343

44+
### slow.lua
45+
46+
Simulates a server being slow because of huge traffic.
47+
48+
The *sleep* command accepting a float as argument is required to make this
49+
script works out of the box.
50+
51+
The slowdowns can be configured to make all requests longer by a factor or by
52+
a fixed amount of time (or both).
53+
54+
By default, requests are made twice slower with an additional overhead of 0.1s.
55+
4456
[mysql-proxy]: http://forge.mysql.com/wiki/MySQL_Proxy

slow.lua

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
-- MySQL Proxy script for simulating a slow server
2+
--
3+
-- Written by Patrick Allaert <[email protected]>
4+
-- Copyright © 2009-2011 Libereco Technologies
5+
--
6+
-- This program is free software: you can redistribute it and/or modify
7+
-- it under the terms of the GNU General Public License as published by
8+
-- the Free Software Foundation, either version 3 of the License, or
9+
-- (at your option) any later version.
10+
--
11+
-- This program is distributed in the hope that it will be useful,
12+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
-- GNU General Public License for more details.
15+
--
16+
-- You should have received a copy of the GNU General Public License
17+
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
-- Requirements: the sleep command accepting a float value as parameter
20+
-- See http://lua-users.org/wiki/SleepFunction for alternatives
21+
22+
-- Factor of slowness, how many times slower every requests should be
23+
factor = 2
24+
25+
-- In addition to a factor of slowness you can set a fixed amount of additional
26+
-- time every request should take (in seconds).
27+
additionalTime = 0.1
28+
29+
function read_query( packet )
30+
if packet:byte() ~= proxy.COM_QUERY then
31+
return
32+
end
33+
proxy.queries:append(1, string.char(proxy.COM_QUERY) .. packet:sub(2))
34+
35+
return proxy.PROXY_SEND_QUERY
36+
end
37+
38+
function read_query_result (inj)
39+
os.execute( "sleep " .. ( ( (factor - 1) * inj.response_time / 1e6 ) + additionalTime ) )
40+
end

0 commit comments

Comments
 (0)