Skip to content

Commit

Permalink
log slow reponses in dois controller with warn level
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jun 1, 2019
1 parent 3d5264c commit 051de01
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 18 deletions.
28 changes: 22 additions & 6 deletions app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 22 additions & 5 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down
31 changes: 24 additions & 7 deletions app/controllers/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 051de01

Please sign in to comment.