pigato 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 006a5eeffba25d949d31e70896e14f45948c3398
4
- data.tar.gz: 17181c572ada29a77a007636415bb20a87e785f4
3
+ metadata.gz: 767b55541e28f390d0a978bc478cb209d8022e48
4
+ data.tar.gz: 7ad212b6cd040e718a74cff8f54e1383c01a7cc9
5
5
  SHA512:
6
- metadata.gz: 2df204b3748cf487b2fe3c177f2cd65ec9d52fd8bb721b493cb61d11b69838c53c1f4dced7eff1ccfe9dbbbc747648c495b4026fad135381696742a150e74529
7
- data.tar.gz: 4426e095848a3907a79f6a6e06ed2b0f3f594df6bfb46a3b66e11b86d7d2b669dd765e9a8414486d39a2a92d9627981ef6a7b8e69060fa474c2df4a240a82270
6
+ metadata.gz: 5679ae6ea22bd9a45275f8de037bf2c8abbda0a3a1cb5b914a72a4417005f083902ed3deb1fc175c7e525f1c9662b373e55e4d56a68c5a9bd06b6e9d1ac1ce10
7
+ data.tar.gz: 4fa094d344f1e726b47610e003c16d10747626c7e54ef99b76aada96193d4d1ce2c103b0ed0d157c60b7038bb6025ce5164d6bb5c3bc041165655264ea0612f4
@@ -4,11 +4,12 @@ require "rubygems"
4
4
  require "#{File.dirname(__FILE__)}/../lib/pigato.rb"
5
5
 
6
6
  client = PigatoClient.new('tcp://localhost:55555')
7
- requests = 10
7
+ requests = 1000
8
+ d1 = Time.now
8
9
  requests.times do |i|
9
10
  begin
10
- puts client.send('echo', 'Hello world')
11
+ client.send('echo', 'Hello world')
11
12
  end
12
13
  end
13
-
14
- puts "#{requests} requests/replies processed"
14
+ d2 = Time.now
15
+ puts "#{requests} requests/replies processed (#{(d2 - d1) * 1000} milliseconds)"
data/lib/pigato/client.rb CHANGED
@@ -1,5 +1,4 @@
1
- require "json"
2
- require "ffi-rzmq"
1
+ require "oj"
3
2
  require "securerandom"
4
3
 
5
4
  class PigatoClient
@@ -9,45 +8,49 @@ class PigatoClient
9
8
  @context = ZMQ::Context.new(1)
10
9
  @client = nil
11
10
  @poller = ZMQ::Poller.new
11
+ @timeout = 2500
12
12
 
13
13
  reconnect_to_broker
14
14
  end
15
15
 
16
- def send service, request, timeout = 2500
17
- request = [request.to_json]
16
+ def send service, request, timeout = @timeout
17
+ request = [Oj.dump(request)]
18
18
 
19
19
  rid = SecureRandom.uuid
20
20
  request = [Pigato::C_CLIENT, Pigato::W_REQUEST, service, rid].concat(request)
21
21
  @client.send_strings request
22
22
 
23
- res = Array.new
24
- res << rid
25
-
26
- data = Array.new
23
+ res = []
27
24
  while 1 do
28
- chunk = _recv(timeout)
29
- data << chunk[4]
25
+ chunk = _recv(rid, timeout)
26
+ break if chunk == nil
27
+ res << Oj.load(chunk[4])
30
28
  break if chunk[0] == Pigato::W_REPLY
31
29
  end
32
30
 
33
- res << data
34
31
  res
35
32
  end
36
33
 
37
- def _recv timeout
34
+ def _recv rid, timeout = @timeout
38
35
  items = @poller.poll(timeout)
39
- if items
40
- messages = []
41
- @client.recv_strings messages
36
+ if items
37
+ msg = []
38
+ d1 = Time.now
39
+ while 1 do
40
+ @client.recv_strings(msg, ZMQ::DONTWAIT)
41
+ msg = [] if msg.length < 5 || msg[3] != rid
42
+ break if msg.length > 0 || ((Time.now - d1) * 1000 > timeout)
43
+ end
44
+
45
+ return nil if msg.length == 0
42
46
 
43
47
  # header
44
- if messages.shift != Pigato::C_CLIENT
48
+ if msg.shift != Pigato::C_CLIENT
45
49
  raise RuntimeError, "Not a valid Pigato message"
46
50
  end
47
51
 
48
- return messages
52
+ return msg
49
53
  end
50
-
51
54
  nil
52
55
  end
53
56
 
@@ -1,3 +1,3 @@
1
1
  module Pigato
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
data/lib/pigato/worker.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "json"
1
+ require "oj"
2
2
  require "ffi-rzmq"
3
3
  require "securerandom"
4
4
 
@@ -25,7 +25,7 @@ class PigatoWorker
25
25
  end
26
26
 
27
27
  def reply reply
28
- reply = [@reply_to, '', @reply_rid, '0'].concat([reply.to_json])
28
+ reply = [@reply_to, '', @reply_rid, '0'].concat([Oj.dump(reply)])
29
29
  send_to_broker Pigato::W_REPLY, reply, nil
30
30
  end
31
31
 
@@ -37,28 +37,29 @@ class PigatoWorker
37
37
 
38
38
  items = @poller.poll(@timeout)
39
39
  if items
40
- messages = []
41
- @worker.recv_strings messages
40
+ msg = []
41
+ @worker.recv_strings msg
42
42
 
43
43
  @liveness = HEARTBEAT_LIVENESS
44
44
 
45
- header = messages.shift
45
+ header = msg.shift
46
46
  if header != Pigato::W_WORKER
47
47
  puts "E: Header is not Pigato::WORKER"
48
+ next
48
49
  end
49
50
 
50
- command = messages.shift
51
+ command = msg.shift
51
52
 
52
53
  case command
53
54
  when Pigato::W_REQUEST
54
55
  # We should pop and save as many addresses as there are
55
56
  # up to a null part, but for now, just save one...
56
- puts "REQUEST"
57
- @reply_to = messages.shift
58
- @reply_service = messages.shift
59
- messages.shift # empty
60
- @reply_rid = messages.shift
61
- return messages[0] # We have a request to process
57
+ @reply_to = msg.shift
58
+ @reply_service = msg.shift
59
+ msg.shift # empty
60
+ @reply_rid = msg.shift
61
+ val = Oj.load(msg[0]) # We have a request to process
62
+ return val
62
63
  when Pigato::W_HEARTBEAT
63
64
  # do nothing
64
65
  when Pigato::W_DISCONNECT
data/pigato.gemspec CHANGED
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 1.8"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_runtime_dependency "ffi-rzmq", "~> 2.0"
25
+ spec.add_runtime_dependency "oj", "~> 2.2.0"
25
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pigato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paolo Ardoino
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-07 00:00:00.000000000 Z
11
+ date: 2015-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: oj
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.2.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.2.0
55
69
  description: PIGATO-RUBY
56
70
  email:
57
71
  - paolo.ardoino@gmail.com