Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics: metrics_local: Remove key argument to optimize performance #3473

Merged
merged 1 commit into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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