Forgot your password?
typodupeerror
Java Programming

Using Java In Low Latency Environments 371

Posted by Soulskill
from the shaving-milliseconds dept.
twofishy writes "Something I've noticed amongst financial service companies in London is a growing use of Java in preference to C/C++ for exchange systems, High Frequency Trading and over low-latency work. InfoQ has a good written panel discussion with Peter Lawrey, Martin Thompson, Todd L. Montgomery and Andy Piper. From the article: 'Often the faster an algorithm can be put into the market, the more advantage it has. Many algorithms have a shelf life and quicker time to market is key in taking advantage of that. With the community around Java and the options available, it can definitely be a competitive advantage, as opposed to C or C++ where the options may not be as broad for the use case. Sometimes, though, pure low latency can rule out other concerns. I think currently, the difference in performance between Java and C++ is so close that it's not a black and white decision based solely on speed. Improvements in GC techniques, JIT optimizations, and managed runtimes have made traditional Java weaknesses with respect to performance into some very compelling strengths that are not easy to ignore.'"
This discussion has been archived. No new comments can be posted.

Using Java In Low Latency Environments

Comments Filter:
  • Thanks Dice!! (Score:2, Insightful)

    by Anonymous Coward on Friday August 02, 2013 @10:12AM (#44455981)

    This Slashvertisement brought to you by: Dice.com

  • Huh? (Score:2, Insightful)

    by TWX (665546) on Friday August 02, 2013 @10:17AM (#44456021)
    Why would the language of choice matter terribly much if the programmer has skills with the language?

    Wouldn't a C++ programmer generate an applicable program effectively as quickly as a Java programmer? It's not like compiling is the time-consuming part anymore...
  • Re:memory monster (Score:5, Insightful)

    by Minwee (522556) <dcr@neverwhen.org> on Friday August 02, 2013 @10:32AM (#44456169) Homepage

    Traders are typically working with monster servers outfitted with over a hundred gigabytes of RAM, not tiny desktop workstations that need to swap just to move the mouse. I won't say that memory usage is no object, but there is almost no reason not to throw extra memory at a process if it wants it.

    Your trading engine runs in Java and leaks four gigabytes an hour? No problem. Just give it 64G of stack and do half an hour of garbage collection after the market closes. Is that not enough? Okay, give it more. Don't have that much available? Get more. Can't afford it? Now you're just pulling my leg. Buying extra memory is cheaper than debugging a live system where any slip-up could cost you thousands of dollars in missed trades or penalties.

    It's a weird world, but somehow it works that way.

  • by satuon (1822492) on Friday August 02, 2013 @10:35AM (#44456211)

    Java is slow because it is Garbage-Collected, not because it runs in a Virtual Machine.

    Memory usage is more important than the virtual machine for performance for anything more complex than calculating Fibonacci numbers, as it affects hard drive swapping and cache misses. That's what is making Java programs **feel** slow. The hard disk is the bottleneck, not the CPU.

  • by Anonymous Coward on Friday August 02, 2013 @10:40AM (#44456267)

    Java runs in a virtual machine, and is compiled "just in time".

    For "real time" applications, that need guarenteed latency, this is a no no.

    Java's garbage collection, running is also a no no.

    Real time applications need hard deadlines, that are deterministic. A function must always return X mSec, regardless of any other things like GC, etc.

    Just imagine if say a pacemaker ran Java.

    "I detected an unusual event, but I have to run GC first, then process the event..oh, what the patient is dead?"

    Why don't we have for ultimate speed, a java interpreter written in java, running on a java interpreter written in java running on... ad nauseaum?

    I don't want a 15 min boot time for my embedded system. there is a reason most Android tablets have huuuge lag at unexpected times. Give me access to the bare metal any day. I'll figure out memory management myself, thank you very much!

    Then again, I come from the embedded days, when memory was and sometimes still is, measued in Kb, not Gb.

    Java is great for student programmers and others of limited skill that need to produce *something* ,at limited cost. They can't really harm the underlying system, and don't need to lean any hard concepts like memory management and real-time deadlines.

  • by UnknownSoldier (67820) on Friday August 02, 2013 @10:41AM (#44456279)

    > I think currently, the difference in performance between Java and C++ is so close that...

    Additionally the problem is this blowhard is talking out of their ass (SWAG / opinion) instead of showing us cold, hard, facts.

    Open Source + Open Data = let the results speak for themselves instead of some opinion that no one gives a fuck about.

    Mod Article: -1 Troll

  • Re:Huh? (Score:5, Insightful)

    by Xest (935314) on Friday August 02, 2013 @10:47AM (#44456329)

    "Wouldn't a C++ programmer generate an applicable program effectively as quickly as a Java programmer?"

    No, some languages simply are slower to develop with and debug. The problem is also made worse depending on the frameworks and IDEs available. As an example, you're going to get your work done way quicker writing an application manipulating dates and times using C# and Visual Studio than you are Java and Eclipse because until Java 8 Java's date time functionality is shit and Eclipse is a dog slow IDE. With Java 8 and say NetBeans or JDeveloper though things will be pretty similar.

    At the end of the day with C/C++ you have to deal with memory management and that's just one additional piece of work that you don't have to be so concerned with with Java. C/C++ give you more scope for optimisation and more control over memory management as a benefit of that though. It's about trade-offs and figuring out what matters.

    But it's possible to be great at both C++ and Java without having to descend into petty arguments as to which is better and know when to use each in response to a specific task, and that's the sort of great programmer these institutions will be looking for and this is really what they're talking about - both have their place but in some cases getting a trading application to market a day earlier than the competition even at slight latency trade-off may be enough to net your company a few million dollars advantage. In other cases, the latency improvements of a highly optimised C++ application may instead be the key to scooping up those extra millions.

  • by serviscope_minor (664417) on Friday August 02, 2013 @10:54AM (#44456399) Journal

    Really.

    Meh.

    http://benchmarksgame.alioth.debian.org/u64/java.php [debian.org]

    Or not. Benchmarks are a game and everyone likes to play, except the users of brainfuck for whom creating a program which completes is essentially winning.

    The thing is people have been trumpeting "blah is as fast as C/C++/Fortran" since nearly the inception of C and C++ and probably shortly after the inception of FORTRAN.

    I think there is a kernel of truth in that the reason C, C++ and FORTRAN/Fortran are always the targets is because they are almost always either the fastest or with a few percent of the fastest.

    When people start comparing execution speeds of Haskell, Python, C#, C++, $NEWLANGUAGE etc consistently against Java then I'll believe that Java is indeed king of the hill.

  • by WOOFYGOOFY (1334993) on Friday August 02, 2013 @10:57AM (#44456425)

    Uh since around 1.3 the JIT optimization for java has led to blindly fast code containing optimizations which are not even available to C++ . Dynamic compiling allows for branch prediction to be more accurately, unlike malloc, the GC knows where to look for free memory and returns it from the last bit of memory you just requested, if you know where pointers are pointing at compile time, you can put them in registers. C++ and other statically compile languages don't have this information, so it stores them in cache, but the JIT can acquire this information and store it in a register. It's the difference between a register to register test and reading from disk.

    There are tons of other stuff like this. I don't have it committed to memory, and compiler technology is not my thing but if you look around you'll see that actually GC and JIT are theoretical advantages in terms of speed and those advantages are being realized. It can even figure out what chip it's being run on at runtime and optimize the code for that chip.

    The Java is Slow Meme is left over from 1995 before there was even HotSpot.

    Not bashing any other language here. C# could also avail itself of these advantages.

  • by LostMyBeaver (1226054) on Friday August 02, 2013 @10:58AM (#44456437)
    Leaving aside my political beliefs that high speed trading needs to be banned, let me say this.

    Switching to Java should yield similar results to C++. What matters is whether the programmer understands the memory architecture of the run-time environment well enough to not have issues. Generally, you'll find that even the best programmers in either language will overlook things like garbage collectors and memory fragmentation issues. It's a time-to-market thing. When working with large dynamic data sets, it doesn't matter if you're using Java or C++, the developer needs to be able to adapt their code to perform well on the system.

    Code written without considering the processing time of memory management will probably work much better in C++ than Java. That said for huge data sets, Java could perform better since the memory itself is location independent and it is highly probable that you're gain a great deal of performance from being able to defragment memory. Consider however that the garbage collector and the defragmenter will have unpredictable times which can cause multi-millisecond hiccoughs during processing.

    I recommend if you take this route, you hire a compiler geek to work on staff optimizing the memory operations.
  • Re:Huh? (Score:1, Insightful)

    by Xest (935314) on Friday August 02, 2013 @11:07AM (#44456525)

    Yes, I'm a Microsoft shill, that's why I praised an Open Source IDE (NetBeans), a competitors proprietary IDE (JDeveloper) as well as the Java language and in another thread only about half an hour ago said good things about Sony, and Nintendo. Two days ago I was apparently a Samsung shill too.

    Has it really come to this? If you dare praise any company or one of it's products for absolutely anything then you're a shill?

    The worst part is because I'm not a fanboy and I praise any company that does something good and criticise any that doesn't I must be a shill for every tech company on earth because even those I least like such as Apple I've praised sometimes (i.e. for shaking up the smartphone market and forcing innovation) and Facebook though I have a mostly negative view of it produced a nice clean site relative to the social networks that came before it (MySpace) crushing them as a result.

    If only I really was collecting all those paycheques from the entire who's who list of wealthy silicon valley firms...

  • Re:Huh? (Score:4, Insightful)

    by MindStalker (22827) <(moc.liamg) (ta) (reklatsdnim)> on Friday August 02, 2013 @11:21AM (#44456699) Journal

    Honestly, when your task is, "Grab data from mysql, dump it to screen." There really is nothing faster than coding it in PHP. Its quick, its easy, and it gets the job done as fast as a shell script.

  • Re:Huh? (Score:5, Insightful)

    by parlancex (1322105) on Friday August 02, 2013 @11:29AM (#44456789)
    Garbage collection creates a different class of problems, namely that the performance characteristics of your program become non-deterministic. This is a Big Deal for certain classes of applications such as video games and in particular HFT. Would you like to be the person explaining why the GC caused your program to stall at an inopportune time for 50ms and lost somebody a few million bucks?
  • Re:Huh? (Score:2, Insightful)

    by Anonymous Coward on Friday August 02, 2013 @11:36AM (#44456855)
    In the real world so what if you know how to write better software. If you have a job to maintain some old large software, you're mostly stuck with its compile times.

    Rewriting it "better" would take many years - you'd be sacked long before you succeeded.
  • Re:memory monster (Score:5, Insightful)

    by scamper_22 (1073470) on Friday August 02, 2013 @11:42AM (#44456937)

    It's hardly a weird world.

    Water leaks into basements. Many times, the solution is to use a sumppump to pump the water out rather than a very costly rebuilding of the house and surrounding terrain.

    I've bought many products in my life (just recently a car tire pump) that tells you not to run it for more than 15 minutes. It might over heat.

    Many people have cars that start leaking oil as they age. They don't spend the money to fix it as long as they can just add enough oil to keep it going.

    And who hasn't used duct-tape to seal leaks?

    It's hardly a weird world out there.

  • Re:Huh? (Score:4, Insightful)

    by Darinbob (1142669) on Friday August 02, 2013 @02:07PM (#44458991)

    Garbage Collection with a bad implementation this is true. But garbage collectors do not need to cause non-determinism; they can be used even in real time systems. The problems is that people re-invent the wheel and don't learn from all the research in the past that sped GC up. Or more likely, the system was originally designed to be a simple quick-and-dirty scripting language but its scope has grown so that now the hastily written GC is unsuitable for the new requirements.

    To be fair, good GC is hard, and it is extremely difficult to do it portably. Some good GC techniques need hooks into the operating system (ie, you want to mark pages as clean or dirty). Doing this portably sometimes means you see implementations that sit GC up on top of malloc, so that GC is merely a way to eliminate manual allocating and freeing, and you end up with performance headaches with memory fragmentation.

    Yes it's true, if you use a malloc and free directly and no GC, you can still end up with non-deterministic allocation performance! Especially with a naive malloc I see used a lot on small systems, where you just have a linked list of available regions so you have a linear search to find regions big enough. And you end up with fragmentation on any system that does not have relocatable memory (ie, most traditional non-interpreted systems), so many embedded systems prefer to use memory pools to fix those problems.

  • by Darinbob (1142669) on Friday August 02, 2013 @02:17PM (#44459109)

    Yes, Java at its core is a simple language, with well understood concepts and features that people have been using for decades. But it's saddled with a huge amount of framework. To be a good Java developer these days doesn't mean knowing how to use Java the language, it means knowing all about the infrastructure and how to quickly tie together pre-existing functions to do what you want.

  • Re:Huh? (Score:4, Insightful)

    by 0123456 (636235) on Friday August 02, 2013 @02:43PM (#44459429)

    At the end of the day with C/C++ you have to deal with memory management and that's just one additional piece of work that you don't have to be so concerned with with Java.

    You're funny.

    I think we have about a dozen calls to new and free in a few hundred thousand lines of code in our server. The vast majority of memory allocation in C++ is hidden in libraries like STL, which we presume have been debugged.

    In Java, on the other hand, you have to be very careful with memory management or you'll either end up pausing for long periods for garbage collection or crashing with out of memory errors. Instead of worrying about whether people remember to call free after allocating something, you end up putting in caches so you can reuse objects rather than reallocate them. We've used some Java libraries designed for high-performance financial uses and they try very hard not to allocate any objects that they'll later need to clean up.

    Programmers believing that 'you don't have to worry about memory management in Java' is the reason so many Java programs are a slug-like mass of memory bloat.

Is a person who blows up banks an econoclast?

Working...