-
Notifications
You must be signed in to change notification settings - Fork 1
/
basic_sim.rb
62 lines (47 loc) · 1.4 KB
/
basic_sim.rb
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
require 'rbsim'
model = RBSim.model do
program :wget do |opts|
sent = 0
on_event :send do
cpu do |cpu|
(150 / cpu.performance).miliseconds
end
send_data to: opts[:target], size: 1024.bytes, type: :request, content: sent
sent += 1
register_event :send, delay: 5.miliseconds if sent < opts[:count]
end
on_event :data_received do |data|
log "Got data #{data} in process #{process.name}"
stats :request_served, process.name
end
register_event :send
end
program :apache do
on_event :data_received do |data|
stats_start :apache, process.name
cpu do |cpu|
(100 * data.size.in_bytes / cpu.performance).miliseconds
end
send_data to: data.src, size: data.size * 10, type: :response, content: data.content
stats_stop :apache, process.name
end
end
node :desktop do
cpu 100
end
node :gandalf do
cpu 1400
end
new_process :client1, program: :wget, args: { target: :server, count: 10 }
new_process :client2, program: :wget, args: { target: :server, count: 10 }
new_process :server, program: :apache, args: 'apache1'
net :net01, bw: 1024.bps
net :net02, bw: 510.bps
route from: :desktop, to: :gandalf, via: [ :net01, :net02 ], twoway: true
put :server, on: :gandalf
put :client1, on: :desktop
put :client2, on: :desktop
end
model.run
model.stats_print
p model.stats_summary