Posts

Simple Event Driven design

Overview Developers often ask about the performance or efficiency of a system or their code. What does this really mean? My code is so efficient, only a coding god could understand how it works. My code is really clever but unmaintainable. The next developer will re-write it anyway. My code is really efficient for the machine, but inefficient for the developer. My code is really simple to understand which means the developer is more efficient, and the code is more than fast enough and easy to fix if not. So instead of asking yourself how fast you can make the code and how many clever tricks you can put into it, ask yourself; how simple can I make this and still be more than fast enough? Simple Event processing. For me, the simplest event processing is a method call which doesn't return anything. This is simple to translate into an asynchronous messaging transport e.g. public interface EventProcessor {     void event(MyEventData data);    ...

How do low latency applications differ for regular applications?

Overview A common question we get is; What makes a low latency application different? What is it like to read? There is a number of considerations in designing a low latency application which distinguish it from other applications. Simplicity is key The best way to make something go faster is to get the application to do less work.  This means; create less garbage, transform data less times, make data the application needs readily available. Note: I say you need the option to do this, but this doesn't mean you have to.  You should use a profiler to guide you as to what sections need optimizing. Simplicity is especially important if you want consistent performance. If you are looking at your 99th percentile (worst 1 in 100) or  99.9th percentile (worst 1 in 1000) you are looking at the time when most things are going wrong at once.  The more complex the system, the more there is to go wrong. If throughput is also important to you, you find that one ...

StackOverflow Q&A you should read if you program in Java

Overview There are common questions which come up repeatedly in Java.  Even if you know the answer it is worth getting a more thorough understanding of what is happening in these cases. How do I compare Strings? The more general questions is how do I compare the contents of an Object.  What is surprising when you use Java for the first time is that if you have a variable like String str this is a reference to an object, not the object itself.  This means when you use == you are only comparing references. Java has no syntactic sugar to hide this fact so == only compares references, not the contents of references. If you are in any doubt, Java only has primitives and references for data types up to Java 9 (in Java 10 it might value value types) The only other type is void which is only used as a return type. Is Java Pass by Reference or Pass by Value? How do I compare Strings? Why does 128 == 128 return false but 127 == 127 return true? How do I a...

Some reviews of my JavaOne 2015 talks

Stephan Seigl reviewed my talks at JavaOne favourably here Has any one seen any other reviews of JavaOne? Cheers, Peter. ------------ Here are his reviews for my talks. Work with Hundreds of Hot Terabytes in JVMs (Peter Lawrey, Higher Frequency Trading and Per-Ake Minborg, Speedment) In this session Peter and Per-Ake showed nicely what benefits applications can achieve if they do not need to access the slow database for each request. Speedment basically allows to automatically read all data from a database to a memory cache and – this is interesting – provide a highly scalable approach to synchronize the data (Reactive persistent caching). Peter’s Chronicle Engine (mostly open source) allows to access this memory data is the most efficient way. This approach scales greatly. The examples they were showing had heap sizes in the range of tens of terabytes. Very nice talk. Presentation My Rating:  4/5 Legacy code and lambda (Peter Lawrey, Higher Freque...

My Bio

I often get asked for my Bio, so in case anyone is too shy to ask, here it is. My Bio - Most answers for Java and JVM on StackOverflow.com (11K+) - "Vanilla Java" blog with four million views and around 300 posts. - Founder of the  Performance Java User's Group , a virtual JUG with 1700+ members. - Architect of Chronicle Software , open source project for high performance, low latency libraries in Java. - Java Champion My LinkedIn page is  https://www.linkedin.com/in/peterlawrey Initial Services Over the last year, the most common way we engage a new client to conduct a one week workshop, even if you have been using Chronicle Software for a while this will be of benefit to you. Over the week the team develops the skeleton of a project of their choice and we look at how Chronicle Software products can help, and how to develop high performance code in Java in general. I am usually booked two months in advance, however we have other staff which can conduct t...

Common misconception: How many objects does this create?

Image
Overview A common question is how many objects or how many Strings does a section of code create. Often the answer is not what you think nor should you really need to know.  It is useful to have an idea of when an object is created but there is so many other factors which are often far more important to consider which can mean the total number for an application is not what you think. String is a not a single object A String wraps a char[].  This means that when you see a new String there could be a new char[] also involved. If you do + with a String it could use a StringBuilder (from Java 5.0) which also wraps a char[].  This means that usually there is more char[] created in Java than String objects. Sometimes char[] is the most common object type in a JVM. String literals are still Strings A common misconception is that String literals don't count.  They don't add to the total after the code has been run at least once, however most of the time the qu...

Low latency FIX engine in Java

Image
Overview Chronicle FIX is our Low Latency FIX engine and database for Java. What makes it different is that it; is designed for ultra low GC* in Java. supports Strings and date times in a way which minimises garbage and overhead. is customisable to include only the fields you expect. uses optimisations normally used in binary parsers and generators such as reading/writing 4 or 8 bytes at a time to improve efficiency. built on low latency persistence to minimise the latency of logging. is optimised for low latency network cards such as Solarflare. * Ultra low GC means it can produce less than a byte of garbage per message on average If you keep your total garbage rate to less than 1 GB per hour a 24 GB Eden can take all day to fill up and you don't get any minor GCs.  Produce less than 200 MB/hour and you can run for a week without a GC. But isn't Java slow? Java can be slower than C++ but written well Java can be faster than a C++ application not writte...