Skip to content

Commit

Permalink
Add more timings
Browse files Browse the repository at this point in the history
  • Loading branch information
pverscha committed Mar 26, 2024
1 parent 354841b commit 3fe363e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
21 changes: 15 additions & 6 deletions app/controllers/mpa_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ def pept2data
return
end

database_time = 0;
aggregation_time = 0;
index_time = 0
index_parse_time = 0
database_time = 0
aggregation_time = 0

peptides.each_slice(50) do |peptide_slice|
# Convert the peptide_slice array into a JSON string
Expand All @@ -34,13 +36,17 @@ def pept2data
request.content_type = "application/json"
request.body = json_data

starting_index_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
# Set up the HTTP session
response = Net::HTTP.start(uri.hostname, uri.port) do |http|
http.request(request)
end
index_time += Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting_index_time

start_index_parse_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
# Parse the response body as JSON
response_data = JSON.parse(response.body)
index_parse_time += Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_index_parse_time

# Keep track of all proteins that we need to retrieve extra information for from the database
proteins = Set.new
Expand All @@ -49,13 +55,13 @@ def pept2data
proteins.merge(item["uniprot_accessions"])
end

starting_databes_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
starting_databases_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)

# Now, retrieve all of these protein accessions from the database and retrieve the functions associated with them.
entries = UniprotEntry
.where(uniprot_accession_number: proteins.to_a.uniq)

database_time += Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting_databes_time
database_time += Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting_databases_time

# Convert the retrieved entries to a hash (for easy retrieval)
accession_to_protein = Hash.new
Expand Down Expand Up @@ -89,8 +95,11 @@ def pept2data
entry["lineage"] = @lineages[entry["lca"].to_i]
end

@response["database_time"] = database_time
@response["aggregation_time"] = aggregation_time
@timings = Hash.new
@timings["index_time"] = index_time
@timings["index_parse_time"] = index_parse_time
@timings["database_time"] = database_time
@timings["aggregation_time"] = aggregation_time

@response
end
Expand Down
4 changes: 4 additions & 0 deletions app/views/mpa/pept2data.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
json.peptides(@response.values)
json.index_time @timings["index_time"]
json.index_parse_time @timing["index_parse_time"]
json.database_time @timings["database_time"]
json.aggregation_time @timings["aggregation_time"]

0 comments on commit 3fe363e

Please sign in to comment.