News for hackers. Stuff that matters.
Re:Java is better than C++ for high speed trading systems by vgatherps on Thursday November 26, 2020 @01:45AM (#25217499)
I’ve seen this sentiment before and worked on both a “low latency Java” team and low latency C++ teams.

I have some sympathy for the idea that the JVM is better since it means you won’t spend all your time chasing crash reports. The thing is, like another comment hinted at, is that this issue is generally more reflective of the environment you build in than the technology choice.

Here’s a good talk on the reasons for and limits of using C++ for low latency systems: https://m.youtube.com/watch?v=NH1Tta7purM

If I had to rank in terms of reliability of trading infrastructure I’ve used/worked on,

* Low Latency C / C++ infra at fully automated trading firm. Very much run by the programmers and quants and also fairly small. By far the fastest (near limits of what you could do) and also most reliable.

* Low Latency Java execution infrastructure. Pretty reliable, not that fast, had some issues with GC battling and manual memory management to avoid GC, etc. There was a pretty clear latency floor (still quite low) even when “doing everything right” that serious native infrastructure beat.

* C++ market making infra at a firm run by manual traders. It was by far the slowest and least reliable. Echos the experience of “spent hours debugging weird crashes”. The culture was very “A trader asked for this and needs it done yesterday. Also this refactoring business doesn’t sound like adding new features, drop it”.

What I saw is that if you hire people who have a good idea of what they’re doing and keep a culture of technical excellence, C++ is definitely a better choice if you care about latency. You really have to maintain a culture of high quality code, testing, and in general caring about the technology.

This is only really possible when all of the stakeholders are involved in the technology, or at least understand the benefits. Once you start down the path of “well this feature could be done a day quicker if...” this goes down the drain, and a few years later you find yourself getting run over on latency AND with an impossible to use trading system. It’s really the worst of both worlds.

Re:Java is better than C++ for high speed trading systems by angry_octet on Thursday November 26, 2020 @02:38AM (#25217795)
The worst (messiest, laziest and most chaotic) engineer I know works at a brokerage, coding obscenely large and unreliable edifices (and in a number of languages, from C++ to Excel+VB)... He does what he is asked, and doesn't worry about telling them what they need. They never demand code that doesn't crash, they see that as a fact of life, and developers are an overhead. Basically someone else owns the risk, the brokers don't, so why should he?

People who don't like this style (or the code) leave.

The direction for quality has to come from the top and be supported by systematic mechanisms. In fact that would be a question to ask in interviews.

Re:Java is better than C++ for high speed trading systems by Karellen on Thursday November 26, 2020 @08:08AM (#25219708)
^^This^^ is why you shouldn't call software developers "engineers" (disclaimer, am software developer).

"No-one ever explicitly specified that the bridge shouldn't fall down and kill everyone who was on it at the time", said no engineer, ever.

Re:Java is better than C++ for high speed trading systems by derefr on Thursday November 26, 2020 @10:12AM (#25220642)
I think it’s not that software engineers aren’t engineers; but more that they’re most equivalent to combat engineers — engineers operating under time-pressure and shipping-pressure, where the systems they build need to “work” (in the sense of a bridge getting people across a ravine) but may only need to work once; and where it may be perfectly fine/expected/required to need to “baby” the resulting engineered system along (i.e. letting a batch of people over the bridge, then closing it to traffic, examining the piles for faults, and shoring up the ones that are slipping; then reopening the bridge, in a cycle.)

It’s not that this type of engineering is “not engineering”; it’s that it’s engineering where the engineer themselves (and their ability to actively re-stabilize the system) is considered a load-bearing element in the design, such that the system will very likely fall apart once that element is removed.

Combat engineering is still engineering, in the sense that there are still tolerances to be achieved, and it’s still a disaster if the bridge falls over while it’s in active use for the mission it was built for. It’s just not considered a problem if it falls over later, once that mission is accomplished.

Re:Java is better than C++ for high speed trading systems by dnautics on Thursday November 26, 2020 @12:10PM (#25221770)
you mean they're more like train engineers, or maybe to be charitable, like geordi laforge engineers, someone who runs an engine.
Re:Java is better than C++ for high speed trading systems by travisporter on Thursday November 26, 2020 @09:49AM (#25220438)
I think software developers have a range in terms of responsibility from plumbers/electricians to civil engineers. We could save the designation “software engineer” for someone who has to go through the requisite ethics and case study courses like all other engineers. Otherwise maybe programmer/developer. (I’m gatekeeping I guess)
Re:Java is better than C++ for high speed trading systems by RHSeeger on Thursday November 26, 2020 @10:03AM (#25220566)
I would think it's less about ethics and more about understanding consequences; being able to reason about what happens based on the choices made while implementing something.
Re:Java is better than C++ for high speed trading systems by zanellato19 on Thursday November 26, 2020 @08:18AM (#25219766)
Given the same conditions (i.e. people don't die) the same outcome would present itself. We have a history of bridges falling down, so much so that Wikipedia has a list on that: https://en.wikipedia.org/wiki/List_of_bridge_failures

A particular one that caught my eye: Cimarron River Rail Crossing Dover, Oklahoma Territory United States 18 September 1906 Wooden railroad trestle Washed out under pressure from debris during high water 4-100+ killed Entire span lost; rebuilt Bridge was to be temporary, but replacement was delayed for financial reasons.[8][9][10] Number of deaths is uncertain; estimates range from 4 to over 100.[11]

Emphasis mine. How is that different from software engineering?

Re:Java is better than C++ for high speed trading systems by Karellen on Thursday November 26, 2020 @10:03AM (#25220568)
The point isn't that bridges never fall down. The point is that engineers who build bridges know that it's their responsibility to do everything in their power to make sure it doesn't, even if no-one else around them seems to care about that, or specifically asked for it. That they should walk away from a project rather than sign off on one where they will not have the resources or support to do a competent job.

That said, all bridges have design specifications and limits. If someone drives a convoy of trucks carrying gold bullion over a bridge and exceeds its design max weight by a factor of 10, and it doesn't hold up, that's not the engineer's fault. If a bridge is designed for a geologically active area and is designed to withstand a quake 10x more powerful than the strongest that's ever been recorded in the area, or is predicted by seismologists, and the area gets hit by a 100x quake, that's not the engineer's fault.

And if a bridge designed to last say, 5 years, is neither re-certified for use, or just closed, when its intended lifespan is up then that's not the engineer's fault either.

But the engineer is responsible for finding out what the likely max load of a bridge will be, or how powerful the strongest quake will be, or how long its intended lifespan is - and for adding in safety margins on top of that. They can't just assume that any new bridge will only be needed for 5 years, just because that no-one told them that it will be needed for longer, and then claim "well, it was only temporary" afterwards.

Re:Java is better than C++ for high speed trading systems by zanellato19 on Thursday November 26, 2020 @11:52AM (#25221572)
> The point isn't that bridges never fall down. The point is that engineers who build bridges know that it's their responsibility to do everything in their power to make sure it doesn't, even if no-one else around them seems to care about that, or specifically asked for it. That they should walk away from a project rather than sign off on one where they will not have the resources or support to do a competent job.

The law takes care of that though. The law and inspection. If it was up to the business, any engineers building bridges who would refuse to project it faster because of that would be fired.

Re:Java is better than C++ for high speed trading systems by bigbubba on Thursday November 26, 2020 @02:17PM (#25222815)
A thief thinks every man steals. An apathetic engineer thinks all engineers share his apathy.
Re:Java is better than C++ for high speed trading systems by cobbzilla on Thursday November 26, 2020 @08:30AM (#25219841)
The sarcastic/negative implication of your example is that software engineering today is where civil engineering was 100+ years ago.
Re:Java is better than C++ for high speed trading systems by piaste on Thursday November 26, 2020 @08:54AM (#25220015)
Yes, but not because software engineers are worse human beings than civil engineers, which is all too often the undertone of these discussions.

Rather, because software engineering hasn't killed enough people to advance; or when it has, it wasn't obviously the culprit.

In which fields of software engineering do we find actual solid procedures and standards? Avionics. Medical hardware. Fields where the link between bug and death is as short as possible, and so the stakeholders have demanded solid engineering.

What are the consequences of GP's acquaintance writing poor code? Some trading firm becomes slightly less efficient at trading. Impossible to evaluate the net human loss from it (if it's a loss at all).

The civil engineering equivalent would be something like façade design or layout. If your building is ugly or confusing, it will annoy or waste the time of the people who live and work in it, but as long as it doesn't fall on their heads nobody is going to withdraw your certification.

Re:Java is better than C++ for high speed trading systems by MaxBarraclough on Thursday November 26, 2020 @09:08AM (#25220119)
> not because software engineers are worse human beings than civil engineers, which is all too often the undertone of these discussions

I think the undertone is usually that the software developer at fault had no idea what they were doing, and had no place working on critical systems, rather than that they had ill intent.

Re:Java is better than C++ for high speed trading systems by LoSboccacc on Thursday November 26, 2020 @09:14AM (#25220169)
> software engineering hasn't killed enough people to advance

and where it had, you get pretty serious control and certification process put in place to avoid it (Boeing notwithstanding)

Re:Java is better than C++ for high speed trading systems by MaxBarraclough on Thursday November 26, 2020 @09:33AM (#25220302)
The 737 Max issues were not with the software.
Re:Java is better than C++ for high speed trading systems by fsflyer on Thursday November 26, 2020 @10:20AM (#25220723)
There seems to be plenty of software issues found:

The MCAS software was modified to read from both angle of attack sensors and to be less aggressive in pushing the nose of the plane down. The software that controlled the indicator light that illuminated when the two angle of attack sensors disagreed was also fixed.

While reviewing the software systems, a number of other software issues were found.

The wiring bundle issue was also found during these reviews.

https://www.barrons.com/articles/these-6-issues-are-preventi...

https://simpleflying.com/boeing-737-max-software-update-3/

Re:Java is better than C++ for high speed trading systems by MaxBarraclough on Thursday November 26, 2020 @10:45AM (#25220946)
I phrased that poorly, I should have said The 737 Max issues that caused the crashes were not with the software implementation. They were at the level of requirements and high-level design, and were not specific to the discipline of software engineering. We're not talking about a missing break statement here.

> The MCAS software was modified to read from both angle of attack sensors and to be less aggressive in pushing the nose of the plane down.

That strikes me as a design issue in the domain of aeronautical engineering, rather than in software engineering. Software engineers aren't the ones with the domain expertise to determine the right aggression parameters.

> The software that controlled the indicator light that illuminated when the two angle of attack sensors disagreed was also fixed.

I thought the issue was that the sensor-disagree warning light was not included as standard, it was sold as an optional extra. [0]

> While reviewing the software systems, a number of other software issues were found.

Interesting, I wasn't aware of that. If I understand correctly these issues aren't thought to have a direct bearing on the crashes.

[0] https://www.nytimes.com/2019/05/05/business/boeing-737-max-w...

Re:Java is better than C++ for high speed trading systems by angry_octet on Thursday November 26, 2020 @05:56PM (#25224147)
Exactly. People seem to have skipped the V&V lectures. The code did exactly what it was asked to do. But the system/aero engineers made that decision. Even the lights issue was specified that way in the system diagram.

But the biggest defect was the decision that the pilots didn't have to be told about the risk (to avoid retraining and certification costs). If they had been told the pilots/airlines may well have protested about the lack of redundancy. All those higher ups in Boeing and the FAA should be in prison.

Re:Java is better than C++ for high speed trading systems by nickpeterson on Thursday November 26, 2020 @08:38AM (#25219895)
I don’t think that is too far off the mark. Given 8 more decades of progress we might even be able to produce reliable code. Webpages will be 100GB of JavaScript though
Re:Java is better than C++ for high speed trading systems by MaxBarraclough on Thursday November 26, 2020 @09:15AM (#25220177)
> Given 8 more decades of progress we might even be able to produce reliable code

As the risk of nitpicking, we already can produce reliable code, but as piaste's comment states, it's rare to make the necessary investment.

Avionics software and medical systems software is held to a very high standard, at great expense, but the average website or desktop application is not.

> Webpages will be 100GB of JavaScript though

I agree that the problem of bloat is likely to continue to worsen in the web, but that's just the web. Other sectors, like high-performance game engines, will continue to compete on efficiency.

Re:Java is better than C++ for high speed trading systems by m_mueller on Thursday November 26, 2020 @08:55AM (#25220021)
I think reliability is, after a certain point, inverse proportional to the amount of code involved. So I'd disagree that we'll have even larger webpages then - the same way that in modern construction, heavy and thick stone & brick pillars have been replaced with comparatively light and strong steel-reinforced concrete. Maybe the equivalent would be just enough strongly typed code running on top of just enough, well tested & secure WASM?
Re:Java is better than C++ for high speed trading systems by elros on Thursday November 26, 2020 @09:44AM (#25220397)
Given software engineering is less than 200 years old while civil engineering is a few thousand years old, I don't see this as a negative at all.
Re:Java is better than C++ for high speed trading systems by zanellato19 on Thursday November 26, 2020 @09:12AM (#25220150)
I don't think that is the case - but that is certainly one interpretation of it. They were still engineers at the time though, and so are we.
Re:Java is better than C++ for high speed trading systems by nomoreusernames on Thursday November 26, 2020 @08:52AM (#25220000)
made me chuckle.
Re:Java is better than C++ for high speed trading systems by levosmetalo on Thursday November 26, 2020 @09:10AM (#25220136)
"I need that bridge yesterday. If my army doesn't cross the river today, we are all dead. I don't care if the bridge collapse tomorrow, or if the rain wear it down, as long as I can use it today."

If it's your job to do what is requested from you, then you do it. It's not like having brittle unmaintainable code is morally wrong. It's not engineers responsibility to judge use case of the customer paying for the bridge.

Re:Java is better than C++ for high speed trading systems by Enginerrrd on Thursday November 26, 2020 @09:39AM (#25220355)
>It's not engineers responsibility to judge use case of the customer paying for the bridge.

Actually yes, yes it is! I am a civil engineer and there's a standard of ethics and personal responsibility among engineers that is very, very high. When we graduate, most engineers participate in a ring ceremony. They get a funny, angled ring on their right pinky. It was originally made from the metal from a bridge that fell down and killed people. It was meant to be a daily reminder, worn on the drafting hand, that every single drawing you signed carried the weight of public trust of their lives. Even pedestrian bridges get built with vehicle load standards, because you can't just assume that it will only be used by pedestrians.

Civil engineering is a licensure, and no matter what liability structure you use, when you stamp a drawing, you carry PERSONAL liability for anything that might happen if that design fails. Even small violations of ethics or operating outside your scope of knowledge are dealt with very aggressively by the licensing board.

In school, if we misplaced a decimal or got a calculation wrong or failed to adhere to a very specific standard, it was automatic failure because if you do that in real life, people die.

Re:Java is better than C++ for high speed trading systems by dmz73 on Thursday November 26, 2020 @05:38PM (#25224062)
It is difficult to compare software development with civil engineering as they operate on different levels. Software development is better compared to building houses. No one expects single story house to support 4 extra levels or for internal walls to be resistant to hammer blows. Imagine what civil engineering would produce if you were building a bridge from a to b and then 3/4 way through you were required to add two extra exits c and d that were miles apart from a and b and another 4 lanes and extra level for train traffic...all in the same time frame and for no extra cost. Civil engineers would not be able to do it and no-one would even expect them to but this is regular occurrence for software developers and most of them actually manage to deliver. Sure there are bugs but bridges need constant maintenance too, some quite substantial and that is expected. For some reason, lots of non-software engineers expect software to be perfect when their own products are not, not even close.
Re:Java is better than C++ for high speed trading systems by ryandrake on Thursday November 26, 2020 @01:09PM (#25222255)
This is a key common thread in all these discussions. At so many development shops, developers have no agency to push back against poor quality. They don't have a license on the line that they can stand behind and firmly say "NO we will not do it that way or I could be personally liable for its failure!" When they point out that they're shipping buggy crap, the response simply is: Ship the crap on time.

It's strange too, you hear in other threads about how high the demand is for software engineers, how high their salaries are, how much negotiating power they have with their companies, but when it comes to the actual product content, suddenly they have no power at all and it's just Yes boss, whatever you say, boss. How is this true?

Re:Java is better than C++ for high speed trading systems by RestlessMind on Thursday November 26, 2020 @12:43PM (#25222057)
> I am a civil engineer and there's a standard of ethics and personal responsibility among engineers that is very, very high.

And that is because no one can just go to a 6-month bootcamp and call themselves a Civil engineer. And even if they did, no one would hire them or the employer would go to jail.

If we want Software Engineering to be as rigorous as other Engineering disciplines, we need to erect similar barriers to become a Software Engineer.

Re:Java is better than C++ for high speed trading systems by Enginerrrd on Thursday November 26, 2020 @02:14PM (#25222788)
Honestly, I think it would be sensible to have a software engineering licensure, though it shouldn't be required for all developers or development. I'd say something like an engineering stamp would be pretty reasonable for anything requiring encryption, financial data or transactions, health data, etc. And that's not to say that developers couldn't work on it, but just that a licensed software engineer should be in responsible charge of their work to ensure that it has been performed according to best practices and standards.
Re:Java is better than C++ for high speed trading systems by quonn on Thursday November 26, 2020 @12:28PM (#25221922)
Is this the same in Europe? I doubt it and at least in Germany an engineer (even a software engineer) is someone who has studied a technical subject at university. It has nothing to do with liability here.
Re:Java is better than C++ for high speed trading systems by Enginerrrd on Thursday November 26, 2020 @02:10PM (#25222763)
The exact protected term varies by country but there is an equivalent license in Europe. The EU has a "Eur Ing." title issued by FEANI which is roughly equivalent. As I understand it, Germany is a bit unique even for the EU. They still have some things which require a certification of sorts, but I don't know exactly how that works.
Re:Java is better than C++ for high speed trading systems by ampdepolymerase on Thursday November 26, 2020 @10:58AM (#25221082)
Found yer old union gatekeeper. Canadian engineer?
Re:Java is better than C++ for high speed trading systems by fishermanbill on Thursday November 26, 2020 @09:50AM (#25220443)
That is a really weird analogy. Using extreme scenarios to argue your point is never going to put you on a strong footing.

Anyway for most systems deployed the customer usually wants to maintain a business using it. If the system constantly falls over, cant be readily changed etc etc that is going to cost the customers business compared to its competitors.

Add that a lot of developers work for the same company as the customer and that is just as much the developers responsibility.

99.999% of bridges built would be expected to hold up 10 years later and require minimal maintenance. I'd wager all bridges even temporary army ones would be expected to not unforeseeably fail. See the Morandi Bridge tragedy.

Re:Java is better than C++ for high speed trading systems by lowtech on Thursday November 26, 2020 @11:23AM (#25221277)
Enginners where not requested to make the Voyagers last a hundred years, yet they're still up and running. Personally I think the correlation between quality of code and time to delivery are not linear. People can cram more work and quality in the same ammount of time if they want and have the right incentives to do so.
Re:Java is better than C++ for high speed trading systems by throw93232 on Thursday November 26, 2020 @12:48PM (#25222094)
Dont argue with that. There is common trend to blame poor managerial decisions on lower level developers. just shows how crooked system is.
Re:Java is better than C++ for high speed trading systems by AlexTWithBeard on Thursday November 26, 2020 @10:40AM (#25220890)
The state of software engineering these days resemble that of civil engineering of late 19th century: some masterpieces, some failures and lots of experiments.

Do we put the cockpit in front of the boiler or behind?

Do we make a walking steam engine? How about using gears instead of wheels?

Which gauge to pick for the rails?

We'll get there in software engineering at well. It will be very reliable and equally boring.

Re:Java is better than C++ for high speed trading systems by sorokod on Thursday November 26, 2020 @12:04PM (#25221714)
There may be reasons for not calling software developers engineers but this is not one of them. The software "bridge" in this case has the following properties:

1. It can be rebuilt in a matter of hours by a single person.

2. The customers that ordered the bridge are also the people on the bridge and are totally fine with the bridge crashing on them from time to time.

Re:Java is better than C++ for high speed trading systems by ryandrake on Thursday November 26, 2020 @01:03PM (#25222209)
#2 was the most frustrating thing (to me) about writing software, and ultimately what got me to move out of coding over to other areas of the business. This universal acceptance of low quality and crashing. You always have the classic "Schedule, cost, quality, pick 2" tradeoff, and 99 out of 100 places you'll work will throw quality under the bus when push comes to shove.

I remember the exact turning point. We had a super buggy Windows application that had tons of crashes in it. Instead of root causing each crash and fixing them, I was asked to simply write a launcher app that sat in the background, waited for the application to crash, then re-launch it. That was the great solution. And it was totally acceptable to the customer. Arghhhhh! I remember thinking: I didn't spend four years in university to shit this kind of finished product out.

Re:Java is better than C++ for high speed trading systems by RestlessMind on Thursday November 26, 2020 @12:40PM (#25222031)
I guess the key reason why software developers are not engineers is that there is no barrier to entry. If a necessary requirement to build a bridge is to hire a certified Civil Engineer who has undergone the necessary ethics and reliability training, then you have no choice but to pay up for that certification cost. You can't outsource that work to Eastern EU or Asia or hire another one willing to "hack" the bridge to deliver it on your tight timeline.

On the other hand, if someone takes software reliability seriously, either they are going to burn themselves out to meet the crazy deadlines or are going to "not deliver on time", in which case they will be replaced by someone who can "get shit done" cheaper and faster.

Re:Java is better than C++ for high speed trading systems by fma on Thursday November 26, 2020 @02:04PM (#25222722)
If you wanna design a bridge...you need an engineering background. If you wanna design a car...you need an engineering background.

If you want to design the software that designs the bridge or the car...just need a 8 week bootcamp.

Re:Java is better than C++ for high speed trading systems by krzyk on Thursday November 26, 2020 @08:42AM (#25219932)
You shouldn't compare bridge building to developing a trading apps (on causes death, the other merely financial loss)

Compare bridge building to developing software for pace maker.

Now compare number of failures in both cases.

You get what you pay for, if you pay for developer you'll get a developer.

Re:Java is better than C++ for high speed trading systems by pps43 on Thursday November 26, 2020 @08:56AM (#25220025)
You can convert between financial loss and loss of human life using implied cost of averting a fatality [1], which is about $10 million.

[1] https://en.wikipedia.org/wiki/Value_of_life

Re:Java is better than C++ for high speed trading systems by angry_octet on Friday November 27, 2020 @02:54AM (#25226416)
That is not a bidirectional transform. A financial loss in an investment fund just means that other traders made more profit.
Re:Java is better than C++ for high speed trading systems by qayxc on Thursday November 26, 2020 @09:14AM (#25220167)
> You get what you pay for, if you pay for developer you'll get a developer.

That's way too oversimplified. You can be as good and as thorough as you want, but if the root of the problem is that software is seen as a cost not as an integral part of the solution, you get bad results.

This often starts with unclear/vague requirements that change every other day as new information and understanding is gained.

But it doesn't stop there - unrealistic deadlines, lack of defined processes and quality control as well as disregard (and refusal to budget and schedule) for background tasks (documentation, refactoring, ...) are also contributing factors that can turn even the best and most diligent software developer into a messy code cowboy.

If gaming the system is rewarded more or actually doing a good job is even penalised, why do a good job?

Re:Java is better than C++ for high speed trading systems by julienfr112 on Thursday November 26, 2020 @08:58AM (#25220038)
I remember reading about bad software in a radiotherapy machine inducing many deaths. And also about software in Toyota cars failing and also inducing deaths because the code was a huge mess. In the end, there is no such thing as a clear separation between "engineer" and "developers".
Re:Java is better than C++ for high speed trading systems by astral303 on Thursday November 26, 2020 @01:37PM (#25222495)
The Bridge analogy is often applied with flaws. Bridges are not free to build. Software essentially is.

Here is a 1992 truth bomb rewind about it:

https://www.developerdotstar.com/printable/mag/articles/reev...

Basically engineers care about the quality of the code because they know that is the design. As soon as caring about codebase quality leaves the building, so will the quality of the product.

Re:Java is better than C++ for high speed trading systems by criddell on Thursday November 26, 2020 @02:05PM (#25222730)
A civil engineer will put their stamp on the design of a bridge certifying that it will not fail. If it does fail, they will be held responsible and may lose their license to practice.

Software engineers often hide behind a contract saying they aren't responsible for anything.

Re:Java is better than C++ for high speed trading systems by astral303 on Saturday November 28, 2020 @09:04PM (#25242359)
Software engineers are held responsible to plenty of things (HIPAA) when there is a will to do so.
Re:Java is better than C++ for high speed trading systems by angry_octet on Thursday November 26, 2020 @05:18PM (#25223929)
He is a qualified elec eng though, he's just found a non-engineering job that pays a lot more.

Software engineering is real and does require you to have a real understanding of risk (including through formal methods, model based design, systematic testing etc) in regard to the consequence. If you work in a more regulated industry (e.g. railways, aviation, automotive) these things are taken more seriously. This is why things like 'partial autonomy' driving needs more regulation -- no one is requiring Tesla to have a Chief Engineer sign off on anything meeting any standard.

Re:Java is better than C++ for high speed trading systems by RHSeeger on Thursday November 26, 2020 @09:58AM (#25220530)
There are _plenty_ of places in engineering where defects / quality / etc are lesser concerns, just like there are places in software development where they're a major concern. There's also a _lot_ more call for quality up high (ie, regulations) for the various engineering disciplines.

I would expect that there are plenty of engineers that look at faults in the systems they're working on and say, "management doesn't care, not my problem".

Re:Java is better than C++ for high speed trading systems by firethief on Thursday November 26, 2020 @11:51AM (#25221560)
If software developers aren't engineers, why are we judging this person's engineering? I think this case is an argument that software developers are engineers, even when their employer fails to see it that way
Re:Java is better than C++ for high speed trading systems by gbin on Thursday November 26, 2020 @09:36AM (#25220322)
On the opposite end you have programmed obsolescence for example that is definitely an engineering art. It takes talent and effort to make things fail.
Re:Java is better than C++ for high speed trading systems by 2OEH8eoCRo0 on Thursday November 26, 2020 @10:07AM (#25220603)
Sounds like defense software. Feature A is blatantly obvious but there is no "shall" requirement for it.
Re:Java is better than C++ for high speed trading systems by MrDresden on Thursday November 26, 2020 @06:08PM (#25224211)
Except those who go through university level software engineering or computer science degrees
Re:Java is better than C++ for high speed trading systems by erikerikson on Thursday November 26, 2020 @12:39PM (#25222025)
I would suggest that some in the field are developers while others are engineers. The former write some code that does what they tested it for, the latter designed code to account for every detail. The former thinks it does the job the latter knows. The former rushes through while the latter codes in ways that avoids redundant busy work to allow for the higher up front investment. The former slows over time as they slog through the "ball of mud" they call inevitable while the latter increasingly gains and shares insight on the deeper problems being solved and the opportunities afoot.

TL;DR: I think the extent to which we are engineers is a choice we individually make.

Re:Java is better than C++ for high speed trading systems by burnthrow on Thursday November 26, 2020 @11:42AM (#25221447)
Nice flamebait.
Re:Java is better than C++ for high speed trading systems by shitgoose on Friday November 27, 2020 @06:51PM (#25233669)
I know exactly the type of guys you are talking about. They write tools for traders, a mix of Excel, VB, .Net, you name it. They are not obsessed with architectural beauty, patterns and frameworks. They just write what users ask them (and they do not tell traders what traders need - the response will be swift and insulting). The traders take these tools and generate profit. And they do not give a shit about test coverage or not sound architecture principles. If software generates profit, then it works.
Re:Java is better than C++ for high speed trading systems by knuthsat on Thursday November 26, 2020 @07:36AM (#25219455)
From my experience, JVM can't do much when there's a deep stack.

I remember just refactoring all of foreach-loops/iterators into for-loops and got insane speedups.

Functions with inefficient iterations would get optimized if called directly but deep in the call stack and nothing happens.

These kinds of things are impossible with C++.

It's possible to write efficient Java but you have to not use some of the language features to do so.

Re:Java is better than C++ for high speed trading systems by rramadass on Friday November 27, 2020 @07:07AM (#25227996)
>These kinds of things are impossible with C++

What? Anything you can do in C, you can do in C++ at the same performance level (pay only for what you use); just be aware of what you are doing and using.

Re:Java is better than C++ for high speed trading systems by iamcreasy on Thursday November 26, 2020 @01:04PM (#25222217)
> I remember just refactoring all of foreach-loops/iterators into for-loops and got insane speedups.

Wow! Can you please provide a simple example when/where it happens?

> It's possible to write efficient Java but you have to not use some of the language features to do so.

Please tell us more.

Re:Java is better than C++ for high speed trading systems by knuthsat on Thursday November 26, 2020 @05:30PM (#25224013)
Let's say you write an Iterable class so that you can use foreach on your data structure. It's quite possible iteration won't be completely inlined and the overhead of calling hasNext & next can become non-significant.

An even worse case that made massive speedups is just inlining everything. I believe modern IDEs can automatically inline all invocations of a function. You'd be surprised how much performance you can get with that.

As for writing efficient Java, it comes down to using primitive and value types.

Although, my experience is mostly with Java 8. I have no idea how streams or other new syntax works. After optimizing a really massive Java code base I've never used it since.

Re:Java is better than C++ for high speed trading systems by iamcreasy on Thursday November 26, 2020 @07:32PM (#25224572)
But you still have to make the next and hasNext calls in a for loop. What guarantees that they would be inline in a for loop?
Re:Java is better than C++ for high speed trading systems by knuthsat on Friday November 27, 2020 @05:44AM (#25227465)
I inline them manually.
Re:Java is better than C++ for high speed trading systems by iamcreasy on Saturday November 28, 2020 @03:07PM (#25240100)
How much was the performance improvement?
Re:Java is better than C++ for high speed trading systems by knuthsat on Sunday November 29, 2020 @06:00AM (#25244386)
The biggest improvement I measured was about 15x. I'd say you can get 3x most of the time (go down to 33% of previous runtime).
Re:Java is better than C++ for high speed trading systems by iamcreasy on Sunday November 29, 2020 @04:18PM (#25248173)
That is insane speedup! Thanks for sharing. How do I find next and hasNext is the bottleneck? Should I run profiler to see if they are being called a large number of times?
Re:Java is better than C++ for high speed trading systems by knuthsat on Sunday November 29, 2020 @06:59PM (#25249308)
Unfortunately, any profiler I tried does not show these issues. Because the code you are profiling will be optimized completely differently. Although it makes sense to do the optimizations/inlining inside the top-level functions that profiler reports to take a lot of time (even if the iteration happens in deeper levels).

You just have to try it and see. I remember it was quite easy in IntelliJ, I believe there's an option to inline all invocations of a function. I just went crazy with that option but did it systematically to really find where the bottleneck is and make a minimal change.

Re:Java is better than C++ for high speed trading systems by arthurcolle on Thursday November 26, 2020 @02:22AM (#25217700)
I thought the actual approach taken these days is to disable GC for any JVM based trading systems and use arena based architectures or similar for application where you need super low latency, like a LOB mirror or execution engine, no?
Re:Java is better than C++ for high speed trading systems by vgatherps on Thursday November 26, 2020 @02:36AM (#25217788)
Yeah, basically everything has to be that way.

At the super fast speeds you start running into things like:

* why won’t the devirtualizer trigger?

* these object headers are sure wasting a lot of cache

* there’s a lot of forced pointer indirection

And you just end up spending vast amounts of time and effort trying to shave off those few microseconds you’re wasting in the JVM. Once you add in all the effort trying to get around the GC, it’s bleak picture for competing with quality C++ without spending far more effort.

Re:Java is better than C++ for high speed trading systems by arthurcolle on Thursday November 26, 2020 @12:46PM (#25222079)
Thanks for the insights - I must admit I only briefly ever even used Java so I am not an expert. Do you have any recommendations for documents or a PDF that covers the JVM memory model and scheduler in any depth that makes it appropriate, possibly with applications to hard-realtime systems?

Again, thanks for the response, this was insightful and I'd love to learn more.

Also, an aside - do you have any thoughts on the use of Rust in these same systems? It's a little bit more bleeding edge, but I'm curious to hear an expert's thoughts!

Re:Java is better than C++ for high speed trading systems by chrisseaton on Thursday November 26, 2020 @04:33AM (#25218371)
What do you mean by ‘devirtualizer’ and why would you want that triggered? Sounds like something you wouldn’t want to trigger?
Re:Java is better than C++ for high speed trading systems by vgatherps on Thursday November 26, 2020 @06:30AM (#25219018)
The devirtualizer (maybe this is the wrong JVM terminology, it’s basically what clang/GC call it) is part of the optimizer which sees that you have a virtual function call (like most in Java) where there is a unique caller, so you can replace the virtual call with a direct one and possibly inline it.

In the JVM I think this can only be done speculatively (you have to double check the type), but it still matters.

Re:Java is better than C++ for high speed trading systems by chrisseaton on Thursday November 26, 2020 @06:39AM (#25219071)
Ah right yes conflict of terminology.

In the JVM devirtualising means making a virtual object a full object again, so the opposite of what you want to be happening.

I don't think the JVM really names the optimisation you're talking about, but it does do it, through either a global assumption based on the class hierarchy, or an inline cache with a local guard.

Re:Java is better than C++ for high speed trading systems by masklinn on Thursday November 26, 2020 @07:20AM (#25219326)
What do you mean by “virtual object”, an object which has been broken up on the stack instead of a “real” object living as a single entity on the heap?
Re:Java is better than C++ for high speed trading systems by chrisseaton on Thursday November 26, 2020 @09:10AM (#25220137)
> What do you mean by “virtual object”, an object which has been broken up on the stack instead of a “real” object living as a single entity on the heap?

Yes... but let's not say 'broken up on the stack' - the object's fields become dataflow edges. The object doesn't exist reifed on the stack - fields may exist on the stack, or in registers, or not at all.

Re:Java is better than C++ for high speed trading systems by aweinstock on Thursday November 26, 2020 @12:58PM (#25222173)
LLVM calls the process of breaking a struct/object into dataflow variables "Scalar Replacement of Aggregates".

https://llvm.org/doxygen/classllvm_1_1SROA.html#details

Re:Java is better than C++ for high speed trading systems by chrisseaton on Thursday November 26, 2020 @01:12PM (#25222273)
Yes that's what the JVM calls it - and then the node the ties together the state is the virtual object.
Re:Java is better than C++ for high speed trading systems by bluGill on Thursday November 26, 2020 @08:35AM (#25219875)
Remember back in cs101 where you had class animal, with subclasses dog and cat. You can call speak() on animal and get either ruff or meow depending on what animal is. Animal is a virtual object. The system needs to do some work to figure out which speak to call every time, the work isn't too bad, but it turns out that cpus basically never have the right thing in the cache, so it ends up being very slow compared to most of what you are doing.

When we say devirtualize we mean that we know animal is always a cat so we don't have to look up which speak to use.

Re:Java is better than C++ for high speed trading systems by masklinn on Thursday November 26, 2020 @12:07PM (#25221742)
Please don't take others for complete morons.

And that makes literally no sense in-context, you're mapping those words directly to the concept of virtual methods but that's the opposite of the way chrisseaton uses them (and they're clearly familiar with the concept of virtual calls and it's not what they're using "virtual" for), hence asking them what they mean specifically by this terminology.

Re:Java is better than C++ for high speed trading systems by gameswithgo on Thursday November 26, 2020 @06:57AM (#25219168)
the jvm names the optimization exactly like he said
Re:Java is better than C++ for high speed trading systems by thu2111 on Thursday November 26, 2020 @12:26PM (#25221902)
IIRC it calls it monomorphisation.
Re:Java is better than C++ for high speed trading systems by wolf550e on Thursday November 26, 2020 @07:16AM (#25219291)
See Aleksey Shipilёv on JVM method dispatch: https://shipilev.net/blog/2015/black-magic-method-dispatch/
Re:Java is better than C++ for high speed trading systems by blackrock on Thursday November 26, 2020 @04:08AM (#25218254)
Why not just write it in C? And pre-allocate all the data structures, make them global, put them into a queue, and constantly reuse them. No more need to instantiate objects.
Re:Java is better than C++ for high speed trading systems by vgatherps on Thursday November 26, 2020 @06:31AM (#25219021)
This is why C++ is used over Java for very fast stuff, or “just” fast stuff if you don’t want to bother fighting the JVM
Re:Java is better than C++ for high speed trading systems by chrisseaton on Thursday November 26, 2020 @04:34AM (#25218375)
Why not just write it in assembly while you’re at it?

The answer to both questions is that many people prefer writing in higher-level languages with more safety guarantees.

Re:Java is better than C++ for high speed trading systems by mcqueenjordan on Thursday November 26, 2020 @07:56AM (#25219617)
This is a bit of a false equivalency -- there aren't many perf benefits in rewriting a C program in asm. The cost you pay for that rewrite is also much greater.

Yes, of course $HIGH_LEVEL_LANG is preferable for many many use cases. In this context, we're discussing "high speed trading systems", for which native implementations are going to be the favorite.

Re:Java is better than C++ for high speed trading systems by chrisseaton on Thursday November 26, 2020 @09:08AM (#25220124)
> for which native implementations are going to be the favorite

...but the point of the article is they aren't always the favourite.

Re:Java is better than C++ for high speed trading systems by opportune on Thursday November 26, 2020 @01:32PM (#25222451)
They mention not even using most of the Java features (exceptions, built in GC) that make it safe. So I think it's a pretty fair question, since they are essentially using a very stripped down version of the language that removes most of the compelling reasons to use it, and seemingly fighting the language runtime along the way.
Re:Java is better than C++ for high speed trading systems by chrisseaton on Friday November 27, 2020 @06:54AM (#25227901)
The reason these people still use Java is that everything else can be nice high-level Java code.

So they use regular Java for the build system, deployment, testing, logging, loading configuration, debugging, etc etc. There's a small core written in this strange way... but everything else is easier. And things like your profiler and debugger still work on the core as well.

Re:Java is better than C++ for high speed trading systems by acqq on Thursday November 26, 2020 @08:06AM (#25219695)
I write C++ for now almost 30 years, and always for the workloads where the cost of allocations was plainly visible, especially in the critical parts of the applications. So I have never stopped writing "non idiomatic" C++, at least from the point of view of typical language lawyers (and C++ attracted them a lot through the years). And I'm surely not the only one: there were different environments where it was recognized, through the times, first, that creating and destroying much objects was very bad, and later, with the growth of the C++ standard library, that even not everything in the C++ standard library should be treated the same, and that are better solutions than what's already available, and that the third party libraries are often bringing even more potential danger.

Depending on the goal, one has to be very careful when choosing what one uses. The good side is, C++ kept its C features: if I'm deciding how I'll do something, I don't have to follow the rules of the "language lawyers." I can do my work producing what is measurably efficient. And compiler can still help me avoiding some types of errors -- others can anyway be discovered only with testing (and additional tools). At the end, knowing good what one wants is the most important aspect of the whole endeavor.

Re:Java is better than C++ for high speed trading systems by MauranKilom on Thursday November 26, 2020 @10:13AM (#25220659)
> I don't have to follow the rules of the "language lawyers."

I'm not exactly sure what specifically you are trying to imply here. When you proclaim to ignore language lawyers, it sounds like you are knowingly breaking the rules of the C++ standard. That takes a lot of faith in compilers doing what you meant to do, despite writing code that is incompatible with the standard those compilers implement...

Re:Java is better than C++ for high speed trading systems by rramadass on Friday November 27, 2020 @07:22AM (#25228101)
Yep. I always say start with the "better C" part of C++ to get stronger type checking and then add in other features only as needed. All abstractions should be with minimal overhead with a strict pay only what you need policy.
Re:Java is better than C++ for high speed trading systems by SomeoneFromCA on Thursday November 26, 2020 @09:15AM (#25220174)
Yep, the same thing I do - just write in C++ as if it was good old C, with very occasional use of templates, containers and exceptions.
Re:Java is better than C++ for high speed trading systems by acqq on Thursday November 26, 2020 @09:53AM (#25220486)
To those who miss the point, nobody is here denying that C++ has something to bring, it's just that what it brings isn't what those who promote some fashion would claim that is to be universally used, and, honestly, there's no actual reason to believe such claims, for they being not more true now than at the times where "making complex OOP hierarchies" was the most popular advice -- I remember these times too. Or the times when managers wanted to believe that everybody will just use Rational Rose to draw nice diagrams and the actual programming won't be needed, at all. Every time has its hypes:

http://www.jot.fm/issues/issue_2003_01/column1/

https://wiki.c2.com/?UmlCaseVultures

One size doesn't fit all. Some solutions to some problems could be and are provably better than those typically promoted or "generally known" at some point of time.

If that all still doesn't mean anything to you, please read carefully and very, very slowly "The Summer of 1960", seen on HN some 9 years ago:

https://news.ycombinator.com/item?id=2856567

Edit: Answering the parallel post writing "When you proclaim to ignore language lawyers, it sounds like you are knowingly breaking the rules of the C++ standard."

No. The language lawyers, in my perception, religiously follow everything that enters the standard and proclaim that all that has to be used, because it's standardized. Including the standard libraries and some specific stuff there that isn't optimal for the problem I'm trying to solve. And especially that whatever is newer and more recently entered the standard is automatically better. It's understandable that they support their own existence by doing all that -- it's about becoming "more important" just by following/promoting some book or some obligatory rituals (it's an easy and time proven strategy through the centuries, and that's why I call it "religiously", of course -- and I am also not surprised that somebody who identifies themselves with being one of the "lawyers" wouldn't like this perspective -- you are free to suggest a better name). But it should also be also very obvious that it's not what's necessarily optimal for me to follow, as soon as I can decide what I'm doing. And yes, it's different in the environment where the "company policy" is sacred. There one has the company "policy lawyers", and typically every attempt of change can die if one isn't one of them.

Re:Java is better than C++ for high speed trading systems by pjmlp on Thursday November 26, 2020 @05:07PM (#25223866)
I guess this is for you, in case you haven't seen it already,

"Orthodox C++"

https://gist.github.com/bkaradzic/2e39896bc7d8c34e042b

Re:Java is better than C++ for high speed trading systems by acqq on Thursday November 26, 2020 @05:31PM (#25224018)
Haven't seen, but thanks. Lived and worked while following some of the ideas mentioned.

E.g. at the whole bottom of the page in some comment is a link to:

"Why should I have written ZeroMQ in C, not C++ (part II)"

https://250bpm.com/blog:8/

where the author writes "Let's compare how a C++ programmer would implement a list of objects..." and then "The real reason why any C++ programmer won't design the list in the C way is that the design breaks the encapsulation principle" etc.

I have indeed more than once used intrusive data structures in non-trivial C++ code, and the result was easy to read, and very efficient. There I really didn't care about some "thou shalt not" "breaking the encapsulation principle" because whoever thinks at that level of "verbot" 100% of times is just wrong.

The "encapsulation principle" is an OK principle for some levels of abstraction, but nobody says that one has to hold to it religiously (exactly my point before). I would of course always make an API which would hide what's behind it. But where I implement something ("the guts" of something), I of course have my freedom to use intrusive elements, if that solves the problem better. I have even created some "extremely intrusive" stuff (with a variable number of intrusive links in the structures). It worked perfectly. Insisting on doing anything as "ritual" all the time is just so, so wrong.

Re:Java is better than C++ for high speed trading systems by dehrmann on Thursday November 26, 2020 @02:31AM (#25217745)
I've heard of people doing that 10-15 years ago. I'm sure it still works, but hopefully the GC situation has also improved.
Re:Java is better than C++ for high speed trading systems by simonh on Thursday November 26, 2020 @03:28AM (#25218047)
A pause is still a pause though. One system I know of had a solution. Throw in a huge amount of RAM on the server and delay garbage collection until end of day.
Re:Java is better than C++ for high speed trading systems by maccard on Thursday November 26, 2020 @08:46AM (#25219949)
But a pause that can happen when you want it is acceptable. A 3 second stall might be totally acceptable as long as it happens outside of a trade, and you can guarantee that.
Re:Java is better than C++ for high speed trading systems by simonh on Thursday November 26, 2020 @03:41PM (#25223373)
If you can predict 3 seconds in advance if you’re going to need to trade or not, you’d make millions very quickly. In trading terms, that’s basically having a time machine.
Re:Java is better than C++ for high speed trading systems by maccard on Thursday November 26, 2020 @03:50PM (#25223429)
You don't need to predict in advance, you just need the capability in the system. If a system takes X time from the beginning of a trade to being ready to process the next trade, with Y of that time being GC, it doesn't matter how long Y is if you can execute the entire trade before all of the GC happens.
Re:Java is better than C++ for high speed trading systems by simonh on Thursday November 26, 2020 @05:22PM (#25223957)
I used to support a derivatives trading system at a company called Patsystems, so I’ve seen this. Our legacy system could process trade triggers from 4ms to 7ms, but tracing the behaviour of the new system it could do it in 3ms, great. Except every now and then a GC pause would halt order processing for around 50ms. Our customers hit the roof.

Trading systems trigger almost all their orders based on detecting market changes, which you cannot predict. If a symbol hits a price that triggers one of your trades you want that trade in the market ASAP every millisecond matters. Randomly add 50ms on to that and your trading system is out of business. The customers will go elsewhere.

Re:Java is better than C++ for high speed trading systems by maccard on Monday November 30, 2020 @05:27AM (#25252404)
(Sorry, I missed this over the weekend) - I think the issue in this case is you're selling this as a guaranteed 3ms, going down from 4-7ms. If you have to pause for this 50ms GC once every X trades, then you force the GC to happen _after_ the X-1th trade has completed, but you need to provision an extra 15(?) machines to cover the pause. Otherwise, you're not delivering 3ms trades, you're delivering (3 + GCTime/X) ms. It doesn't matter if GC takes 1ms or 1s, you "simply" need to have the capacity to cover the extra GC time.
Re:Java is better than C++ for high speed trading systems by overkalix on Thursday November 26, 2020 @04:02AM (#25218226)
Why waste money hire best engineers when more ram does trick?
Re:Java is better than C++ for high speed trading systems by ska on Thursday November 26, 2020 @11:44AM (#25221458)
As I understand it (before my time), this was a practical solution found on original symbolics lisp machines; trigger the GC and go get lunch...
Re:Java is better than C++ for high speed trading systems by 2sk21 on Thursday November 26, 2020 @07:09AM (#25219236)
Interesting but doesn't allocation get slower as the heap increases?
Re:Java is better than C++ for high speed trading systems by masklinn on Thursday November 26, 2020 @07:23AM (#25219343)
Normally yes but that’s mostly a factor of heap fragmentation. It the GC never runs the “old” buffers are always full so you never bother going through them.
Re:Java is better than C++ for high speed trading systems by thu2111 on Thursday November 26, 2020 @12:28PM (#25221917)
There are open source 'pauseless' (really: ultra low pause) GCs for the JVM now. Azul made good money selling such a thing to the finance industry for a long time.

Typical pauses may be far less than a millisecond in these GCs because they do almost everything in parallel.

Re:Java is better than C++ for high speed trading systems by opportune on Thursday November 26, 2020 @01:34PM (#25222466)
What is an arena based architecture? A quick google didn't show any results. My assumption is that you mean pre-allocating all the memory you want to use at once, but I'm not sure and I'm curious.
Re:Java is better than C++ for high speed trading systems by dan-robertson on Thursday November 26, 2020 @03:21PM (#25223246)
Basically yeah. You allocate out of pools or arenas. In a language like C this usually means using a block of memory for objects that can all be freed together, so instead of calling malloc and free for each little object in your critical path (eg from request to response on some server, or a frame in a videogame), you somehow determine a maximum size, allocate that (and write enough bytes to have the OS actually give you the memory), and then allocations are just bumping a pointer into this block. At the end of the request, free the block (or return it to a pool to be used later).

Sometimes an arena may instead refer to a region of memory for allocations that are all the same size/type. Because everything is the same size, the data structures for tracking allocations may be simpler.

In a language like Java, you basically preallocate an array of objects of the same type with a bunch of fields set to zero, and then have some data structure to give you a fast interface a bit like malloc. Because you don’t do any extra allocation, the GC can be safely turned off.

Re:Java is better than C++ for high speed trading systems by bboygravity on Thursday November 26, 2020 @03:23AM (#25218031)
Am I understanding correctly that those firms really really care about latency & have unlimited money & chose C++/JAVA with a standard off-the-shelve compiler + an OS and/or JVM??

If you'd really really care about latency and have the resources, wouldn't it be more effective to just go bare metal? Bare metal as in: no OS (talk to the hardware registers directly from code), possibly a custom compiler, use all the relevant instructions that your CPU offers you. Or at the very least mess with the compiler to optimize it more to the specific make/model of the CPU/hardware that it will run on?

What are the considerations in those companies for or against this?

Re:Java is better than C++ for high speed trading systems by scatters on Thursday November 26, 2020 @03:45AM (#25218134)
I don't know about java, but when using c++ you can use the OS to start the program, set up the hardware mappings and then move it to an isolated core where you talk to the hardware directly without ever issuing a system call.

Compilers already offer flags to optimize for specific processor generations (and use the newly available instructions); you aren't going to be able to do better than that with a custom compiler.

Re:Java is better than C++ for high speed trading systems by funcDropShadow on Thursday November 26, 2020 @07:18AM (#25219309)
The jit compiler of typical jvms automatically uses the instruction sets (with limits afaik) that are available on the hardware that it is running on.
Re:Java is better than C++ for high speed trading systems by bboygravity on Thursday November 26, 2020 @05:15AM (#25218600)
Oh, that's cool. However, you'd still be sharing at least 1 core (and all peripheral hardware and memory access in the system) with the OS. A core, other hardware and memory that you could otherwise access directly from your application without having to wait for the OS to finish its business?

I'm not sure whether it's worth it to go through this trouble (writing for bare metal vs just using an off-the-shelve OS) in a real life trading-app scenario. Hence my wonder :)

Re:Java is better than C++ for high speed trading systems by scatters on Thursday November 26, 2020 @07:26AM (#25219366)
Accessing other hardware isn't latency-sensitive, though; that's usually disk and the internal network, for logging, telemetry and control. Typically a trading application will keep a thread running on the shared core and send messages between that and its dedicated core thread using lock-free queues, or simple atomics. As you say, writing for bare metal is a lot of hassle and it's unnecessary for the parts of a trading application that don't need to be super fast; using a commodity OS and isolating resources gives the best of both worlds.
Re:Java is better than C++ for high speed trading systems by sakex on Thursday November 26, 2020 @11:34AM (#25221377)
I've never seen that, how do you do it? Also, how do you deal with VM and scheduling?
Re:Java is better than C++ for high speed trading systems by scatters on Thursday November 26, 2020 @12:32PM (#25221960)
Isolating a core: isolcpus and taskset, or possibly cgroups, plus nohz and there's a patch set that offers even stronger isolation guarantees (keeping kernel threads off the core). Hardware mappings are done as a ring buffer in memory mapped to the device; a kernel module helps set up that mapping but once it's in place reads and writes to those virtual addresses go directly (well - via MMU and memory bus) to the hardware. The general term for this is user-space networking (although obviously you can do it with other hardware as well). Some addresses may be mapped to device registers that trigger hardware actions on read/write.

VM - the key is to get everything mapped in at the start and avoid page faults subsequently. madvise can help with this and obviously you need to avoid memory leaks that could result in sbrk - but in any case allocating at all in the trading thread is generally unnecessary (after startup) and frowned on. This does mean that the (lock-free) queue back to the shared core needs to recycle memory and both sides need to service it regularly or you need a strategy to deal with exhaustion. Scheduling isn't an issue - you have a single thread per core and (with isolcpus) the kernel scheduler knows to avoid placing other threads on it.

Re:Java is better than C++ for high speed trading systems by rramadass on Friday November 27, 2020 @07:27AM (#25228129)
Thank you for that writeup. Can you please list some resources (links/articles/books etc.) for us to read up on the above?
Re:Java is better than C++ for high speed trading systems by ericbarrett on Thursday November 26, 2020 @12:12PM (#25221796)
Brief intro, should bootstrap your knowledge: https://codywu2010.wordpress.com/2015/09/27/isolcpus-numactl...
Re:Java is better than C++ for high speed trading systems by throwaway_dcnt on Thursday November 26, 2020 @12:54PM (#25222139)
In addition to the peer comments, using JNI, these facilities can also be availed in Java. Chronicle queue does this.
Re:Java is better than C++ for high speed trading systems by fma on Thursday November 26, 2020 @02:06PM (#25222733)
Well...the article says:

"If you have an unlimited amount of time and resources, the best solution for speed will be coded in FPGA," says Lawrey, referring to the language that directly codes field-programmable gate arrays. "If you still have a lot of time and resources and you want to create multiple exchange adaptors, you'll choose C++. - But if you want to engage with 20+ exchanges, to go to market quickly, and implement continuous performance tuning, you'll choose Java."

Re:Java is better than C++ for high speed trading systems by layoutIfNeeded on Thursday November 26, 2020 @03:34AM (#25218072)
I used to work at a market maker where they used FPGAs to beat HFTs. Of course it was a constant arms race, so I’m not sure what they would be using nowadays...
Re:Java is better than C++ for high speed trading systems by bboygravity on Thursday November 26, 2020 @03:37AM (#25218089)
I would imagine they switched to ASICs which are more optimized than FPGAs (much smaller feature size, less general reconfigurable bloat, higher clocks, etc).
Re:Java is better than C++ for high speed trading systems by vgatherps on Thursday November 26, 2020 @06:37AM (#25219056)
Only a few have, and even then only for a few fixed things. They have extreme versions of the inflexibility problems that fpgas have, and few exchanges have low enough jitter to justify ASICS over fpgas.

It might surprise people that relatively few hfts do latency arb (and the ones that do often have some other structural advantage), and at that the ones are more and more mixing in serious short-term alpha. In that context speed is simply becoming table stakes for playing the game, and not the one true race to win it all.

Re:Java is better than C++ for high speed trading systems by chrisseaton on Thursday November 26, 2020 @04:36AM (#25218389)
I don’t know what you think the practical benefit of running with no OS is?
Re:Java is better than C++ for high speed trading systems by bboygravity on Thursday November 26, 2020 @05:10AM (#25218570)
More processing capacity for your application (no need to share with OS), no more interruptions by the OS that are unpredictable in duration, no more interruptions by the OS that are unpredictable in terms of timing and priority and above all, since this seems to be the main goal of the software we're talking about: lower overall latency. Standard C++/JAVA (as far as I know) talks to hardware through a software layer (the OS's system calls). This takes time. Time you can save by cutting out the middle man.

There are apparently ways to do this with an OS running in parallel as well though when you have multiple cores available apparently (see another comment to this thread).

Re:Java is better than C++ for high speed trading systems by chrisseaton on Thursday November 26, 2020 @05:59AM (#25218836)
You can get all this by pinning to a core and DMA to hardware. Think of the OS like a library - if you don't call it and don't ask it to call you it stays out of the way. There's no need to throw away the OS.
Re:Java is better than C++ for high speed trading systems by vgatherps on Thursday November 26, 2020 @06:38AM (#25219068)
This is exactly what is done. OS’s are really nice to have around and will stay out of the way. In the day and age of fpgas no reason to ruin the software side to maybe kind of sort of get a bit faster in your software?
Re:Java is better than C++ for high speed trading systems by toolslive on Thursday November 26, 2020 @07:14AM (#25219276)

    - raw, unshared access to devices.
    - no more interrupts.
You can get really close to this via virtualization though. Run a guest machine without operating system on the hypervisor. It doesn't even have to be low level code to get most of the benefits (for example MirageOS)
Re:Java is better than C++ for high speed trading systems by chrisseaton on Thursday November 26, 2020 @09:07AM (#25220116)
> raw, unshared access to devices

Get to OS to set up DMA for you.

> no more interrupts

If the OS has no need to interrupt you, it will never interrupt you. The OS doesn't context switch from a usefully running application on its own core unless you ask it to.

Don't need virtualisation.

Re:Java is better than C++ for high speed trading systems by bluGill on Thursday November 26, 2020 @08:40AM (#25219906)
There is only a limit amount of money to make. If your algorithm generates 100k in gross profit a year that doesn't even pay for the programmers to maintain it, unless they can do other things as well. (I'd guess common, there are a lot of algorithms) the sum total doesn't pay. Where it does pay you are better off spending money on fpga, or even asic.
Re:Java is better than C++ for high speed trading systems by roel_v on Thursday November 26, 2020 @02:54AM (#25217880)
Which one of these firms made the most money?
Re:Java is better than C++ for high speed trading systems by vgatherps on Thursday November 26, 2020 @03:05AM (#25217932)
The third one was definitely the least, it was losing money (and specifically to trader-invisible things that never got worked on).

The whole of the trading strategy (and capital traded, return profiles, etc) between the first two was fairly different, so it’s hard to compare.

I would say though that the first firm was significantly outperforming its peers in a way the second firm did not, although both were very successful.

The technology wasn’t the whole story in either case, but the first firm had significantly more and better opportunities as a result of just having a better stack all around

Re:Java is better than C++ for high speed trading systems by Ragib_Zaman on Thursday November 26, 2020 @03:11AM (#25217967)
It's generally pretty rare for a market maker to lose money over a whole year. Colour me surprised.
Re:Java is better than C++ for high speed trading systems by lordnacho on Thursday November 26, 2020 @08:39AM (#25219897)
There's costs that aren't the PnL of buy-low-sell-high. The coders, the data, the infra. All cost money, a lot of money. Add to that there's a competitive aspect in the models interacting with each other, there's no slam-dunk.

There's at least a couple of MMs struggling these days.

Re:Java is better than C++ for high speed trading systems by hnracer on Thursday November 26, 2020 @07:08AM (#25219226)
True but I feel that the market maker label gets applied pretty loosely nowadays, couldve been a firm that mixes in a lot of intraday position taking trades that blew up
Re:Java is better than C++ for high speed trading systems by Roritharr on Thursday November 26, 2020 @02:09AM (#25217620)
Interestingly I have seen this pattern in all kinds of software businesses, but for most it tended to be less of a core business problem.

I'm still wondering if the businesses would work better if the focus on technical excellency could be instilled and especially which parts of the company would have to suffer for it and what the ultimate outcome would be.

I'm convinced that at least for some companies, it simply can't be the winning strategy.

Re:Java is better than C++ for high speed trading systems by fizixer on Thursday November 26, 2020 @08:56AM (#25220024)
You missed one comparison: C infra (no C++).

(well strictly speaking, additionally you could also have hand-written assembly infra).

Re:Java is better than C++ for high speed trading systems by humanrebar on Thursday November 26, 2020 @10:14AM (#25220664)
You can write C style code in C++ and still get access to features that are still interesting in the problem domain. constexpr functions, typesafe enums, static assertions, and destructors come to mind. No need to even touch a template or inheritance if you don't want to.

The main benefits of C per se are ABI stability and availability of compilers.

Re:Java is better than C++ for high speed trading systems by 95th on Thursday November 26, 2020 @09:11AM (#25220141)
Well there is a middle ground - Rust
Re:Java is better than C++ for high speed trading systems by aldanor on Thursday November 26, 2020 @09:43AM (#25220382)
From what perspective exactly is Rust a middle ground Java and C++?
Re:Java is better than C++ for high speed trading systems by jandrewrogers on Thursday November 26, 2020 @11:31AM (#25221348)
Rust improves on Java in that it doesn't have a GC, so no pauses, and the code gen is similar to C++ in terms of performance.

Rust is worse than C++ in that it struggles to express some idiomatic high-performance code architectures, such as using DMA for I/O, because they violate axioms of Rust's memory safety model, or in other cases because Rust currently lacks the language features. To make it work in Rust requires writing more code and disabling safety features.

Rust fixes many language design and performance issues with Java, while offering some similar types of safety, but (like Java) it is missing some elements of expressiveness of C++ that are important for high-performance architectures.

Re:Java is better than C++ for high speed trading systems by aldanor on Thursday November 26, 2020 @02:16PM (#25222801)
Hm... unsafe {} + use pointers and you're back to c++-style? You've had unsound code in one language, now you have unsound code in other language, how come it's suddenly worse other than having to type unsafe explicitly?

I've done my fair share of C++, including low latency stuff, and in the grand scheme of things I'd say "expressiveness of C++" is completely overshadowed by its complexity and occasional ambiguity, lack of proper type system and proper generics, lack of proper module system, lack of dependency tracking, lack of a unified build systems, etc. I'm not exactly sure what you mean by expressiveness though.

Re:Java is better than C++ for high speed trading systems by jandrewrogers on Thursday November 26, 2020 @03:44PM (#25223392)
The issue, beyond having no visible references at compile-time, is that DMA has no concept of objects and has its own rules for how and when it interacts with regions of memory. It is oblivious to ownership semantics. In things like databases, most of your address space is DMA-able memory and therefore "unsafe". In C++, you can completely hide these mechanics behind constructs that look like unique_ptr/shared_ptr but which are guaranteed to be DMA-safe. In this context, all references are treated as mutable because mutability is not a property of references per se. Conflicts can only be resolved at runtime.

Instead of using an ownership-based memory safety model, which is clearly broken for systems that use DMA, they can use schedule-based memory safety models, which are formally verifiable. These don't rely on immutable references for safety, and also eliminate most need for locking -- many of the concepts originate in research on automated lock-graph conflict resolution in databases. The evolution away from ownership-based to schedule-based models is evident in database kernels over the decades. It was originally motivated by improved concurrency; suitability for later DMA-based designs was a happy accident and C++ allows it to be expressed idiomatically.

As for expressiveness, beyond the ability construct alternative safety models, modern C++ metaprogramming facilities enable not only compile-time optimization but also verification of code correctness that would be impractical in languages like Rust.

Re:Java is better than C++ for high speed trading systems by splix on Thursday November 26, 2020 @10:32AM (#25220818)
Maybe dev comfort like with Java, and performance like with C++?
Re:Java is better than C++ for high speed trading systems by pjmlp on Thursday November 26, 2020 @05:09PM (#25223882)
I like Rust, but it definitely isn't dev comfort like Java.
Re:Java is better than C++ for high speed trading systems by phildawes on Thursday November 26, 2020 @11:19AM (#25221250)
Memory safety with no unpredictable gc latency
Re:Java is better than C++ for high speed trading systems by vmception on Thursday November 26, 2020 @09:39AM (#25220352)
VHDL is faster no?

Isn’t everything you wrote from the wrong decade?

Re:Java is better than C++ for high speed trading systems by vgatherps on Thursday November 26, 2020 @07:01PM (#25224427)
Fpgas have a huge amount of operational and practical difficulties. They’re great for fixed-function stuff like feed parsing or dumb triggers your software can direct in real-time, but absolutely terrible for something where you the ability to be flexible and adaptive.

Pure latency arb isn’t the only hft trade there is anyways.

Re:Java is better than C++ for high speed trading systems by vmception on Thursday November 26, 2020 @09:38AM (#25220348)
VHDL is faster no?