fluent-plugin-redis-counter 0.3.0 → 0.3.1

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjcyZmZkMWJmZWM1Y2IyMDg5YzY5OTc0Y2M2NDEyOWJjMDdlODBhNw==
4
+ YjI2ZDVjZjQ2ZjkyZGE4N2VlZDIxOTdhMGQzNWQ5MTUzYzUwYmIwYw==
5
5
  data.tar.gz: !binary |-
6
- ODk1ZmUyNWRlNjQzMWI1OWJjZTYyMDdlN2Y1ZjBkOTI3MWVmNGMzMw==
6
+ MTEyN2U5MDlhZmQ0NmZlNjhiMDEzNmFhNmYwYzdhMjA5NDliMDEwNw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- M2FjODc0ZjUwNzU1M2E3M2VmYWIzYmUyOTE5N2U3ZWU0ZDAxZjRhMzhjM2Yw
10
- ZjExNmE5OTVkNTk2YTZhODJiYTdhNjBhMmU0MzAwMDk0ZWU1ODZmNjBmMDUz
11
- NDc3MGE0ODRkYzZhYTkwZWIyYWYzNWNjZDRhMjI2NjhlOWQxMjE=
9
+ MmEwMjA0YTkxM2NhNWZiMWY5NmY1MzdjNTg0NDA3ZWI5YzQ3NTI5ZjhmNzQz
10
+ MGVkZDkxYmZlYjlhM2NjNDY4ZWMwNGE2MWFlODhkNjgzMThjYTliYWFlN2Vm
11
+ YmJmOGI2OGRmZGQ5ZmY5YzY4ZTlmYjVhMzIwY2UwNTRlYTYzMmE=
12
12
  data.tar.gz: !binary |-
13
- MjMyNmM4OWFmNzg4YmYzNGFlMWE5Yjk5OTBkYWQ0YzFmNTg5NTJlYTZmZDdh
14
- ZDBlY2EwMzI0YjlkZDE5YjVjZWE2MDk1OTE2Mjc2MzI3ZjBlMGZlMzQ2MjZl
15
- MThlNzQ2N2FhZmQyMTI1NzUyODUzNDIzMjA1NWI1YWFhOWM3NmE=
13
+ ZGUyYTI3MjYxZWRmYWVlY2M5OWEzZTI0ODM0MzNlODk4MmI1MGQ2NjU2Mzdj
14
+ MTdiYWEyNjAyOTA2MWQwNzQ3NmQxNDhkY2RkOGJmYjc2ZTMzODAzNTk0M2Iz
15
+ NWJkMjY3ZWJiZmZmMjRhMTY4NDNmMjEwNzlhMGUyZDA2NTdjMGI=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.3.1
2
+ * improve performance
3
+
1
4
  ## 0.3.0
2
5
  * count value can be picked up from JSON data contents.
