This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
The following commit(s) were added to refs/heads/master by this push:
new 112fac1e More detailed timings
112fac1e is described below
commit 112fac1e13de14e541aa0a79452ed6c50d3a37b7
Author: Sebb <[email protected]>
AuthorDate: Sat Feb 15 13:59:08 2025 +0000
More detailed timings
---
www/status/index.cgi | 20 ++++++++++++++++----
www/status/monitor.rb | 21 ++++++++++++++++++++-
2 files changed, 36 insertions(+), 5 deletions(-)
diff --git a/www/status/index.cgi b/www/status/index.cgi
index 6697f068..73c45b22 100755
--- a/www/status/index.cgi
+++ b/www/status/index.cgi
@@ -6,15 +6,26 @@ require 'time'
require 'whimsy/asf/status'
json = File.expand_path('../status.json', __FILE__)
-status = JSON.parse(File.read(json)) rescue {}
-
+begin
+ status = JSON.parse(File.read(json))
+rescue
+ $stderr.puts "Failed to read status.json: #{e}"
+ status = {}
+end
+timings = [] # more debug timing
t1 = Time.now # Try to find where time is being spent
# Get new status every minute
if not status[:mtime] or Time.now - Time.parse(status[:mtime]) > 60
begin
require_relative './monitor'
- status = StatusMonitor.new.status || {}
+ t1a = Time.now
+ sm = StatusMonitor.new
+ t1b = Time.now
+ status = sm.status || {}
+ t1c = Time.now
+ timings = sm.timings || []
+ t1d = Time.now
rescue Exception => e
print "Status: 500 Internal Server Error\r\n"
print "Context-Type: text/plain\r\n\r\n"
@@ -112,5 +123,6 @@ EOF
t5 = Time.now
if t5 - t1 > 2 # seconds
- $stderr.puts "Times: #{t2-t1} #{t3-t2} #{t4-t3} #{t5-t4} Overall: #{t5-t1}"
+ $stderr.puts "Times1: #{t2-t1} (#{t1a -t1} #{t1b -t1a} #{t1c -t1b} #{t1d
-t1c}) #{t3-t2} #{t4-t3} #{t5-t4} Overall: #{t5-t1}"
+ $stderr.puts "Times2: #{timings.each_cons(2).map{|a,b| b-a}} Overall:
#{timings[-1]-timings[0]}"
end
diff --git a/www/status/monitor.rb b/www/status/monitor.rb
index 7fc3b972..0963b3f2 100644
--- a/www/status/monitor.rb
+++ b/www/status/monitor.rb
@@ -31,16 +31,27 @@ class StatusMonitor
LEVELS = %w(success info warning danger fatal)
attr_reader :status
+ attr_reader :timings # debug timings
def initialize(args = [])
+ @timings = []
+ timings << Time.now
status_file = File.expand_path('../status.json', __FILE__)
File.open(status_file, File::RDWR|File::CREAT, 0644) do |file|
+ timings << Time.now
# lock the file
mtime = File.exist?(status_file) ? File.mtime(status_file) : Time.at(0)
file.flock(File::LOCK_EX)
+ timings << Time.now
# fetch previous status (using symbolic keys)
- baseline = JSON.parse(file.read, {symbolize_names: true}) rescue {}
+ begin
+ baseline = JSON.parse(file.read, {symbolize_names: true})
+ rescue Exception => e
+ $stderr.puts "Failed to read status.json: #{e}"
+ baseline = {}
+ end
+ timings << Time.now
baseline[:data] = {} unless baseline[:data].instance_of? Hash
# If status was updated while waiting for the lock, use the new status
@@ -49,6 +60,7 @@ class StatusMonitor
return
end
+ timings << Time.now
# start each monitor in a separate thread
threads = []
self.class.singleton_methods.sort.each do |method|
@@ -90,24 +102,31 @@ class StatusMonitor
end
end
+ timings << Time.now
# collect status from each monitor thread
newstatus = {}
threads.each do |thread|
+ timings << Time.now
thread.join
+ timings << Time.now
newstatus[thread[:name]] = thread[:status]
end
+ timings << Time.now
# normalize status
@status = normalize(data: newstatus)
+ timings << Time.now
File.write(File.expand_path('../../logs/status.data', __FILE__),
@status.inspect)
+ timings << Time.now
# update results
file.rewind
file.write JSON.pretty_generate(@status)
file.flush
file.truncate(file.pos)
+ timings << Time.now
end
end