rbsim 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/.hgignore +6 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +12 -0
  5. data/Gemfile.lock +66 -0
  6. data/LICENSE.txt +674 -0
  7. data/README.md +960 -0
  8. data/TODO +28 -0
  9. data/basic_sim.rb +62 -0
  10. data/fast-tcpn.rb +3 -0
  11. data/lib/rbsim.rb +14 -0
  12. data/lib/rbsim/dsl.rb +30 -0
  13. data/lib/rbsim/dsl/infrastructure.rb +48 -0
  14. data/lib/rbsim/dsl/mapping.rb +32 -0
  15. data/lib/rbsim/dsl/process.rb +129 -0
  16. data/lib/rbsim/dsl/program.rb +10 -0
  17. data/lib/rbsim/experiment.rb +110 -0
  18. data/lib/rbsim/hlmodel.rb +25 -0
  19. data/lib/rbsim/hlmodel/infrastructure.rb +116 -0
  20. data/lib/rbsim/hlmodel/mapping.rb +5 -0
  21. data/lib/rbsim/hlmodel/process.rb +152 -0
  22. data/lib/rbsim/numeric_units.rb +107 -0
  23. data/lib/rbsim/simulator.rb +184 -0
  24. data/lib/rbsim/statistics.rb +77 -0
  25. data/lib/rbsim/tokens.rb +146 -0
  26. data/lib/rbsim/version.rb +3 -0
  27. data/new_process.rb +49 -0
  28. data/rbsim.gemspec +42 -0
  29. data/show_readme.rb +15 -0
  30. data/sim.rb +142 -0
  31. data/sim_bamboo.rb +251 -0
  32. data/sim_process.rb +83 -0
  33. data/sim_process_dsl.rb +58 -0
  34. data/spec/dsl/infrastructure_nets_spec.rb +39 -0
  35. data/spec/dsl/infrastructure_nodes_spec.rb +72 -0
  36. data/spec/dsl/infrastructure_routes_spec.rb +44 -0
  37. data/spec/dsl/mapping_spec.rb +70 -0
  38. data/spec/dsl/process_spec.rb +56 -0
  39. data/spec/dsl/program_spec.rb +36 -0
  40. data/spec/dsl_and_hlmodel/new_process_spec.rb +235 -0
  41. data/spec/hlmodel/net_spec.rb +112 -0
  42. data/spec/hlmodel/process_spec.rb +242 -0
  43. data/spec/hlmodel/route_spec.rb +47 -0
  44. data/spec/hlmodel/routes_spec.rb +44 -0
  45. data/spec/integration/basic_simulation_spec.rb +104 -0
  46. data/spec/integration/net_spec.rb +44 -0
  47. data/spec/integration/process_spec.rb +117 -0
  48. data/spec/integration/rbsim_spec.rb +40 -0
  49. data/spec/simulator/logger_spec.rb +35 -0
  50. data/spec/simulator/stats_spec.rb +93 -0
  51. data/spec/spec_helper.rb +26 -0
  52. data/spec/statistics_spec.rb +300 -0
  53. data/spec/tcpn/add_route_spec.rb +55 -0
  54. data/spec/tcpn/cpu_spec.rb +53 -0
  55. data/spec/tcpn/map_data_spec.rb +37 -0
  56. data/spec/tcpn/network_spec.rb +163 -0
  57. data/spec/tcpn/register_event_spec.rb +48 -0
  58. data/spec/tcpn/route_to_self_spec.rb +53 -0
  59. data/spec/tcpn/stats_spec.rb +77 -0
  60. data/spec/tokens/data_queue_obsolete.rb +121 -0
  61. data/spec/tokens/data_queue_spec.rb +111 -0
  62. data/spec/units_spec.rb +48 -0
  63. data/tcpn/model.rb +6 -0
  64. data/tcpn/model/add_route.rb +78 -0
  65. data/tcpn/model/application.rb +250 -0
  66. data/tcpn/model/cpu.rb +75 -0
  67. data/tcpn/model/map_data.rb +42 -0
  68. data/tcpn/model/network.rb +108 -0
  69. data/tcpn/model/register_event.rb +89 -0
  70. data/tcpn/model/stats.rb +46 -0
  71. metadata +221 -0
