Instrumentation of Ruby Web Applications Motivation

Instrumentation of Ruby Web Applications
master thesis subject of
Martin Ennemoser (0855518)
in cooperation with
Compuware Cooperation
February 12, 2014, Linz
Abstract
Ruby is a modern programming language which has become popular for the development of large and complex web applications. These
applications often have to work under heavy load of a high number of
visitors. Hence, it is important to manage web application performance
in productive environments at runtime. Ob jective of this master thesis
is to implement a prototype which instruments Ruby web applications
in order to collect performance related information.
This prototype
should be integrated into dynaTrace accordingly.
Motivation
Nowadays many websites are built using scripting languages along with web
application frameworks in order to alleviate the development of dynamic
websites, web applications or web services. Many dierent scripting languages and frameworks exist which are used for dierent kinds of tasks. One
famous scripting language is Ruby which is actually a general programming
language but is mostly used for the development of web applications. Ruby
got popular with the emergence of Ruby on Rails (RoR) [1] which is a web
application framework written in Ruby. RoR has gained great popularity
among web developers in the last years. According to builtWith [2], Ruby
on Rails is listed as one of the most popular frameworks.
Web site owners are interested in how well their Ruby based websites perform and whether there are any performance bottlenecks present. There
are already tools available for monitoring and analyzing the performance of
Ruby web applications [3][4]. But these tools are either slow, framework
specic or give not enough information to obtain a comprehensive overview
where the application could be improved.
1
Objective
The objective of this master thesis is the development of a prototype for
dynaTrace [5] which is able to collect performance related information of
web based Ruby applications. This tool has to perform the following tasks:
• Interception of web requests and responses which are made to the ap-
plication.
• Instrumentation of web applications in order to collect information
about method executions. It should be possible to inject custom code
into methods in order to collect information like parameters or return
values.
• Collect CPU usage, garbage collector or memory information about
the running Ruby process.
• Sending the collected data to a central server for analysis and to track
execution.
This tool should not only be usable for RoR but for many (or all) Ruby
frameworks, even though RoR is by far the most prevalent one.
To achieve the listed tasks above, the system has to be divided into dierent
parts:
• Agent: The agent gets injected into the Ruby runtime. It is responsible
for the placement of the sensors to inject custom instrumentation code.
Furthermore, the agent has to transmit the collected performance information to the server.
• Sensors: Sensors (e.g. web request sensor, database sensor) are placed
in the web application or other parts of the system in order to collect
performance related information. This information is then forwarded
to the agent.
• The server's task is to analyze the collected data sent by the agents.
Figure 1 shows a typical Ruby based environment. The dynaTrace specic parts are depicted as boxes with a gray background. The web server
receives a request from a client and dispatches it to the application server.
The application server in turn dispatches the request to the target web application. The placed HTTP-sensor intercepts the request in order to measure
the response time. The sensor in the web application is responsible for the
collection of performance data like method execution times or parameter.
In addition, Figure 1 shows a database sensor which gets placed between a
Ruby object relational mapper and a database in order to collect information
about database queries.
2
Figure 1: Ruby environment with injected agent
Motivation
To achieve the objectives mentioned before the following steps have to be
taken:
1. Research of the most important Ruby interpreters: Which interpreters
are currently used? Which of them are relevant for this master thesis?
2. Research of the most important Ruby web application frameworks:
Which web application frameworks are important beside Ruby on Rails?
3. Research of Ruby performance tools: Which performance tools are
already available? How do they work? How can they be used in terms
of this master thesis?
4. Research about injection: Which possibilities exist in order to inject
custom code into the web application?
5. Implementation of the agent: To implement a prototype, the following
questions have to be answered rst:
(a) Is it necessary to access the internals of the interpreter in order
to obtain performance metrics? If yes, how could this be done?
(b) Is it possible to get performance metrics directly from the frameworks?
3
6. Implementation of the sensors: How can we inject custom code into
the application? How can we keep the injection overhead small? How
are the data collected and how are they transmitted to the agent?
7. Evaluation of the prototype: Test the tool on a real life application to
assess its performance.
References
[1] David Heinemeier Hansson. Ruby on rails. http://rubyonrails.org/.
[2] Builtwith. http://trends.builtwith.com/framework.
[3] Shugo Maeda and Charlie Savage. Ruby prof. https://github.com/
rdp/ruby-prof.
[4] Aman Gupta. Perftools. https://github.com/tmm1/perftools.rb.
[5] Compuware dynatrace software.
http://www.compuware.com/
application-performance-management/dynatrace-enterprise.
html.
[6] Christian Schwarzbauer. Instrumentation of Distributed .Net Applications for performance analysis under load, 2004.
4