stat-count-client 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 595651505fecffd5f682998e37926c9f741d3c1d
4
- data.tar.gz: 7ebed0499b909897e1fecf87b9178ca74354a432
3
+ metadata.gz: 87d871672e40a91293e2b061ef214c03c8f5e6a4
4
+ data.tar.gz: 379a6cad4f296795eae3fbc21ae97d23d650b496
5
5
  SHA512:
6
- metadata.gz: 69a7038be10efbb2139e4d145815085cea14acc243d0a0db57d50d9ce6b86f36318894b82a58d540d0ee13f7844d6b5678f19cf1406e27879f9190e02a9fb4f7
7
- data.tar.gz: 75c9141157a994a2f33474e404dfc5bcb3c3cc45db298bb1af05688be853627f7e002572ec1fa1feadeacf7837e3d4d91779c32b3ea0639a927f6699a854b1e5
6
+ metadata.gz: 4b32f31fe751b288e59eabc931bd3d442df8bb7a3bc4dfeeb692accf4abf5f4646f8ae53081dc42e233dac8035649c6a8e0eb077914d91fecfd9ba51043e87c8
7
+ data.tar.gz: ba2887361ca54a5c429fc2e36ddb5eced14a4d14538d4d17f7539f091f4a1c971ab7a43999fc907e06f8620870126ee8cd2ec108a3b5719990148e889843a624
@@ -0,0 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ stat-count-client (0.0.2)
5
+ hessian2
6
+ thrift-client
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ remote: http://192.168.3.220:9292/
11
+ specs:
12
+ bigdecimal (1.2.1)
13
+ hessian2 (2.0.0)
14
+ bigdecimal
15
+ thrift (0.9.1)
16
+ thrift-client (0.0.5)
17
+ thrift (~> 0.9.0)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ stat-count-client!
@@ -8,6 +8,10 @@
8
8
  # log.level: info
9
9
 
10
10
  module ConfigLoader
11
- LOADER = YAML.load_file("../config/stat-count-client.yaml");
12
- CONFIG = LOADER['stat.count']
11
+ begin
12
+ LOADER = YAML.load_file(File.join(File.dirname(__FILE__),"../config","stat-count-client.yaml"));
13
+ CONFIG = LOADER['stat.count']
14
+ rescue
15
+ CONFIG = {}
16
+ end
13
17
  end
@@ -15,22 +15,16 @@ module Stat
15
15
  include Stat::Count::Thrift
16
16
  @@logger = LoggerFactory.getLogger("StatCountThriftClient")
17
17
 
18
- def initialize(servers=nil, config=nil)
19
- servers ||= ENV['stat.count.domain'] || ConfigLoader::CONFIG['thrift.domain'] || "localhost:9090"
20
- config ||= ConfigLoader::CONFIG['thrift.config']
21
- if config.nil?
22
- config[:client_class] = RemoteSimpleCountCollecter::Client
23
- config[:application_exception_classes] = DataCollectionException
24
- else
25
- client_class = config['client_class'] || "RemoteSimpleCountCollecter::Client"
26
- config[:client_class] = eval(client_class)
27
- application_exception_classes_strs = config['application_exception_classes'] || ["DataCollectionException"]
28
- application_exception_classe=application_exception_classes_strs.collect { |class_str|
29
- eval(class_str)
30
- }
31
- config[:application_exception_classes] = application_exception_classe
32
- init(servers, config)
18
+ def initialize(config=nil)
19
+ config ||= ConfigLoader::CONFIG['thrift'] || {}
20
+ config['servers'] ||='localhost:9090'
21
+ config['client_class'] ||= 'Stat::Count::Thrift::RemoteSimpleCountCollecter::Client'
22
+ config['application_exception_classes'] ||= 'Stat::Count::Thrift::DataCollectionException'
23
+ config['timeout'] ||= 10
24
+ if !config['size'].nil? && config['size'] > 1
25
+ config['pool_timeout'] = 12
33
26
  end
27
+ init(config)
34
28
  end
35
29
 
36
30
 
@@ -136,12 +130,11 @@ module Stat
136
130
 
137
131
 
138
132
  private
139
- def init(servers, config)
140
- @@logger.info("Init Stat count client connect to thrift url: #{servers}, config: #{config}")
141
- puts servers
142
- puts config
133
+ def init(config)
134
+ @@logger.info("Init Stat count client connect to thrift config: #{config}")
135
+ puts "StatCount init config #{config}"
143
136
  begin
144
- @client = ThriftClient.new(servers, config)
137
+ @client = ThriftClient.new(config)
145
138
 
