Measuring Report Execution Time
This article will show you how to measure report execution time for a specific workspace. In this example, we want to know which reports are being computed longer than 5 seconds.
You have probably already heard about our GoodData Ruby tool. What can be done with the Ruby Tool? You can create new workspaces, add users, execute reports etc. If you are interested, the GoodData Ruby tool is available on GitHub, so you can fork your repository and collaborate on development.
Install the Ruby Tool
The Ruby tool is available as a Ruby gem, so if you don’t have it installed, do it right now. Use
sudo gem install gooddata
Using the Ruby Tool
Now, lets build the script that will do the business. In the beginning of the script, you need to include all gems that will be needed.
require 'rubygems'
require 'gooddata'
require 'benchmark'
require 'logger'
require 'pp'
Once we required all necessary gems, we need to initialize the variable where we’ll store the workspace ID and then connect to GoodData using your credentials and the workspace ID.
In GoodData, terms workspace and project denote the same entity. For example, project ID is exactly the same as workspace ID. See Find the Workspace ID.
pid = "projectID"
GoodData::connect 'user@email.com', 'password'
GoodData::use pid
Now, we are connected to the GoodData API and we can use the Ruby Tool functionality. It’s time to GET the list of reports and then send every report to the GoodData executor and measure the total report execution time using the Benchmark module:
result = GoodData::get "/gdc/md/#{pid}/query/reports"
reports = result["query"]["entries"].map {|r| GoodData::Report[r["link"]]}
long_running_reports = reports.find_all do |report|
measurement = Benchmark.realtime do
result = report.execute
end
puts measurement
measurement > 5
end
puts "Reports that took more than 5 secs to compute (#{long_running_reports.count})"
long_running_reports.each {|r| puts r.title}
As a result, you can see a list of reports that took longer than 5 seconds to compute. For sure you don’t need to print the names you can do whatever you want and use reports in your application. Do you want to try it? Download the script.
Check the example result: