norikra 0.0.8-java → 0.0.9-java

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.
data/Gemfile CHANGED
@@ -2,5 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in norikra.gemspec
4
4
  gemspec
5
-
6
- gem "norikra-udf-woothee", :git => "file:///Users/tagomoris/Documents/norikra-udf-woothee"
data/README.md CHANGED
@@ -92,6 +92,12 @@ UDF as plugins over rubygems are available. For example, see 'norikra-udf-mock'
92
92
 
93
93
  TBD
94
94
 
95
+ ## Performance
96
+
97
+ Threads option available with command line options.
98
+
99
+ TBD
100
+
95
101
  ## Versions
96
102
 
97
103
  TBD
@@ -4,20 +4,35 @@ require 'thor'
4
4
  module Norikra
5
5
  class CLI < Thor
6
6
  desc "start", "start Norikra server process"
7
+
8
+ ### Server options
7
9
  option :host, :type => :string, :default => '0.0.0.0', :aliases => "-H", :desc => 'host address that server listen [0.0.0.0]'
8
10
  option :port, :type => :numeric, :default => 26571, :aliases => "-P", :desc => 'port that server uses [26571]'
9
11
  # option :config, :type => :string, :default => nil, :aliases => "-c", :desc => 'configuration file to define target/query [none]'
10
12
 
13
+ ### Execution options
11
14
  option :daemonize, :type => :boolean, :default => false, :aliases => "-d", \
12
15
  :desc => 'daemonize Norikra server [false (foreground)]'
13
16
  option :pidfile, :type => :string, :default => '/var/run/norikra.pid', :aliases => "-p", \
14
17
  :desc => "pidfile path when daemonized [/var/run/norikra.pid]"
15
18
 
19
+ ### Performance options
20
+ option :'inbound-threads', :type => :numeric, :default => 0, :desc => 'number of threads for inbound data'
21
+ option :'outbound-threads', :type => :numeric, :default => 0, :desc => 'number of threads for outbound data'
22
+ option :'route-threads', :type => :numeric, :default => 0, :desc => 'number of threads for events routing for query execution'
23
+ option :'timer-threads', :type => :numeric, :default => 0, :desc => 'number of threads for internal timers for query execution'
24
+ option :'inbound-thread-capacity', :type => :numeric, :default => 0
25
+ option :'outbound-thread-capacity', :type => :numeric, :default => 0
26
+ option :'route-thread-capacity', :type => :numeric, :default => 0
27
+ option :'timer-thread-capacity', :type => :numeric, :default => 0
28
+
29
+ ### Logging options
16
30
  option :logdir, :type => :string, :default => nil, :aliases => "-l", \
17
31
  :desc => "directory path of logfiles when daemonized [nil (console)]"
18
32
  option :'log-filesize', :type => :string, :default => '10MB'
19
33
  option :'log-backups' , :type => :numeric, :default => 10
20
34
 
35
+ ### Loglevel options
21
36
  option :'more-quiet', :type => :boolean, :default => false, :desc => 'set loglevel as ERROR'
22
37
  option :quiet, :type => :boolean, :default => false, :aliases => "-q", :desc => 'set loglevel as WARN'
23
38
  option :verbose, :type => :boolean, :default => false, :aliases => "-v", :desc => 'set loglevel as DEBUG'
@@ -31,6 +46,13 @@ module Norikra
31
46
  raise NotImplementedError if options[:daemonize]
32
47
  #TODO: pidcheck if daemonize
33
48
 
49
+ conf[:thread] = {
50
+ inbound: {threads: options[:'inbound-threads'], capacity: options[:'inbound-thread-capacity']},
51
+ outbound: {threads: options[:'outbound-threads'], capacity: options[:'outbound-thread-capacity']},
52
+ route_exec: {threads: options[:'route-threads'], capacity: options[:'route-thread-capacity']},
53
+ timer_exec: {threads: options[:'timer-threads'], capacity: options[:'timer-thread-capacity']},
54
+ }
55
+
34
56
  conf[:loglevel] = case
35
57
  when options[:'more-verbose'] then 'TRACE'
36
58
  when options[:verbose] then 'DEBUG'
@@ -41,6 +63,7 @@ module Norikra
41
63
  conf[:logdir] = options[:logdir]
42
64
  conf[:logfilesize] = options[:'log-filesize']
43
65
  conf[:logbackups] = options[:'log-backups']
66
+
44
67
  server = Norikra::Server.new( options[:host], options[:port], conf )
45
68
  server.run
46
69
  server.shutdown
@@ -16,11 +16,12 @@ module Norikra
16
16
  class Engine
17
17
  attr_reader :targets, :queries, :output_pool, :typedef_manager
18
18
 
