Skip to content

Commit

Permalink
Merge pull request #3473 from cosmo0920/optimize-metrics-plugins
Browse files Browse the repository at this point in the history
metrics: metrics_local: Remove key argument to optimize performance
  • Loading branch information
cosmo0920 committed Jul 30, 2021
2 parents 2610d90 + 200abba commit 7671d77
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 134 deletions.
12 changes: 6 additions & 6 deletions lib/fluent/plugin/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,27 @@ def create(namespace:, subsystem:,name:,help_text:,labels: {})
# This API is for cmetrics type.
end

def get(key)
def get
raise NotImplementedError, "Implement this method in child class"
end

def inc(key)
def inc
raise NotImplementedError, "Implement this method in child class"
end

def dec(key)
def dec
raise NotImplementedError, "Implement this method in child class"
end

def add(key, value)
def add(value)
raise NotImplementedError, "Implement this method in child class"
end

def sub(key, value)
def sub(value)
raise NotImplementedError, "Implement this method in child class"
end

def set(key, value)
def set(value)
raise NotImplementedError, "Implement this method in child class"
end

Expand Down
32 changes: 16 additions & 16 deletions lib/fluent/plugin/metrics_local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class LocalMetrics < Metrics

def initialize
super
@store = Hash.new(0)
@store = 0
@monitor = Monitor.new
end

Expand All @@ -48,47 +48,47 @@ def multi_workers_ready?
true
end

def get(key)
def get
@monitor.synchronize do
@store[key.to_s]
@store
end
end

def inc(key)
def inc
@monitor.synchronize do
@store[key.to_s] += 1
@store += 1
end
end

def dec_gauge(key)
def dec_gauge
@monitor.synchronize do
@store[key.to_s] -= 1
@store -= 1
end
end

def add(key, value)
def add(value)
@monitor.synchronize do
@store[key.to_s] += value
@store += value
end
end

def sub_gauge(key, value)
def sub_gauge(value)
@monitor.synchronize do
@store[key.to_s] -= value
@store -= value
end
end

def set_counter(key, value)
return if @store[key.to_s] > value
def set_counter(value)
return if @store > value

@monitor.synchronize do
@store[key.to_s] = value
@store = value
end
end

def set_gauge(key, value)
def set_gauge(value)
@monitor.synchronize do
@store[key.to_s] = value
@store = value
end
end
end
Expand Down

0 comments on commit 7671d77

Please sign in to comment.