Skip to content

Commit

Permalink
remove benchmark logging. datacite/datacite#881
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Nov 21, 2019
1 parent 7adc2f5 commit e6f3767
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 128 deletions.
34 changes: 4 additions & 30 deletions app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'benchmark'

class ClientsController < ApplicationController
include Countable

Expand Down Expand Up @@ -160,36 +158,12 @@ def totals
logger = Logger.new(STDOUT)

page = { size: 0, number: 1}
response = nil
bmt = Benchmark.ms {
state = current_user.present? && current_user.is_admin_or_staff? && params[:state].present? ? params[:state] : "registered,findable"
response = Doi.query(nil, provider_id: params[:provider_id], state: state, page: page, totals_agg: true)
}
if bmt > 10000
logger.warn "[Benchmark Warning] clients totals " + bmt.to_s + " ms"
else
logger.info "[Benchmark] clients totals " + bmt.to_s + " ms"
end
state = current_user.present? && current_user.is_admin_or_staff? && params[:state].present? ? params[:state] : "registered,findable"
response = Doi.query(nil, provider_id: params[:provider_id], state: state, page: page, totals_agg: true)
total = response.results.total

registrant = nil
bmc = Benchmark.ms {
registrant = total > 0 ? clients_totals(response.response.aggregations.clients_totals.buckets) : nil
}
if bmc > 10000
logger.warn "[Benchmark Warning] clients clients_totals " + bmc.to_s + " ms"
else
logger.info "[Benchmark] clients clients_totals " + bmc.to_s + " ms"
end

bmr = Benchmark.ms {
render json: registrant, status: :ok
}
if bmr > 10000
logger.warn "[Benchmark Warning] clients render " + bmr.to_s + " ms"
else
logger.info "[Benchmark] clients render " + bmr.to_s + " ms"
end
registrant = total > 0 ? clients_totals(response.response.aggregations.clients_totals.buckets) : nil
render json: registrant, status: :ok
end

protected
Expand Down
91 changes: 24 additions & 67 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'uri'
require 'base64'
require 'benchmark'

class DoisController < ApplicationController
include ActionController::MimeResponds
Expand Down Expand Up @@ -45,9 +44,7 @@ def index
params[:state] = "findable" if current_user.nil? || current_user.role_id == "user"

if params[:id].present?
logger.info "[Benchmark] find_by_id " + Benchmark.ms {
response = Doi.find_by_id(params[:id])
}.to_s + " ms"
response = Doi.find_by_id(params[:id])
elsif params[:ids].present?
response = Doi.find_by_id(params[:ids], page: page, sort: sort)
else
Expand Down Expand Up @@ -84,12 +81,6 @@ def index
end

begin
if response.took > 1000
logger.warn "[Benchmark Warning] Elasticsearch request " + response.took.to_s + " ms"
else
logger.info "[Benchmark] Elasticsearch request " + response.took.to_s + " ms"
end

# If we're using sample groups we need to unpack the results from the aggregation bucket hits.
if sample_group_field.present?
sample_dois = []
Expand All @@ -113,50 +104,24 @@ def index
total_pages = page[:size] > 0 ? (total_for_pages / page[:size]).ceil : 0
end

# we need to define those variables before the block
states = nil
resource_types = nil
created = nil
registered = nil
providers = nil
clients = nil
affiliations = nil
prefixes = nil
schema_versions = nil
sources = nil
link_checks_status = nil
links_with_schema_org = nil
link_checks_schema_org_id = nil
link_checks_dc_identifier = nil
link_checks_citation_doi = nil
links_checked = nil
subjects = nil
certificates = nil
bma = Benchmark.ms {
states = total > 0 ? facet_by_key(response.response.aggregations.states.buckets) : nil
resource_types = total > 0 ? facet_by_resource_type(response.response.aggregations.resource_types.buckets) : nil
created = total > 0 ? facet_by_year(response.response.aggregations.created.buckets) : nil
registered = total > 0 ? facet_by_year(response.response.aggregations.registered.buckets) : nil
providers = total > 0 ? facet_by_provider(response.response.aggregations.providers.buckets) : nil
clients = total > 0 ? facet_by_client(response.response.aggregations.clients.buckets) : nil
affiliations = total > 0 ? facet_by_affiliation(response.response.aggregations.affiliations.buckets) : nil
prefixes = total > 0 ? facet_by_key(response.response.aggregations.prefixes.buckets) : nil
schema_versions = total > 0 ? facet_by_schema(response.response.aggregations.schema_versions.buckets) : nil
sources = total > 0 ? facet_by_key(response.response.aggregations.sources.buckets) : nil
link_checks_status = total > 0 ? facet_by_cumulative_year(response.response.aggregations.link_checks_status.buckets) : nil
links_with_schema_org = total > 0 ? facet_by_cumulative_year(response.response.aggregations.link_checks_has_schema_org.buckets) : nil
link_checks_schema_org_id = total > 0 ? response.response.aggregations.link_checks_schema_org_id.value : nil
link_checks_dc_identifier = total > 0 ? response.response.aggregations.link_checks_dc_identifier.value : nil
link_checks_citation_doi = total > 0 ? response.response.aggregations.link_checks_citation_doi.value : nil
links_checked = total > 0 ? response.response.aggregations.links_checked.value : nil
subjects = total > 0 ? facet_by_key(response.response.aggregations.subjects.buckets) : nil
certificates = total > 0 ? facet_by_key(response.response.aggregations.certificates.buckets) : nil
}
if bma > 1000
logger.warn "[Benchmark Warning] aggregations " + bma.to_s + " ms"
else
logger.info "[Benchmark] aggregations " + bma.to_s + " ms"
end
states = total > 0 ? facet_by_key(response.response.aggregations.states.buckets) : nil
resource_types = total > 0 ? facet_by_resource_type(response.response.aggregations.resource_types.buckets) : nil
created = total > 0 ? facet_by_year(response.response.aggregations.created.buckets) : nil
registered = total > 0 ? facet_by_year(response.response.aggregations.registered.buckets) : nil
providers = total > 0 ? facet_by_provider(response.response.aggregations.providers.buckets) : nil
clients = total > 0 ? facet_by_client(response.response.aggregations.clients.buckets) : nil
affiliations = total > 0 ? facet_by_affiliation(response.response.aggregations.affiliations.buckets) : nil
prefixes = total > 0 ? facet_by_key(response.response.aggregations.prefixes.buckets) : nil
schema_versions = total > 0 ? facet_by_schema(response.response.aggregations.schema_versions.buckets) : nil
sources = total > 0 ? facet_by_key(response.response.aggregations.sources.buckets) : nil
link_checks_status = total > 0 ? facet_by_cumulative_year(response.response.aggregations.link_checks_status.buckets) : nil
links_with_schema_org = total > 0 ? facet_by_cumulative_year(response.response.aggregations.link_checks_has_schema_org.buckets) : nil
link_checks_schema_org_id = total > 0 ? response.response.aggregations.link_checks_schema_org_id.value : nil
link_checks_dc_identifier = total > 0 ? response.response.aggregations.link_checks_dc_identifier.value : nil
link_checks_citation_doi = total > 0 ? response.response.aggregations.link_checks_citation_doi.value : nil
links_checked = total > 0 ? response.response.aggregations.links_checked.value : nil
subjects = total > 0 ? facet_by_key(response.response.aggregations.subjects.buckets) : nil
certificates = total > 0 ? facet_by_key(response.response.aggregations.certificates.buckets) : nil

