-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.txt
64 lines (46 loc) · 2.39 KB
/
README.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Summary
Jstreusel is a JVMTI agent which enables tracking of memory usage on
a "per request" basis.
Motivation
In a multithreaded web application, it can be difficult to diagnose resource
utilization problems. The resource I am trying to investigate here is
memory consumption. Since the memory is owned by a single process which may
be handling multiple, varied requests, it's hard to say why memory usage is
high at any given time.
It could be due to:
- lots of concurrent requests where each consumes some memory.
- a particular request results in a large amount of memory being consumed.
Couple this with using 3rd party libraries, such as Hibernate, it can be
difficult to predict a priori what the memory usage will be.
In general, many failures can be gracefully handled in Java. However,
out of memory exceptions are especially dangerous because memory is a
common resource, so a memory problem in one thread can cause issues for
an unrelated request. This makes it much more difficult to understand
the root cause.
Background
This started as a morning of hacking around. The goal
was to produce a tool for tracking and monitoring memory consumption
on a per-request basis for diagnosing memory leaks in JVM based web
applications.
This tool is only minorly evasive and allows you to track "per request"
memory consumption. (Where a request is defined as a period of
execution on a single thread.) There shouldn't be any extra memory
consumed per allocation while the agent is loaded and it can be run
in a stock jvm.
Usage
There are basically three calls:
startRequest()
endRequest()
List<RequestStats> getRequestStats()
startRequest() should be called when a new request has begun. It will
return a sequential id which will be used to track all subsequent memory
allocations performed be this thread.
Then, after the request is complete, endRequest() can be invoked to stop
tracking memory allocations within the current thread.
To get summary statistics of the heap organized broken up by requestId,
call getRequestStats(). This will in turn perform a garbage collection
(so that only memory still referenced remains) and then the heap is
walked, and the memory is tabulated by requestId.
Included in the distribution is a servlet filter which performs the
startRequest() and endRequest() as well as produces an html report
with the current stats when the "memory-info" url is hit.