19
- def initialize(output_pool, typedef_manager=nil)
19
+ def initialize(output_pool, typedef_manager, opts={})
20
20
  @output_pool = output_pool
21
- @typedef_manager = typedef_manager || Norikra::TypedefManager.new()
21
+ @typedef_manager = typedef_manager
22
22
 
23
- @service = com.espertech.esper.client.EPServiceProviderManager.getDefaultProvider
23
+ conf = configuration(opts)
24
+ @service = com.espertech.esper.client.EPServiceProviderManager.getDefaultProvider(conf)
24
25
  @config = @service.getEPAdministrator.getConfiguration
25
26
 
26
27
  @mutex = Mutex.new
@@ -34,6 +35,36 @@ module Norikra
34
35
  @waiting_queries = []
35
36
  end
36
37
 
38
+ def camelize(sym)
39
+ sym.to_s.split(/_/).map(&:capitalize).join
40
+ end
41
+
42
+ def configuration(opts)
43
+ conf = com.espertech.esper.client.Configuration.new
44
+ defaults = conf.getEngineDefaults
45
+
46
+ if opts[:thread]
47
+ t = opts[:thread]
48
+ threading = defaults.getThreading
49
+ [:inbound, :outbound, :route_exec, :timer_exec].each do |sym|
50
+ next unless t[sym] && t[sym][:threads] && t[sym][:threads] > 0
51
+
52
+ threads = t[sym][:threads].to_i
53
+ capacity = t[sym][:capacity].to_i
54
+ info "Engine #{sym} thread pool enabling", :threads => threads, :capacity => (capacity == 0 ? 'default' : capacity)
55
+
56
+ cam = camelize(sym)
57
+ threading.send("setThreadPool#{cam}".to_sym, true)
58
+ threading.send("setThreadPool#{cam}NumThreads".to_sym, threads)
59
+ if t[sym][:capacity] && t[sym][:capacity] > 0
60
+ threading.send("setThreadPool#{cam}Capacity".to_sym, capacity)
61
+ end
62
+ end
63
+ end
64
+
65
+ conf
66
+ end
67
+
37
68
  def start
38
69
  debug "norikra engine starting: creating esper runtime"
39
70
  @runtime = @service.getEPRuntime
@@ -135,9 +166,24 @@ module Norikra
135
166
  @output_pool = output_pool
136
167
  end
137
168
 
169
+ def type_convert(event)
170
+ event = (event.respond_to?(:getUnderlying) ? event.getUnderlying : event).to_hash
171
+ event.keys.each do |key|
172
+ trace "event content key:#{key}, value:#{event[key]}, value class:#{event[key].class}"
173
+ if event[key].respond_to?(:to_a)
174
+ event[key] = event[key].to_a
175
+ elsif event[key].respond_to?(:to_hash)
176
+ event[key] = event[key].to_hash
177
+ end
178
+ end
179
+ event
180
+ end
181
+
138
182
  def update(new_events, old_events)
139
- trace "updated event", :query => @query_name, :event => new_events
140
- @output_pool.push(@query_name, new_events)
183
+ t = Time.now.to_i
184
+ events = new_events.map{|e| [t, type_convert(e)]}
185
+ trace "updated event", :query => @query_name, :event => events
186
+ @output_pool.push(@query_name, events)
141
187
  end
142
188
  end
143
189
  ##### Unmatched events are simply ignored
@@ -12,8 +12,6 @@ module Norikra
12
12
  end
13
13
 
14
14
  def push(query_name, events)
15
- t = Time.now.to_i
16
- events = events.map{|e| [t, (e.respond_to?(:getUnderlying) ? e.getUnderlying : e).to_hash]}
17
15
  @mutex.synchronize do
18
16
  @pool[query_name] ||= []
19
17
  @pool[query_name].push(events) if events.size > 0
@@ -26,7 +26,7 @@ module Norikra
26
26
 
27
27
  Norikra::Log.init(conf[:loglevel], conf[:logdir], {:filesize => conf[:logfilesize], :backups => conf[:logbackups]})
28
28
 
29
- @engine = Norikra::Engine.new(@output_pool, @typedef_manager)
29
+ @engine = Norikra::Engine.new(@output_pool, @typedef_manager, {thread: conf[:thread]})
30
30
  @rpcserver = Norikra::RPC::HTTP.new(:engine => @engine, :port => port)
31
31
  end
32
32
 
@@ -1,3 +1,3 @@
1
1
  module Norikra
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: norikra
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.8
5
+ version: 0.0.9
6
6
  platform: java
7
7
  authors:
8
8
  - TAGOMORI Satoshi
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-14 00:00:00.000000000 Z
12
+ date: 2013-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mizuno