-
Notifications
You must be signed in to change notification settings - Fork 182
/
performance_test.exs
117 lines (95 loc) · 2.87 KB
/
performance_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
defmodule PerformanceTest do
use ExUnit.Case
require Logger
import ExqTestUtil
setup do
TestRedis.setup()
on_exit(fn ->
TestRedis.teardown()
end)
:ok
end
defmodule Worker do
def perform(arg) do
if arg == "last" do
Logger.info("Last message detected")
send(:tester, :done)
end
end
end
defmodule FlakeyWorker do
def perform(instruction) do
case instruction do
"done" -> send(:tester, :done)
1 -> raise "error"
2 -> Process.exit(self(), :normal)
3 -> Process.exit(self(), :kill)
4 -> 1 / 0
5 -> 1 = 0
6 -> Exq.worker_job(Exq)
end
end
end
test "test to_job_serialized performance" do
started = :os.timestamp()
max_timeout_ms = 1_000
for _ <- 1..1000,
do:
Exq.Redis.JobQueue.to_job_serialized(
"default",
PerformanceTest.Worker,
["keep_on_trucking"],
max_retries: 10
)
elapsed_ms = :timer.now_diff(:os.timestamp(), started) / 1_000
Logger.debug("to_job_serialized performance test took #{elapsed_ms / 1_000} secs")
assert elapsed_ms < max_timeout_ms
end
test "performance is in acceptable range" do
Process.register(self(), :tester)
started = :os.timestamp()
max_timeout_ms = 5 * 1_000
{:ok, sup} = Exq.start_link()
for _ <- 1..1000,
do: Exq.enqueue(Exq, "default", PerformanceTest.Worker, ["keep_on_trucking"])
Exq.enqueue(Exq, "default", PerformanceTest.Worker, ["last"])
# Wait for last message
receive do
:done -> Logger.info("Received done")
after
# This won't count enqueue
max_timeout_ms -> assert false, "Timeout of #{max_timeout_ms} reached for performance test"
end
elapsed_ms = :timer.now_diff(:os.timestamp(), started) / 1_000
Logger.debug("Perf test took #{elapsed_ms / 1_000} secs")
count = Exq.Redis.Connection.llen!(:testredis, "test:queue:default")
assert count == 0
assert elapsed_ms < max_timeout_ms
# let stats finish
wait_long()
stop_process(sup)
end
test "performance for flakey workers" do
Process.register(self(), :tester)
max_timeout_ms = 2 * 1_000
{:ok, sup} = Exq.start_link(concurrency: 20)
for _ <- 1..200,
do:
Exq.enqueue(Exq, "default", PerformanceTest.FlakeyWorker, [
Enum.random([1, 2, 3, 4, 5, 6])
])
Exq.enqueue(Exq, "default", PerformanceTest.FlakeyWorker, [:done])
# Wait for last message
receive do
:done -> Logger.info("Received done")
after
# This won't count enqueue
max_timeout_ms -> assert false, "Timeout of #{max_timeout_ms} reached for performance test"
end
count = Exq.Redis.Connection.llen!(:testredis, "test:queue:default")
assert count == 0
# let stats finish
wait_long()
stop_process(sup)
end
end