em-nodes 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/benchmark/client.rb CHANGED
@@ -2,10 +2,7 @@ require 'rubygems'
2
2
  require "bundler/setup"
3
3
  Bundler.require
4
4
 
5
- class Client < EM::Nodes::Client
6
- include HelloFeature
7
- include TaskFeature
8
-
5
+ class Client < EM::Nodes::DefaultClient
9
6
  def info
10
7
  { :name => "client" }
11
8
  end
@@ -13,15 +10,9 @@ class Client < EM::Nodes::Client
13
10
  def on_task(task_id, data)
14
11
  send_task_result(task_id, data + 1)
15
12
  end
16
-
17
- def unbind
18
- super
19
- EM.stop
20
- end
21
13
  end
22
14
 
23
15
  EM.run do
24
16
  puts "client run"
25
17
  Client.connect '/tmp/test_em_nodes_sock'
26
18
  end
27
-
@@ -0,0 +1,11 @@
1
+ require 'drb'
2
+
3
+ class DrbClient
4
+ def task(data)
5
+ data + 1
6
+ end
7
+ end
8
+
9
+ i = ARGV[0] || '0'
10
+ DRb.start_service("druby://127.0.0.1:111#{i}", DrbClient.new)
11
+ sleep
@@ -0,0 +1,34 @@
1
+ require 'drb'
2
+
3
+ CLIENTS_COUNT = 5
4
+ TASKS_COUNT = 100000
5
+
6
+ DRb.start_service
7
+ clients = []
8
+ CLIENTS_COUNT.times do |i|
9
+ clients << DRbObject.new(nil, "druby://127.0.0.1:111#{i}")
10
+ end
11
+
12
+ puts "start with clients #{clients.size}"
13
+
14
+ $res = 0
15
+ $res_count = 0
16
+ $mutex = Mutex.new
17
+
18
+ tm = Time.now
19
+ clients.map do |cl|
20
+ Thread.new do
21
+ data = 0
22
+ loop do
23
+ data = cl.task(data)
24
+ $mutex.synchronize do
25
+ $res_count += 1
26
+ $res += data
27
+ if $res_count >= TASKS_COUNT
28
+ puts "executed with #{Time.now - tm}, res: #{$res}, res_count: #{$res_count}"
29
+ exit
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end.each &:join
@@ -0,0 +1,10 @@
1
+ #!/bin/sh
2
+
3
+ ruby drb_server.rb &
4
+ sleep 0.4
5
+ ruby drb_client.rb 0 &
6
+ ruby drb_client.rb 1 &
7
+ ruby drb_client.rb 2 &
8
+ ruby drb_client.rb 3 &
9
+ ruby drb_client.rb 4 &
10
+
data/benchmark/server.rb CHANGED
@@ -5,10 +5,7 @@ Bundler.require
5
5
  CLIENTS_COUNT = 5
6
6
  TASKS_COUNT = 100000
7
7
 
8
- class Server < EM::Nodes::Server
9
- include HelloFeature
10
- include TaskFeature
11
-
8
+ class Server < EM::Nodes::DefaultServer
12
9
  def on_task_result(res)
13
10
  $res_count += 1
14
11
  $res += res
@@ -9,7 +9,6 @@ class EM::Nodes::Client < EM::Connection
9
9
 
10
10
  def post_init
11
11
  @alive = true
12
- EM::Nodes.logger.info { "Connected to server" }
13
12
  end
14
13
 
15
14
  def unbind
@@ -18,6 +17,7 @@ class EM::Nodes::Client < EM::Connection
18
17
  end
19
18
 
20
19
  def self.connect(host, port = nil, *args, &block)
20
+ EM::Nodes.logger.info { "Connecting to server #{host}:#{port}" }
21
21
  EM.connect(host, port, self, *args)
22
22
  end
23
23
  end
@@ -3,7 +3,7 @@ class EM::Nodes::DefaultClient < EM::Nodes::Client
3
3
  include TaskFeature
4
4
 
5
5
  def unbind
6
- super
6
+ super
7
7
  EM.next_tick { EM.stop }
8
8
  end
9
9
  end
@@ -31,6 +31,7 @@ class EM::Nodes::Server < EM::Connection
31
31
  end
32
32
 
33
33
  def post_init
34
+ super
34
35
  @data = OpenStruct.new
35
36
 
36
37
  self.comm_inactivity_timeout = inactivity_timeout if EM.reactor_running?
@@ -49,6 +50,7 @@ class EM::Nodes::Server < EM::Connection
49
50
  end
50
51
 
51
52
  def unbind
53
+ super
52
54
  @alive = false
53
55
  self.class.clients.delete self
54
56
  EM::Nodes.logger.info { "Client #{self.data.inspect} has disconnected" }
