diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index 5711b746d..41d1ae1bf 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -134,18 +134,34 @@ def totals page = { size: 0, number: 1} response = nil - logger.info "[Benchmark] clients totals " + Benchmark.ms { + bmt = Benchmark.ms { response = Doi.query(nil, provider_id: params[:provider_id], state: params[:state], page: page, totals_agg: true) - }.to_s + " ms" + } + if bmt > 10000 + logger.warn "[Benchmark Warning] clients totals " + bmt.to_s + " ms" + else + logger.info "[Benchmark] clients totals " + bmt.to_s + " ms" + end total = response.results.total registrant = nil - logger.info "[Benchmark] clients clients_totals " + Benchmark.ms { + bmc = Benchmark.ms { registrant = total > 0 ? clients_totals(response.response.aggregations.clients_totals.buckets) : nil - }.to_s + " ms" - logger.info "[Benchmark] clients render " + Benchmark.ms { + } + 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 - }.to_s + " ms" + } + if bmr > 10000 + logger.warn "[Benchmark Warning] clients render " + bmr.to_s + " ms" + else + logger.info "[Benchmark] clients render " + bmr.to_s + " ms" + end end protected diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index 1a7315937..5a4b8b3ce 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -76,7 +76,11 @@ def index end begin - logger.info "[Benchmark] Elasticsearch request " + response.took.to_s + " ms" + 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? @@ -101,6 +105,7 @@ 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 @@ -117,7 +122,7 @@ def index link_checks_citation_doi = nil links_checked = nil subjects = nil - logger.info "[Benchmark] aggregations " + Benchmark.ms { + 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 @@ -134,7 +139,12 @@ def index 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 - }.to_s + " ms" + } + if bma > 1000 + logger.warn "[Benchmark Warning] aggregations " + bma.to_s + " ms" + else + logger.info "[Benchmark] aggregations " + bma.to_s + " ms" + end respond_to do |format| format.json do @@ -177,10 +187,17 @@ def index :current_ability => current_ability, } - logger.info "[Benchmark] render " + Benchmark.ms { + bmr = Benchmark.ms { render json: DoiSerializer.new(results, options).serialized_json, status: :ok - }.to_s + " ms" + } + + if bmr > 3000 + logger.warn "[Benchmark Warning] render " + bmr.to_s + " ms" + else + logger.info "[Benchmark] render " + bmr.to_s + " ms" + end end + format.citation do # fetch formatted citations render citation: response.records.to_a, style: params[:style] || "apa", locale: params[:locale] || "en-US" diff --git a/app/controllers/providers_controller.rb b/app/controllers/providers_controller.rb index c99766d8b..45ad6c777 100644 --- a/app/controllers/providers_controller.rb +++ b/app/controllers/providers_controller.rb @@ -187,21 +187,38 @@ def totals page = { size: 0, number: 1} response = nil - logger.info "[Benchmark] providers totals " + Benchmark.ms { + bmt = Benchmark.ms { response = Doi.query("", state: params[:state], page: page, totals_agg: true) - }.to_s + " ms" + } + + if bmt > 10000 + logger.warn "[Benchmark Warning] providers totals " + bmt.to_s + " ms" + else + logger.info "[Benchmark] providers totals " + bmt.to_s + " ms" + end + total = response.results.total registrant = nil - logger.info "[Benchmark] providers providers_totals " + Benchmark.ms { + bmp = Benchmark.ms { registrant = total > 0 ? providers_totals(response.response.aggregations.providers_totals.buckets) : nil - }.to_s + " ms" - logger.info "[Benchmark] providers render " + Benchmark.ms { + } + if bmp > 10000 + logger.warn "[Benchmark Warning] providers providers_totals " + bmp.to_s + " ms" + else + logger.info "[Benchmark] providers providers_totals " + bmp.to_s + " ms" + end + + bmr = Benchmark.ms { render json: registrant, status: :ok - }.to_s + " ms" + } + if bmr > 10000 + logger.warn "[Benchmark Warning] providers render " + bmr.to_s + " ms" + else + logger.info "[Benchmark] providers render " + bmr.to_s + " ms" + end end - # don't delete, but set deleted_at timestamp # a provider with active clients or with prefixes can't be deleted def destroy