background preloader

Tunning

Facebook Twitter

Presentation: Understanding Java Garbage Collection (And What You Can Do About It) Mechanical Sympathy: Lock-Based vs Lock-Free Concurrent Algorithms. Last week I attended a review session of the new JSR166StampedLock run by Heinz Kabutz at the excellent JCrete unconference. StampedLock is an attempt to address the contention issues that arise in a system when multiple readers concurrently access shared state. StampedLock is designed to perform better than ReentrantReadWriteLock by taking an optimistic read approach. While attending the session a couple of things occurred to me. Firstly, I thought it was about time I reviewed the current status of Java lock implementations. Secondly, that although StampedLock looks like a good addition to the JDK, it seems to miss the fact that lock-free algorithms are often a better solution to the multiple reader case. Test Case To compare implementations I needed an API test case that would not favour a particular approach.

Multiple implementations are built for each spaceship and exercised by a test harness. Note: Other CPUs and operating systems can produce very different results. Results Analysis. JVM Memory settings. Caliper - Microbenchmarking framework for Java. Performance and Memory Java Profiler - YourKit Java Profiler. Java Magic. Part 4: sun.misc.Unsafe - mishadoff thoughts. Java is a safe programming language and prevents programmer from doing a lot of stupid mistakes, most of which based on memory management. But, there is a way to do such mistakes intentionally, using Unsafe class. This article is a quick overview of sun.misc.Unsafe public API and few interesting cases of its usage. Unsafe instantiation Before usage, we need to create instance of Unsafe object. There is no simple way to do it like Unsafe unsafe = new Unsafe(), because Unsafe class has private constructor.

It also has static getUnsafe() method, but if you naively try to call Unsafe.getUnsafe() you, probably, get SecurityException. Using this method available only from trusted code. This is how java validates if code is trusted. We can make our code “trusted”. But it’s too hard. Unsafe class contains its instance called theUnsafe, which marked as private. Note: Ignore your IDE. Preferences -> Java -> Compiler -> Errors/Warnings -> Deprecated and restricted API -> Forbidden reference -> Warning. Introduction to JMH   | Java Performance Tuning Guide. By Mikhail Vorontsov JMH is a new microbenchmarking framework (first released late-2013). Its distinctive advantage over other frameworks is that it is developed by the same guys in Oracle who implement the JIT.

In particular I want to mention Aleksey Shipilev and his brilliant blog. JMH is likely to be in sync with the latest Oracle JRE changes, which makes its results very reliable. You can find JMH examples here. JMH has only 2 requirements (everything else are recommendations): You need jmh-core maven dependencyYou need to annotate test methods with @GenerateMicroBenchmark annotation This article will give you an overview of basic rules and abilities of JMH. How to run Add the following dependency to your pom file (check the latest jmh-core version at Maven Central): <dependencies><dependency><groupId>org.openjdk.jmh</groupId><artifactId>jmh-core</artifactId><version>0.4.2</version></dependency></dependencies> Create a Java class with a main method.

Test modes Time units State housekeeping. 5 things you didn't know about ... Java performance monitoring, Part 2. Full-featured, built-in profilers like JConsole and VisualVM sometimes cost more than they're worth in performance overhead — particularly in systems running on production hardware. So, in this second article focusing on Java performance monitoring, I'll introduce five command-line profiling tools that enable developers to focus on just one aspect of a running Java process. The JDK includes many command-line utilities that can be used to monitor and manage Java application performance. Although most of them are labeled "experimental" and therefore technically unsupported, they're still useful. Some might even be seed material for special-purpose tools that could be built using JVMTI or JDI (see Resources). 1. jps (sun.tools.jps) Many command-line tools require that you identify the Java process that you want to monitor.

The "VMID" identifier is not always the same as the native operating system process identifier ("pid"), which is why we need the JDK's jps utility. Back to top In conclusion. iNikem. Monitoring and detecting memory leaks in your java application. So your application is running out of memory, you’re spending days and nights analyzing your application hoping to catch the memory holes in your objects. The next steps will explain how to monitor and detect your memory leaks to make sure your app is on the safe side. 1. Memory leak suspicion If you have a suspicion there is a memory leak a convenient way to make sure it’s really there is using jconsole. You can locally or remotely connect jconsole to your app and let it monitor for a while(Hour, Half day, Overnight, Week..)

After connecting jconsole to your app start analyzing the “Memory” tab. 2. For this purpose I recommend using jisualVM. this tool is part of the JDK. . * Jmap is an oracle tool that prints all objects memory map tree for a given process. So basically you run the jmap on your remote server(for instance your production environment) and then analyze that file locally. 3. I personally like to use MAT(Memory Analyzer) ( 4. 5. Jmap - Memory Map. Eclipse Memory Analyzer (MAT) 1. Memory handling in Java Java handles its memory in two areas. The heap and the stack. We will start with a short overview of memory in general on a computer. Then the Java heap and stack is explained. Native memory is the memory which is available to a process, e.g. the Java process. The processor (CPU) of the computer computes the instructions to execute and stores its computation results into registers.

An operating system (OS) normally uses virtual memory to map the physical memory to memory which each process can see. Current 32-bit systems uses an extension (Physical Address Extension (PAE)) which extends the physical space to 36-bits of the operation system. Of course with a 64-bit OS this 4GB limitation does not exists any more. Java manages the memory for use. In the heap the Java Virtual Machine (JVM) stores all objects created by the Java application, e.g. by using the "new" operator. The memory for new objects is allocated on the heap at run time. 2. 2.2. 2.3. 6. 6.2. Memory Analyzer Open Source Project. Martin Anderson - threads v actors. 11 Best Practices for Low Latency Systems | CodeDependents. Its been 8 years since Google noticed that an extra 500ms of latency dropped traffic by 20% and Amazon realized that 100ms of extra latency dropped sales by 1%.

Ever since then developers have been racing to the bottom of the latency curve, culminating in front-end developers squeezing every last millisecond out of their JavaScript, CSS, and even HTML. What follows is a random walk through a variety of best practices to keep in mind when designing low latency systems. Most of these suggestions are taken to the logical extreme but of course tradeoffs can be made. (Thanks to an anonymous user for asking this question on Quora and getting me to put my thoughts down in writing). Choose the right language Scripting languages need not apply. Though they keep getting faster and faster, when you are looking to shave those last few milliseconds off your processing time you cannot have the overhead of an interpreted language. Keep it all in memory Keep data and processing colocated Batch your writes. Concurrency on the JVM. News September 2013.

Java Performance Tuning Java(TM) - see bottom of page Our valued sponsors who help make this site possible New Relic: Try free w/ production profiling and get a free shirt! ManageEngine's Site24x7: End-to-End analysis on Java EE web transactions. Sign up for FREE! AppDynamics: Get complete browser to backend visibility. News September 2013 Back to newsletter 154 contents Nearly two years ago I announced that "in two years time, you'll have the ability to performance monitor your production JVM with HotRockit Mission Control", and here, right on time, it's available with the Java 7 update 40 release, though it's now called "Java Mission Control". A note from this newsletter's sponsor New Relic - Try New Relic today and get your free Data Nerd shirt! Like jconsole, Java Mission Control has a bunch of plugins that look pretty interesting, based on Eclipse.

The licensing here is a taste of things in the new Oracle world. News Java performance tuning related news. Tools Articles Jack Shirazi. Blog - page 1.