data/tcpn/model/cpu.rb ADDED
@@ -0,0 +1,75 @@
1
+ # model of CPU load by application logic
2
+ # (TCPN implementation of event:cpu)
3
+ page "cpu" do
4
+ cpu = timed_place 'CPU', node: :node
5
+ process = timed_place 'process', { cpu_event: [ :has_event?, :cpu ] }
6
+ working_cpu = timed_place 'working CPU'
7
+
8
+ # Processing data on CPU.
9
+ # args: { block: a Proc that will receive a cpu object as argument and returns computation time on this CPU }
10
+ class EventCPU
11
+ attr_reader :process, :cpu, :event, :delay
12
+ def initialize(binding)
13
+ @process = binding['process'].value
14
+ @cpu = binding['CPU'].value
15
+ end
16
+
17
+ def cpu_and_process_token(clock)
18
+ hsh = { cpu: @cpu, process: @process }
19
+ { ts: clock + delay, val: hsh }
20
+ end
21
+
22
+ private
23
+
24
+ def delay
25
+ event = @process.serve_system_event :cpu
26
+ event[:args][:block].call(@cpu).to_i
27
+ end
28
+ end
29
+
30
+ transition 'event::cpu' do
31
+ input process
32
+ input cpu
33
+
34
+
35
+ output working_cpu do |binding, clock|
36
+ EventCPU.new(binding).cpu_and_process_token clock
37
+ end
38
+
39
+ sentry do |marking_for, clock, result|
40
+ marking_for['process'].each(:cpu_event, true) do |process|
41
+ marking_for['CPU'].each(:node, process.value.node) do |cpu|
42
+ result << { 'process' => process, 'CPU' => cpu }
43
+ end
44
+ end
45
+ end
46
+ =begin
47
+ guard do |binding, clock|
48
+ if binding[:process][:val].has_event?(:cpu) &&
49
+ (binding[:process][:val].node == binding[:cpu][:val].node)
50
+ true
51
+ else
52
+ false
53
+ end
54
+ end
55
+ =end
56
+
57
+ end
58
+
59
+
60
+ transition 'event::cpu_finished' do
61
+ input working_cpu
62
+
63
+ output cpu do |binding, clock|
64
+ cpu = binding['working CPU'].value[:cpu]
65
+ { ts: clock, val: cpu }
66
+ end
67
+
68
+ output process do |binding, clock|
69
+ process = binding['working CPU'].value[:process]
70
+ { ts: clock, val: process }
71
+ end
72
+
73
+ end
74
+
75
+ end
@@ -0,0 +1,42 @@
1
+ # map data to proper destination nodes
2
+ # before network transmission
3
+ page 'map data' do
4
+
5
+ mapping = place 'mapping'
6
+ data_to_send = place 'data to send'
7
+ data_for_network = place 'data for network'
8
+
9
+ transition 'add dst node' do
10
+ input data_to_send
11
+ input mapping
12
+
13
+ output mapping do |binding, clock|
14
+ binding['mapping']
15
+ end
16
+
17
+ class TCPNMapDataDestination
18
+ class ProcessNotMappedToNode < RuntimeError
19
+ end
20
+
21
+ def initialize(binding)
22
+ @data = binding['data to send'].value
23
+ @dst = @data.dst
24
+ @mapping = binding['mapping'].value
25
+ @dst_node = @mapping[@dst]
26
+ if @dst_node.nil?
27
+ raise ProcessNotMappedToNode.new(@dst)
28
+ end
29
+ @data.dst_node = @dst_node
30
+ end
31
+
32
+ def data_token(clock)
33
+ { ts: clock, val: @data }
34
+ end
35
+ end
36
+
37
+ output data_for_network do |binding, clock|
38
+ TCPNMapDataDestination.new(binding).data_token(clock)
39
+ end
40
+ end
41
+ end
42
+
@@ -0,0 +1,108 @@
1
+ # network transmission model
2
+ page 'network' do
3
+ data_with_route = place 'data with route'
4
+ net = timed_place 'net', { name: :name }
5
+ data_after_net = timed_place 'data after net', has_next_net: :has_next_net?
6
+ data_to_receive = place 'data to receive', process_name: :process_name
7
+
8
+ transition 'net' do
9
+ input data_with_route
10
+ input net
11
+
12
+ class TCPNNet
13
+ def initialize(binding)
14
+ @net = binding['net'].value
15
+ @data = binding['data with route'].value
16
+ # make it run random drop generator code to cache drop decision for the next time
17
+ @drop = @net.drop?
18
+ end
19
+
20
+ def net_token(clock)
21
+ { ts: clock + delay, val: @net }
22
+ end
23
+
24
+ def data_token(clock)
25
+ return nil if @drop
26
+ @data.route.next_net
27
+ { ts: clock + delay, val: @data }
28
+ end
29
+
30
+ def guard(clock)
31
+ @data.route.next_net == @net.name
32
+ end
33
+
34
+ private
35
+ def delay
36
+ (@data.size.to_f / @data.fragments) / @net.bw.to_f
37
+ end
38
+ end
39
+
40
+ output net do |binding, clock|
41
+ TCPNNet.new(binding).net_token(clock)
42
+ end
43
+
44
+ output data_after_net do |binding, clock|
45
+ TCPNNet.new(binding).data_token(clock)
46
+ end
47
+
48
+ sentry do |marking_for, clock, result|
49
+ marking_for['data with route'].each do |data|
50
+ next_net = data.value.route.next_net
51
+ marking_for['net'].each(:name, next_net) do |net|
52
+ result << { 'data with route' => data, 'net' => net }
53
+ end
54
+ end
55
+ end
56
+
57
+ =begin
58
+ guard do |binding, clock|
59
+ TCPNNet.new(binding).guard(clock)
60
+ end
61
+ =end
62
+ end
63
+
64
+ transition 'next net' do
65
+ input data_after_net
66
+ output data_with_route do |binding|
67
+ binding['data after net']
68
+ end
69
+
70
+ sentry do |marking_for, clock, result|
71
+ marking_for['data after net'].each(:has_next_net, true) do |data|
72
+ result << { 'data after net' => data }
73
+ end
74
+ end
75
+ =begin
76
+ guard do |binding, clock|
77
+ data = binding['data after net'].val
78
+ data.route.has_next_net?
79
+ end
80
+ =end
81
+ end
82
+
83
+ transition 'transmitted' do
84
+ input data_after_net
85
+ input data_to_receive
86
+
87
+ output data_to_receive do |binding, clock|
88
+ queue = binding['data to receive'].value
89
+ data = binding['data after net'].value
90
+ queue.put data
91
+ { ts: clock, val: queue }
92
+ end
93
+
94
+ sentry do |marking_for, clock, result|
95
+ marking_for['data after net'].each(:has_next_net, false) do |data|
96
+ marking_for['data to receive'].each(:process_name, data.value.dst) do |queue|
97
+ result << { 'data after net' => data, 'data to receive' => queue }
98
+ end
99
+ end
100
+ end
101
+ =begin
102
+ guard do |binding, clock|
103
+ data = binding[:data][:val]
104
+ !data.route.has_next_net?
105
+ end
106
+ =end
107
+ end
108
+ end
@@ -0,0 +1,89 @@
1
+ page "register event" do
2
+ process = timed_place 'process', { first_event: :first_event, id: :id }
3
+ event = timed_place 'event' #, { process_id: :process_id }
4
+
5
+ transition 'event::register_event' do
6
+ input process
7
+
8
+ class EventRegisterEvent
9
+ def initialize(binding)
10
+ @process = binding['process'].value
11
+ end
12
+
13
+ def process_token(clock)
14
+ @process.serve_system_event :register_event
15
+ { val: @process, ts: clock }
16
+ end
17
+
18
+ def event_token(clock)
19
+ @e = @process.serve_system_event :register_event
20
+ event = @e[:args][:event]
21
+ args = @e[:args][:event_args]
22
+ { val: RBSim::Tokens::EventToken.new(@process.id, event, args), ts: clock + @e[:args][:delay] }
23
+ end
24
+
25
+ def guard(clock)
26
+ @process.has_event? :register_event
27
+ end
28
+
29
+ end
30
+
31
+ output process do |binding, clock|
32
+ EventRegisterEvent.new(binding).process_token(clock)
33
+ end
34
+
35
+ output event do |binding, clock|
36
+ EventRegisterEvent.new(binding).event_token(clock)
37
+ end
38
+
39
+ sentry do |marking_for, clock, result|
40
+ marking_for['process'].each(:first_event, :register_event) do |process|
41
+ result << { 'process' => process }
42
+ end
43
+ end
44
+ =begin
45
+ guard do |binding, clock|
46
+ EventRegisterEvent.new(binding).guard(clock)
47
+ end
48
+ =end
49
+ end
50
+
51
+ transition 'event::enqueue_event' do
52
+ input event
53
+ input process
54
+
55
+ class EventEnqueueEvent
56
+ def initialize(binding)
57
+ @process = binding['process'].value
58
+ @event = binding['event'].value
59
+ end
60
+
61
+ def process_token(clock)
62
+ @process.enqueue_event(@event.name, @event.args)
63
+ { val: @process, ts: clock }
64
+ end
65
+
66
+ def guard(clock)
67
+ @process.id == @event.process_id
68
+ end
69
+ end
70
+
71
+ output process do |binding, clock|
72
+ EventEnqueueEvent.new(binding).process_token(clock)
73
+ end
74
+
75
+ sentry do |marking_for, clock, result|
76
+ marking_for['event'].each do |e|
77
+ marking_for['process'].each(:id, e.value.process_id) do |p|
78
+ result << { 'process' => p, 'event' => e }
79
+ end
80
+ end
81
+ end
82
+
83
+ =begin
84
+ guard do |binding, clock|
85
+ EventEnqueueEvent.new(binding).guard(clock)
86
+ end
87
+ =end
88
+ end
89
+ end
@@ -0,0 +1,46 @@
1
+ page "stats" do
2
+ process = timed_place 'process', { first_event: :first_event }
3
+
4
+ # stats for process
5
+ # args: stats tag
6
+ class EventStats
7
+ EventList = [ :stats, :stats_stop, :stats_start, :stats_save ]
8
+
9
+ def initialize(binding)
10
+ @process = binding['process'].value
11
+ @event_list = EventList
12
+ end
13
+
14
+ def process_token(clock)
15
+ @process.serve_system_event @process.first_event
16
+ { val: @process, ts: clock }
17
+ end
18
+
19
+ def guard(clock)
20
+ @event_list.include? @process.first_event
21
+ end
22
+
23
+ end
24
+
25
+ transition 'event::stats' do
26
+ input process
27
+
28
+ output process do |binding, clock|
29
+ EventStats.new(binding).process_token(clock)
30
+ end
31
+
32
+ sentry do |marking_for, clock, result|
33
+ EventStats::EventList.each do |e|
34
+ p = marking_for['process'].each(:first_event, e).first
35
+ result << { 'process' => p } unless p.nil?
36
+ end
37
+ end
38
+
39
+ =begin
40
+ guard do |binding, clock|
41
+ EventStats.new(binding).guard(clock)
42
+ end
43
+ =end
44
+ end
45
+
46
+ end
metadata ADDED
@@ -0,0 +1,221 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbsim
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Wojciech Rząsa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: docile
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fast-tcpn
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-its
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: You can model your distributed infrastructora and application and simulate
84
+ its behavior and observe its efficiency easily.
85
+ email:
86
+ - me@wojciechrzasa.pl
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files:
90
+ - README.md
91
+ files:
92
+ - ".hgignore"
93
+ - ".rspec"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - TODO
99
+ - basic_sim.rb
100
+ - fast-tcpn.rb
101
+ - lib/rbsim.rb
102
+ - lib/rbsim/dsl.rb
103
+ - lib/rbsim/dsl/infrastructure.rb
104
+ - lib/rbsim/dsl/mapping.rb
105
+ - lib/rbsim/dsl/process.rb
106
+ - lib/rbsim/dsl/program.rb
107
+ - lib/rbsim/experiment.rb
108
+ - lib/rbsim/hlmodel.rb
109
+ - lib/rbsim/hlmodel/infrastructure.rb
110
+ - lib/rbsim/hlmodel/mapping.rb
111
+ - lib/rbsim/hlmodel/process.rb
112
+ - lib/rbsim/numeric_units.rb
113
+ - lib/rbsim/simulator.rb
114
+ - lib/rbsim/statistics.rb
115
+ - lib/rbsim/tokens.rb
116
+ - lib/rbsim/version.rb
117
+ - new_process.rb
118
+ - rbsim.gemspec
119
+ - show_readme.rb
120
+ - sim.rb
121
+ - sim_bamboo.rb
122
+ - sim_process.rb
123
+ - sim_process_dsl.rb
124
+ - spec/dsl/infrastructure_nets_spec.rb
125
+ - spec/dsl/infrastructure_nodes_spec.rb
126
+ - spec/dsl/infrastructure_routes_spec.rb
127
+ - spec/dsl/mapping_spec.rb
128
+ - spec/dsl/process_spec.rb
129
+ - spec/dsl/program_spec.rb
130
+ - spec/dsl_and_hlmodel/new_process_spec.rb
131
+ - spec/hlmodel/net_spec.rb
132
+ - spec/hlmodel/process_spec.rb
133
+ - spec/hlmodel/route_spec.rb
134
+ - spec/hlmodel/routes_spec.rb
135
+ - spec/integration/basic_simulation_spec.rb
136
+ - spec/integration/net_spec.rb
137
+ - spec/integration/process_spec.rb
138
+ - spec/integration/rbsim_spec.rb
139
+ - spec/simulator/logger_spec.rb
140
+ - spec/simulator/stats_spec.rb
141
+ - spec/spec_helper.rb
142
+ - spec/statistics_spec.rb
143
+ - spec/tcpn/add_route_spec.rb
144
+ - spec/tcpn/cpu_spec.rb
145
+ - spec/tcpn/map_data_spec.rb
146
+ - spec/tcpn/network_spec.rb
147
+ - spec/tcpn/register_event_spec.rb
148
+ - spec/tcpn/route_to_self_spec.rb
149
+ - spec/tcpn/stats_spec.rb
150
+ - spec/tokens/data_queue_obsolete.rb
151
+ - spec/tokens/data_queue_spec.rb
152
+ - spec/units_spec.rb
153
+ - tcpn/model.rb
154
+ - tcpn/model/add_route.rb
155
+ - tcpn/model/application.rb
156
+ - tcpn/model/cpu.rb
157
+ - tcpn/model/map_data.rb
158
+ - tcpn/model/network.rb
159
+ - tcpn/model/register_event.rb
160
+ - tcpn/model/stats.rb
161
+ homepage: https://github.com/wrzasa/rbsim
162
+ licenses:
163
+ - GPL-3.0
164
+ metadata: {}
165
+ post_install_message:
166
+ rdoc_options:
167
+ - "--main"
168
+ - README.md
169
+ - "--title"
170
+ - RBSim -- Distributed system modeling and simulation tool
171
+ - "--line-numbers"
172
+ - "-A"
173
+ - "-x coverage"
174
+ require_paths:
175
+ - lib
176
+ required_ruby_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '2.0'
181
+ required_rubygems_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ requirements: []
187
+ rubyforge_project:
188
+ rubygems_version: 2.7.7
189
+ signing_key:
190
+ specification_version: 4
191
+ summary: Distributed inftastructure and system simulator with convenient DSL.
192
+ test_files:
193
+ - spec/dsl/infrastructure_nets_spec.rb
194
+ - spec/dsl/infrastructure_nodes_spec.rb
195
+ - spec/dsl/infrastructure_routes_spec.rb
196
+ - spec/dsl/mapping_spec.rb
197
+ - spec/dsl/process_spec.rb
198
+ - spec/dsl/program_spec.rb
199
+ - spec/dsl_and_hlmodel/new_process_spec.rb
200
+ - spec/hlmodel/net_spec.rb
201
+ - spec/hlmodel/process_spec.rb
202
+ - spec/hlmodel/route_spec.rb
203
+ - spec/hlmodel/routes_spec.rb
204
+ - spec/integration/basic_simulation_spec.rb
205
+ - spec/integration/net_spec.rb
206
+ - spec/integration/process_spec.rb
207
+ - spec/integration/rbsim_spec.rb
208
+ - spec/simulator/logger_spec.rb
209
+ - spec/simulator/stats_spec.rb
210
+ - spec/spec_helper.rb
211
+ - spec/statistics_spec.rb
212
+ - spec/tcpn/add_route_spec.rb
213
+ - spec/tcpn/cpu_spec.rb
214
+ - spec/tcpn/map_data_spec.rb
215
+ - spec/tcpn/network_spec.rb
216
+ - spec/tcpn/register_event_spec.rb
217
+ - spec/tcpn/route_to_self_spec.rb
218
+ - spec/tcpn/stats_spec.rb
219
+ - spec/tokens/data_queue_obsolete.rb
220
+ - spec/tokens/data_queue_spec.rb
221
+ - spec/units_spec.rb