146
139
  @client.add_callback(:on_exception) { |method_name, e|
147
140
  @@logger.error("call #{method_name} fails! cause by: #{e.message}, " + "\n" + e.backtrace.join("\n"))
@@ -1,7 +1,7 @@
1
1
  module Stat
2
2
  module Count
3
3
  module Client
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,45 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
+ $:.unshift File.join(File.dirname(__FILE__),"..")
3
+
4
+ require "rubygems"
5
+ require "hessian2"
6
+ require "stat-count-client"
7
+ require_relative "count_mother"
8
+ require 'benchmark'
9
+
10
+ iterations = 100000
11
+ def reset(client)
12
+ client.reset("test", "1")
13
+ client.reset("testHour", "2")
14
+ client.reset("testDay", "3")
15
+ end
16
+
17
+ client = Stat::Count::Client::ThriftStatCountClient.new({"servers" => "localhost:9095"});
18
+ Benchmark.bm do |bm|
19
+ # joining an array of strings
20
+ bm.report do
21
+ iterations.times do
22
+ reset(client)
23
+ count = CountMother.createIncrCount
24
+ countResult = client.incrByCount(count)
25
+ # puts countResult.getResult()
26
+ end
27
+ end
28
+ end
29
+
30
+
31
+ client = Stat::Count::Client::StatCountClient.new("http://localhost:8080/stat-count-runtime/hessian/remoteSimpleCountCollecter");
32
+ Benchmark.bm do |bm|
33
+ # joining an array of strings
34
+ bm.report do
35
+ iterations.times do
36
+ reset(client)
37
+ count = CountMother.createIncrCount
38
+ countResult = client.incrByCount(count)
39
+ # puts countResult.getResult()
40
+ end
41
+ end
42
+ end
43
+
44
+
45
+
@@ -14,7 +14,7 @@ class TC_StatCountClientTest < Test::Unit::TestCase
14
14
  # Called before every test method runs. Can be used
15
15
  # to set up fixture information.
16
16
  def setup
17
- @client = ThriftStatCountClient.new("localhost:9095");
17
+ @client = ThriftStatCountClient.new({"servers" => "localhost:9095"});
18
18
  end
19
19
 
20
20
  # Called after every test method runs. Can be used to tear
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stat-count-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - gavin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-02 00:00:00.000000000 Z
11
+ date: 2013-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hessian2
@@ -46,17 +46,16 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - Gemfile
49
+ - Gemfile.lock
49
50
  - LICENSE
50
51
  - Rakefile
51
52
  - README.md
53
+ - test/benchmark.rb
52
54
  - test/count_mother.rb
53
55
  - test/stat_ccount_client_test.rb
54
56
  - test/stat_count_client_test.rb
55
57
  - test/test.rb
56
58
  - test/thrift_count_client_test.rb
57
- - lib/config_loader.rb
58
- - lib/hessian_data_utils.rb
59
- - lib/logger_factory.rb
60
59
  - lib/stat-count-client/config_loader.rb
61
60
  - lib/stat-count-client/hessian/stat_data_utils.rb
62
61
  - lib/stat-count-client/hessian_client.rb
@@ -95,6 +94,7 @@ signing_key:
95
94
  specification_version: 4
96
95
  summary: stat count client
97
96
  test_files:
97
+ - test/benchmark.rb
98
98
  - test/count_mother.rb
99
99
  - test/stat_ccount_client_test.rb
100
100
  - test/stat_count_client_test.rb
@@ -1,13 +0,0 @@
1
- #encoding: UTF-8
2
-
3
- #Example
4
- #stat.count:
5
- # hessian.domain: http://localhost:8080/stat-count-runtime/hessian/remoteSimpleCountCollecter
6
- # hessian.java.package: com.ximalaya.stat.count.data
7
- # log.file: D:/log/stat/stat-count-ruby.log
8
- # log.level: info
9
-
10
- module ConfigLoader
11
- LOADER = YAML.load_file("../config/stat-count-client.yaml");
12
- CONFIG = LOADER['stat.count']
13
- end
@@ -1,33 +0,0 @@
1
- #encoding: UTF-8
2
-
3
- module Hessian
4
- module Data
5
- module Utils
6
- def to_hash_unit
7
- hash = {}
8
- instance_variables.each {|var| hash[var.to_s.delete("@")] = instance_variable_get(var) }
9
- hash
10
- end
11
-
12
- def to_hash_map
13
- hash = {}
14
- instance_variables.each {|var|
15
- internal_hash = {}
16
- map = instance_variable_get(var)
17
- map.each { |key, list|
18
- newList = nil
19
- list.each { |unit|
20
- if (newList.nil?)
21
- newList = Array.new
22
- end
23
- newList << unit.to_hessian
24
- }
25
- internal_hash[key] = newList
26
- }
27
- hash[var.to_s.delete("@")] = internal_hash
28
- }
29
- hash
30
- end
31
- end
32
- end
33
- end
@@ -1,32 +0,0 @@
1
- #encoding: UTF-8
2
-
3
- require "logger"
4
- require "config_loader"
5
- require "monitor"
6
-
7
- class LoggerFactory
8
- include ConfigLoader
9
- @@logger = nil
10
- def self.getLogger(name)
11
- if @@logger.nil?
12
- @monitor = Monitor.new
13
- @monitor.synchronize do
14
- if @@logger.nil?
15
- log_path = CONFIG['log.file.'+name];
16
- if(log_path.nil?)
17
- log_path = "../log"
18
- end
19
-
20
- log_level = CONFIG['log.level.'+name]
21
- if(log_level.nil?)
22
- log_level = "error";
23
- end
24
- logger = Logger.new(log_path,'daily')
25
- logger.level = Logger::const_get(log_level.upcase)
26
- @@logger = logger;
27
- end
28
- end
29
- end
30
- @@logger
31
- end
32
- end