3
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -0,0 +1,99 @@
1
+ require 'fluent/test'
2
+ require 'benchmark'
3
+
4
+ if ENV["PROFILE"]
5
+ require 'ruby-prof'
6
+ end
7
+
8
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
9
+ require 'fluent/plugin/out_redis_counter'
10
+
11
+ module PerformanceTestApp
12
+ class Benchmarker
13
+ def initialize
14
+ Fluent::Test.setup
15
+ @fluent = Fluent::Test::BufferedOutputTestDriver.new(Fluent::RedisCounterOutput).configure(%[
16
+ host localhost
17
+ port 6379
18
+ db_number 1
19
+ <pattern>
20
+ match_status ^2[0-9]{2}$
21
+ count_key_format status-normal:item_id:%_{item_id}
22
+ count_value 1
23
+ </pattern>
24
+ ])
25
+ end
26
+
27
+ def prepare
28
+ 10_0000.times do
29
+ item_id = ( rand * 10_0000 ).to_i
30
+ @fluent.emit({ "status" => "200", "item_id" => item_id })
31
+ end
32
+ end
33
+
34
+ def run
35
+ result = nil
36
+ profile = nil
37
+ Benchmark.bm do |x|
38
+ result = x.report {
39
+ if ENV["PROFILE"]
40
+ profile = RubyProf.profile do
41
+ @fluent.run
42
+ end
43
+ else
44
+ @fluent.run
45
+ end
46
+ }
47
+ end
48
+
49
+ if ENV["PROFILE"]
50
+ profile_printer = RubyProf::GraphPrinter.new(profile)
51
+ profile_printer.print(STDOUT, {})
52
+ end
53
+ $log.info("benchmark result: #{result}")
54
+ end
55
+ end
56
+
57
+ class MemoryWatcher
58
+ def initialize
59
+ end
60
+
61
+ def run(&block)
62
+ start_memory = get_memory(Process.pid)
63
+ pid = Process.fork do
64
+ block.call
65
+ end
66
+ @max_memory = 0
67
+ th = Thread.new do
68
+ begin
69
+ loop do
70
+ sleep(0.01)
71
+ msize = get_memory(pid)
72
+ if msize > @max_memory
73
+ @max_memory = msize
74
+ end
75
+ end
76
+ ensure
77
+ $log.info("start memory size:\t#{sprintf("%#10d", start_memory / 1024)}KB")
78
+ $log.info("max memory size:\t#{sprintf("%#10d", @max_memory / 1024)}KB")
79
+ end
80
+ end
81
+ Process.waitall
82
+ th.kill
83
+ end
84
+
85
+ def get_memory(pid)
86
+ `ps -h -o rss= -p #{pid}`.to_i * 1024
87
+ end
88
+ end
89
+ end
90
+
91
+ if $0 == __FILE__
92
+ parent = PerformanceTestApp::MemoryWatcher.new
93
+ app = PerformanceTestApp::Benchmarker.new
94
+ parent.run do
95
+ app.prepare
96
+ app.run
97
+ end
98
+ end
99
+
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "fluent-plugin-redis-counter"
6
- s.version = "0.3.0"
6
+ s.version = "0.3.1"
7
7
  s.description = "fluent-plugin-redis-counter is a fluent plugin to count-up/down redis keys."
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Buntaro Okada"]
@@ -3,6 +3,8 @@ module Fluent
3
3
  Fluent::Plugin.register_output('redis_counter', self)
4
4
  attr_reader :host, :port, :db_number, :redis, :patterns
5
5
 
6
+ config_param :max_pipelining, :integer, :default => 1000
7
+
6
8
  def initialize
7
9
  super
8
10
  require 'redis'
@@ -61,8 +63,12 @@ module Fluent
61
63
  }
62
64
  table.each_pair.select { |key, value|
63
65
  value != 0
64
- }.each { |key, value|
65
- @redis.incrby(key, value)
66
+ }.each_slice(@max_pipelining) { |items|
67
+ @redis.pipelined do
68
+ items.each do |key, value|
69
+ @redis.incrby(key, value)
70
+ end
71
+ end
66
72
  }
67
73
  end
68
74
 
@@ -75,10 +81,11 @@ module Fluent
75
81
  @format = format
76
82
  end
77
83
 
84
+ CUSTOM_KEY_EXPRESSION_RE = /(%_\{([^\}]+)\})/
85
+
78
86
  def key(record)
79
- @format.gsub(/(%_\{[^\}]+\})/) do |s|
80
- key = s.match(/\{([^\}]+)\}/)[1]
81
- record[key]
87
+ @format.gsub(CUSTOM_KEY_EXPRESSION_RE) do |s|
88
+ record[$2]
82
89
  end
83
90
  end
84
91
  end
@@ -105,6 +112,7 @@ module Fluent
105
112
  is_localtime = false
106
113
  end
107
114
  @count_key_format = [conf_element['count_key_format'], is_localtime]
115
+ @record_value_formatter = RecordValueFormatter.new(@count_key_format[0])
108
116
  end
109
117
 
110
118
  if conf_element.has_key?('count_value_key')
@@ -142,7 +150,7 @@ module Fluent
142
150
  if @count_key_format == nil
143
151
  @count_key
144
152
  else
145
- count_key = RecordValueFormatter.new(@count_key_format[0]).key(record)
153
+ count_key = @record_value_formatter.key(record)
146
154
  formatter = TimeFormatter.new(count_key, @count_key_format[1])
147
155
  formatter.format(time)
148
156
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-redis-counter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Buntaro Okada
@@ -52,6 +52,7 @@ files:
52
52
  - README.md
53
53
  - Rakefile
54
54
  - VERSION
55
+ - benchmark/performance_test.rb
55
56
  - fluent-plugin-redis-counter.gemspec
56
57
  - lib/fluent/plugin/out_redis_counter.rb
57
58
  - test/plugin/out_redis_counter.rb