@@ -23,5 +23,10 @@ class EM::Nodes::Server
23
23
  self.data.ready = true
24
24
  EM::Nodes.logger.info { "Hello client #{self.data.inspect}" }
25
25
  end
26
+
27
+ def unbind
28
+ super
29
+ self.data.ready = false
30
+ end
26
31
  end
27
32
  end
@@ -2,5 +2,5 @@ module EventMachine
2
2
  end
3
3
 
4
4
  module EventMachine::Nodes
5
- VERSION = "0.2.2"
5
+ VERSION = "0.2.3"
6
6
  end
metadata CHANGED
@@ -1,78 +1,90 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: em-nodes
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 17
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 3
10
+ version: 0.2.3
5
11
  platform: ruby
6
- authors:
7
- - '''Konstantin Makarchev'''
12
+ authors:
13
+ - "'Konstantin Makarchev'"
8
14
  autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
- date: 2014-04-27 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2014-05-29 00:00:00 +04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ requirement: *id001
14
33
  name: eventmachine
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
34
  type: :runtime
35
+ - !ruby/object:Gem::Dependency
21
36
  prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
31
40
  - - ~>
32
- - !ruby/object:Gem::Version
33
- version: '1.5'
41
+ - !ruby/object:Gem::Version
42
+ hash: 5
43
+ segments:
44
+ - 1
45
+ - 5
46
+ version: "1.5"
47
+ requirement: *id002
48
+ name: bundler
34
49
  type: :development
50
+ - !ruby/object:Gem::Dependency
35
51
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ~>
39
- - !ruby/object:Gem::Version
40
- version: '1.5'
41
- - !ruby/object:Gem::Dependency
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ requirement: *id003
42
62
  name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
63
  type: :development
64
+ - !ruby/object:Gem::Dependency
49
65
  prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
66
+ version_requirements: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ requirement: *id004
56
76
  name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
77
  type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
78
  description: Simple EM client server, and some stuffs
70
- email:
71
- - '''kostya27@gmail.com'''
79
+ email:
80
+ - "'kostya27@gmail.com'"
72
81
  executables: []
82
+
73
83
  extensions: []
84
+
74
85
  extra_rdoc_files: []
75
- files:
86
+
87
+ files:
76
88
  - .gitignore
77
89
  - .rspec
78
90
  - Gemfile
@@ -80,7 +92,10 @@ files:
80
92
  - README.md
81
93
  - Rakefile
82
94
  - benchmark/client.rb
95
+ - benchmark/drb_client.rb
96
+ - benchmark/drb_server.rb
83
97
  - benchmark/run.sh
98
+ - benchmark/run_drb.sh
84
99
  - benchmark/server.rb
85
100
  - em-nodes.gemspec
86
101
  - examples/chat_client.rb
@@ -104,31 +119,41 @@ files:
104
119
  - spec/simple_spec.rb
105
120
  - spec/spec_helper.rb
106
121
  - spec/task_spec.rb
122
+ has_rdoc: true
107
123
  homepage: https://github.com/kostya/em-nodes
108
- licenses:
124
+ licenses:
109
125
  - MIT
110
- metadata: {}
111
126
  post_install_message:
112
127
  rdoc_options: []
113
- require_paths:
128
+
129
+ require_paths:
114
130
  - lib
115
- required_ruby_version: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - '>='
118
- - !ruby/object:Gem::Version
119
- version: '0'
120
- required_rubygems_version: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - '>='
123
- - !ruby/object:Gem::Version
124
- version: '0'
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ hash: 3
137
+ segments:
138
+ - 0
139
+ version: "0"
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ hash: 3
146
+ segments:
147
+ - 0
148
+ version: "0"
125
149
  requirements: []
150
+
126
151
  rubyforge_project:
127
- rubygems_version: 2.1.4
152
+ rubygems_version: 1.4.2
128
153
  signing_key:
129
- specification_version: 4
154
+ specification_version: 3
130
155
  summary: Simple EM client server, and some stuffs
131
- test_files:
156
+ test_files:
132
157
  - spec/base_spec.rb
133
158
  - spec/hello_spec.rb
134
159
  - spec/simple2_spec.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 2a95a56a414282e8e364694da3c4c6047a0aabac
4
- data.tar.gz: 8b48fd301eb081c7d35346f07aac1e30581a5a26
5
- SHA512:
6
- metadata.gz: 60ed94305f6d7009fe10130dc252e740e896f472719300c660b8cf01c9b93a6b39dfb8178f3ee15c76206c8eb2b5a2f55ba0c715153ec75c24e9eff324c3a9be
7
- data.tar.gz: af1caadc1bace8f2a75dc7d59fb09262456810fa711ff13637208d7d248d51e542db3c7cf91621ce41a97cbba0e33a98c72a3c1167eb5995672e0ba835b7643a