respond_to do |format|
format.json do
Expand Down Expand Up @@ -207,20 +172,12 @@ def index
is_collection: options[:is_collection]
}

bmr = Benchmark.ms {
# sparse fieldsets
fields = fields_from_params(params)
if fields
render json: DoiSerializer.new(results, options.merge(fields: fields)).serialized_json, status: :ok
else
render json: DoiSerializer.new(results, options).serialized_json, status: :ok
end
}

if bmr > 3000
logger.warn "[Benchmark Warning] render " + bmr.to_s + " ms"
# sparse fieldsets
fields = fields_from_params(params)
if fields
render json: DoiSerializer.new(results, options.merge(fields: fields)).serialized_json, status: :ok
else
logger.info "[Benchmark] render " + bmr.to_s + " ms"
render json: DoiSerializer.new(results, options).serialized_json, status: :ok
end
end

Expand Down
24 changes: 8 additions & 16 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'benchmark'

class EventsController < ApplicationController
include Identifiable

Expand Down Expand Up @@ -191,21 +189,15 @@ def index

options[:is_collection] = true

bmr = Benchmark.ms {
events_serialized = EventSerializer.new(results, options).serializable_hash
if @include.include?(:dois)
options[:include] =[]
doi_names = (results.map { |event| event.doi}).uniq().join(",")
events_serialized[:included] = DoiSerializer.new((Doi.find_by_id(doi_names).results), {is_collection: true}).serializable_hash.dig(:data)
end
render json: events_serialized, status: :ok
}

if bmr > 3000
logger.warn "[Benchmark Warning] Events render.} " + bmr.to_s + " ms"
else
logger.info "[Benchmark] Events render.} " + bmr.to_s + " ms"
events_serialized = EventSerializer.new(results, options).serializable_hash

if @include.include?(:dois)
options[:include] = []
doi_names = (results.map { |event| event.doi}).uniq().join(",")
events_serialized[:included] = DoiSerializer.new((Doi.find_by_id(doi_names).results), {is_collection: true}).serializable_hash.dig(:data)
end

render json: events_serialized, status: :ok
end

def destroy
Expand Down
18 changes: 3 additions & 15 deletions app/controllers/prefixes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'benchmark'

class PrefixesController < ApplicationController
before_action :set_prefix, only: [:show, :update, :destroy]
before_action :authenticate_user!
Expand Down Expand Up @@ -138,22 +136,12 @@ def update
end

def totals
logger = Logger.new(STDOUT)

page = { size: 0, number: 1}
response = nil
logger.info "[Benchmark] prefixes totals " + Benchmark.ms {
response = Doi.query(nil, client_id: params[:client_id], state: "findable,registered", page: page, totals_agg: true)
}.to_s + " ms"
response = Doi.query(nil, client_id: params[:client_id], state: "findable,registered", page: page, totals_agg: true)
total = response.results.total

registrant = nil
logger.info "[Benchmark] prefixes prefixes_totals " + Benchmark.ms {
registrant = total > 0 ? prefixes_totals(response.response.aggregations.prefixes_totals.buckets) : nil
}.to_s + " ms"
logger.info "[Benchmark] clients render " + Benchmark.ms {
render json: registrant, status: :ok
}.to_s + " ms"
registrant = total > 0 ? prefixes_totals(response.response.aggregations.prefixes_totals.buckets) : nil
render json: registrant, status: :ok
end

def destroy
Expand Down

0 comments on commit e6f3767

Please sign in to comment.