A Statistical Approach for Identifying Memory Leaks in Cloud Applications
Total Page:16
File Type:pdf, Size:1020Kb
A STATISTICAL APPROACH FOR IDENTIFYING MEMORY LEAKS IN CLOUD APPLICATIONS Vladimir Sorˇ and Satish Narayana Srirama Institute of Computer Science, University of Tartu, J. Liivi 2, Tartu, Estonia Keywords: Troubleshooting, JavaTM Virtual Machine, Byte code instrumentation, Cloud computing, Tools. Abstract: This position paper describes the attempt to automate the statistical approach for memory leak detection in JavaTM applications. Proposed system extends the basic statistical memory leak detection method with further intelligence to pinpoint the source of the memory leak in the source code. As the method adds only small overhead in runtime it is designed to be used in production systems and will help detecting memory leaks in production environments without constraint to the source of the leak. Architecture of the proposed approach is intended to use in cloud applications. 1 INTRODUCTION in production under very specific circumstances (of- ten hardly specifiable) can be very hard to find and fix Memory leaks can be a major problem in distributed in development and test environments. applications, depleting their performance, even if they This is the area we think we can improve by de- run on platforms with automatic memory manage- veloping the solution that uses efficient statistical al- ment like Java Virtual Machine. Finding memory gorithm to detect memory leaks in advance, imposes leaks is coveredby many researches and there are sev- low overhead in production system and would help eral tools and methodologies to find memory leaks. tracking down the source of the leak. The rest of the However, these tools are incorporated in profilers and paper is organized as follows. Section 2 address the are designed to use in the development phase. On one related work in detail. Section 3 describes the statisti- hand, this is perfectly justified, as memory leaks are cal method we propose along with preliminary analy- bugs in software and finding bugs is a work for devel- sis. Section 4 discusses how cloud computing benefits opers. For this to happen it is expected that such bugs from such a method. Section 6 concludes the paper are found in test environment, or at least they can be with future research directions. reproduced or simulated in test environment. On the other hand, configuration of the production environment (e.g. integrations with real systems), up- 2 RELATED WORK time of the system is much longer, and the usage pat- terns that real users generate are much more rich than Memory leaks have been studied in the industryand in teams of Q/A and analysts could think of. All this research community extensively and currently there means that in production could happen more untested are several approaches for finding memory leaks in situations that may result in memory leaks. And a Java applications. memory leak even in a modern JVM will inevitably First option is the offline memory dump analy- result in the need for a restart of the JVM. sis. Offline in this context means that the memory Use of clustering and cloud computing (Armbrust dump is taken and then analyzed outside of the run- et al., 2009) reduce the impact of such restarts for ning JVM. Memory dump can be either requested the end user, who may even not notice anything, from the live JVM (during this procedure JVM ex- but for operations this still is a problem. Moreover, ecution is stopped) or it can be generated automati- cloud computing and virtualization brings in addi- cally by the JVM when out of memory condition oc- tional uncertainty of not knowing the configuration of curs. There are several algorithms to analyze memory the physical hardware on which the application is ac- dumps to detect possible leaking objects. For exam- tually running. Thus, a memory leak that only occurs ple (Maxwell, 2010) shows usage of graph mining al- Šor V. and Narayana Srirama S.. 623 A STATISTICAL APPROACH FOR IDENTIFYING MEMORY LEAKS IN CLOUD APPLICATIONS. DOI: 10.5220/0003389906230628 In Proceedings of the 1st International Conference on Cloud Computing and Services Science (CLOSER-2011), pages 623-628 ISBN: 978-989-8425-52-2 Copyright c 2011 SCITEPRESS (Science and Technology Publications, Lda.) CLOSER 2011 - International Conference on Cloud Computing and Services Science gorithms for this purpose. Eclipse Memory Analyzer ods for analyzing unnecessary references between ob- or MAT (The Eclipse Foundation, 2010) is an exam- jects: Cork, (Jump and McKinley, 2007) and stale ob- ple of productionquality heap dump analysis software jects: SWAT, (Chilimbi and Hauswirth, 2004). Cork which is freely available. However, such offline anal- implements statistical memory leak detection algo- ysis has several problems: heap dumps can be expen- rithm directly in the Virtual Machine by integrating sive to acquire in production environment (because the method in the garbage collector itself. Cork has generating a dump file requires freezing the applica- achieved significantly small performance penalty – tion) and heap dump files can be very big (up to sev- only 2% and good results in memory leak detection eral gigabytes, depending on the memory configura- (Jump and McKinley, 2007). The only problem is tion). Because of the file size it can be hard to run that this projectis implementedas a modulein the Re- analysis software on a regular development machine. search Virtual Machine (RVM) Jikes (The Jikes RVM Another drawback is the static nature of the memory Project, 2010), which makes it usable mostly in the dump – there is no information regarding the source research community, as the industry is not very keen of allocation of the objects, so finding the code re- anticipating the research VM. sponsible for memory leak is a separate task from just Biggest disadvantage of these methods is the need finding leaked objects. for qualified human operation to analyze gathered Another approach is to monitor certain collection data to find real place in the source code responsi- classes for unlimited growth. This approach relies ble for the memory leak. We think that this manual on bytecode instrumentation and one possible solu- decision and search process can also be automated. tion is described in (Xu and Rountev, 2008). This technique is also used in several Application Per- formance Monitoring (APM) suites. For example, 3 STATISTICAL APPROACH TO TM CA Wily IntroscopeR LeakHunter (CA Wily In- MEMORY LEAK DETECTION troscope, 2010) and AppDynamics (AppDynamics, 2010). Both APM suites add some intelligenceto ease Based on the review of related work we noted that finding the cause of the memory leak. Unfortunately there is still space for the automated end-to-end mem- there is no information about exact algorithms used in ory leak detection solution that would work on the them. Also, mentioned APM suites are targeted to the HotSpot or OpenJDK Java Virtual Machines, would Java Enterprise application and are not applicable for maximally assist the developer by pinpointing both example for desktop GUI applications. allocation and reference points of leaking objects and As alternative to direct bytecode instrumentation, would do that also in the distributed and cloud envi- aspect-oriented instrumentation may be used to find ronments with little performance penalty so it could the metrics needed for memory leak detection. Find- be usable in production systems. Similar idea about Leaks tool is using AspectJ pointcuts for this purpose memory leak detection with statistical method is de- to analyze references between objects and find out scribed in (Formanek and Sporar, 2006) as an ex- leaking objects together with the sites of allocation ample of application of dynamic Java byte code in- (Chen and Chen, 2007). In that paper only GUI ap- strumentation. However, so far it hasn’t been imple- plications were used for testing. mented end-to-endin any known profilers or scientific Profilers are often used in development for find- publications. ing memory leaks. Different profilers allow gathering There are several challenges for implementation different metrics that may help finding memory leaks. of this approach using standard tools: For example, profiler of the NetBeans IDE can obtain • Gathering the data with low overhead during run- object age which can then be used by human opera- time. As the number of objects during application tor to apply statistical method (Sedlacek, 2010). This is huge (for example, specJVM 2008 benchmark, data can be collected during object allocation profil- which we used to test performance impact, during ing. Major disadvantageof the profilersis the need for its 2 hour run created 877 958 317 objects). qualified and experienced operator who can find the actual leaking code. Inexperienced developer, given • Actually applying statistical method in real time the profiler, fact of the memory leak and reasonably to detect classes suspected to be leaking. big code base would be arguably successful in this • Apply dynamic byte code instrumentation to find process. spots of allocation and most importantly referenc- In addition to different instrumentation and byte ing objects (as actually objects referencing leak- code modification techniques there are several re- ing ones are sources of the leaks rather than those search projects applying different statistical meth- instantiating leaking objects). 624 A STATISTICAL APPROACH FOR IDENTIFYING MEMORY LEAKS IN CLOUD APPLICATIONS • Present findings in a user friendly way. space (Sun Microsystems Inc., 2003). So, as garbage The basis of the statistical method is the genera- collector has to keep track of object ages anyway to tional hypothesis or infant mortality of objects and it perform its work, the best place to collect the data is described in (Sun Microsystems Inc., 2003). Gen- for the statistical method would be the garbage col- erational hypothesis states that most of the objects lector itself. Unfortunately as of now it is not possible become unreachable very soon after creation, or in as there is no interface in OpenJDK or HotSpot vir- other words – they ”die” young.