在 Windows 中使用 C++ 的低延迟交易系统?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3593054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Low latency trading systems using C++ in Windows?
提问by Jon
It seems that all the major investment banks use C++ in Unix (Linux, Solaris) for their low latency/high frequency server applications. Why is Windows generally not used as a platform for this? Are there technical reasons why Windows can't compete?
似乎所有主要投资银行都在 Unix(Linux、Solaris)中使用 C++ 作为其低延迟/高频服务器应用程序。为什么 Windows 通常不用作此平台?Windows 无法竞争是否存在技术原因?
回答by caf
The performance requirements on the extremely low-latency systems used for algorithmic trading are extreme. In this environment, microseconds count.
用于算法交易的极低延迟系统的性能要求是极端的。在这种环境中,微秒很重要。
I'm not sure about Solaris, but the case of Linux, these guys are writing and using low-latency patches and customisations for the whole kernel, from the network card drivers on up. It's not that there's a technicalreason why that couldn't be done on Windows, but there is a practical/legal one - access to the source code, and the ability to recompile it with changes.
我不确定 Solaris,但在 Linux 的情况下,这些人正在为整个内核编写和使用低延迟补丁和自定义,从网卡驱动程序开始。并不是说在 Windows 上不能这样做是有技术原因的,而是有一个实际/合法的原因 - 访问源代码,以及通过更改重新编译它的能力。
回答by Ryan Gooler
Technically, no. However, there is a very simple business reason: the rest of the financial world runs on Unix. Banks run on AIX, the stock market itself runs on Unix, and therefore, it is simply easier to find programmers in the financial world that are used to a Unix environment, rather than a Windows one.
从技术上讲,没有。然而,有一个非常简单的商业原因:金融世界的其他部分都在 Unix 上运行。银行在 AIX 上运行,股票市场本身在 Unix 上运行,因此,在金融界更容易找到习惯 Unix 环境的程序员,而不是 Windows 环境。
回答by rjw
(I've worked in investment banking for 8 years) In fact, quite a lot of what banks call low latency is done in Java. And not even Real Time Java - just normal Java with the GC turned off. The main trick here is to make sure you've exercised all of your code enough for the jit to have run before you switch a particular VM into prod ( so you have some startup looping that runs for a couple of minutes - and hot failover).
(我在投资银行工作了 8 年) 事实上,很多银行所说的低延迟都是用 Java 完成的。甚至不是实时 Java - 只是关闭了 GC 的普通 Java。这里的主要技巧是确保在将特定 VM 切换到 prod 之前,您已经练习了足够多的所有代码以使 jit 运行(因此您有一些运行几分钟的启动循环 - 以及热故障转移) .
The reasons for using Linux are:
使用Linux的原因是:
Familiarity
熟悉度
Remote administration is still better, and also low impact - it will have a minimal effect on the other processes on the machine. Remember, these systems are often co-located at the exchange, so the links to the machines (from you/your support team) will probably be worse than those to your normal datacentres.
远程管理仍然更好,而且影响也很小——它对机器上的其他进程的影响很小。请记住,这些系统通常位于交易所,因此与机器(来自您/您的支持团队)的链接可能比与普通数据中心的链接更差。
Tunability - the ability to set swappiness to 0, get the JVM to preallocate large pages, and other low level tricks is quite useful.
可调性 - 将 swappiness 设置为 0、让 JVM 预分配大页面以及其他低级技巧的能力非常有用。
I'm sure you could get Windows to work acceptably, but there is no huge advantage to doing so - as others have said, any employees you poached would have to rediscover all their latency busting tricks rather than just run down a checklist.
我相信你可以让 Windows 以可接受的方式工作,但这样做并没有太大的优势 - 正如其他人所说,你挖走的任何员工都必须重新发现他们所有的延迟破坏技巧,而不是仅仅运行一个清单。
回答by Tony Delroy
Linux/UNIX are much more usable for concurrent remote users, making it easier to script around the systems, use standard tools like grep/sed/awk/perl/ruby/less on logs... ssh/scp... all that stuff's just there.
Linux/UNIX 更适用于并发远程用户,更容易围绕系统编写脚本,在日志上使用标准工具,如 grep/sed/awk/perl/ruby/less...ssh/scp...所有这些就在那里。
There are also technical issues, for example: to measure elapsed time on Windows you can choose between a set of functions based on the Windows clock tick, and the hardware-based QueryPerformanceCounter(). The former is increments each 10 to 16 milliseconds (note: some documentation implies more precision - e.g. the values from GetSystemTimeAsFileTime() measure to 100ns, but they report the same 100ns edge of the clock tick until it ticks again). The latter - QueryPerformanceCounter() - has show-stopping issues where different cores/cpus can report clocks-since-startup that differ by several seconds due to being warmed up at different times during system boot. MSDN documents this as a possible BIOS bug, but it's common. So, who wants to develop low-latency trading systems on a platform that can't be instrumented properly? (There are solutions, but you won't find any software ones sitting conveniently in boost or ACE).
还有一些技术问题,例如:要在 Windows 上测量经过的时间,您可以在基于 Windows 时钟滴答的一组函数和基于硬件的 QueryPerformanceCounter() 之间进行选择。前者每 10 到 16 毫秒递增一次(注意:一些文档意味着更高的精度——例如 GetSystemTimeAsFileTime() 的值测量到 100ns,但它们报告时钟滴答的相同 100ns 边缘,直到它再次滴答)。后者 - QueryPerformanceCounter() - 具有显示停止问题,其中由于在系统启动期间在不同时间预热,不同的内核/CPU 可以报告自启动以来不同的时钟数。MSDN 将此记录为可能的 BIOS 错误,但它很常见。那么,谁想在一个可以'的平台上开发低延迟交易系统?没有被正确检测?(有解决方案,但您不会在 boost 或 ACE 中找到任何方便的软件)。
Many Linux/UNIX variants have lots of easily tweakable parameters to trade off latency for a single event against average latency under load, time slice sizes, scheduling policies etc.. On open source Operating Systems, there's also the assurance that comes with being able to refer to the code when you think something should be faster than it is, and the knowledge that a (potentially huge) community of people have been and are doing so critically - with Windows it's obviously mainly going to be the people who're assigned to look at it.
许多 Linux/UNIX 变体都有许多易于调整的参数,可以在单个事件的延迟与负载下的平均延迟、时间片大小、调度策略等之间进行权衡。在开源操作系统上,还可以保证能够当您认为某些事情应该比它更快时,请参考代码,并且知道一个(可能庞大的)社区已经并且正在批判性地这样做 - 对于 Windows,它显然主要是分配给的人看它。
On the FUD/reputation side - somewhat intangible but an important part of the reasons for OS selection - I think most programmers in the industry would just trust Linux/UNIX more to provide reliable scheduling and behaviour. Further, Linux/UNIX has a reputation for crashing less, though Windows is pretty reliable these days, and Linux has a much more volatile code base than Solaris or FreeBSD.
在 FUD/声誉方面——有点无形,但却是选择操作系统的一个重要原因——我认为行业中的大多数程序员只会更多地信任 Linux/UNIX 来提供可靠的调度和行为。此外,Linux/UNIX 以较少崩溃而著称,尽管如今 Windows 非常可靠,而且 Linux 的代码库比 Solaris 或 FreeBSD 更易变。
回答by BarsMonster
Reason is simple, 10-20 years ago when such systems emerged, "hardcore" multi-CPU servers were ONLY on some sort of UNIX. Windows NT was in kinder-garden these days. So the reason is "historical".
原因很简单,10 到 20 年前,当此类系统出现时,“核心”多 CPU 服务器仅适用于某种 UNIX。这些天,Windows NT 还在幼儿园。所以原因是“历史的”。
Modern systems might be developed on Windows, it's just a matter of taste these days.
现代系统可能是在 Windows 上开发的,现在这只是品味问题。
PS: I am currencly working on one of such systems :-)
PS:我目前正在研究这样的系统之一:-)
回答by BarsMonster
I partially agree with most of the answers above. Though what I have realized is the biggest reason to use C++ is becuase it is relatively faster with a very vast STL library.
我部分同意上面的大部分答案。虽然我已经意识到使用 C++ 的最大原因是因为它有一个非常庞大的 STL 库,速度相对较快。
Apart from it, linux/unix system is also used to boost performance. I know many low latency team which go to a extent of tweaking the linux kernel. Obviously this level of freedom is not provided by windows.
除此之外,linux/unix系统也被用来提升性能。我知道许多低延迟团队在一定程度上调整了 linux 内核。显然,这种自由度不是由 windows 提供的。
Other reasons like legacy systems, license cost, resources count as well but are lesser driving factors. As "rjw" mentioned, I have seen teams use Java as well with a modified JVM.
其他原因,如遗留系统、许可成本、资源也很重要,但不是驱动因素。正如“rjw”所提到的,我已经看到团队使用 Java 以及经过修改的 JVM。
回答by Rory
There are a variety of reasons, but the reason is not only historical. In fact, it seems as if more and more server-side financial applications run on *nix these days than ever before (including big names like the London Stock Exchange, who switched from a .NET platform). For client-side or desktop apps, it would be silly to target anything other than Windows, as that is the established platform. However, for server-side apps, most places that I have worked at deploy to *nix.
有多种原因,但原因不仅是历史原因。事实上,现在似乎有越来越多的服务器端金融应用程序在 *nix 上运行(包括伦敦证券交易所等大牌,它们从 .NET 平台转换而来)。对于客户端或桌面应用程序,针对 Windows 以外的任何应用程序都是愚蠢的,因为 Windows 是已建立的平台。但是,对于服务器端应用程序,我工作过的大多数地方都部署到 *nix。
回答by Rajesh Patil
I second the opinions of historical and access to kernel manipulation.
我支持历史和访问内核操作的意见。
Apart from those reasons I also believe that just like how they turn off garbage collection of .NET and the similar mechanism in Java when using these technologies in some low latency. They might avoid Windows because of the API's at high level which interact with low level os and then the kernel.
除了这些原因,我还相信,就像他们在低延迟使用这些技术时关闭 .NET 的垃圾收集和 Java 中的类似机制一样。他们可能会避免使用 Windows,因为高级 API 与低级操作系统交互,然后与内核交互。
So the core is of course the kernel which can be interacted with using the low level os. The high level APIs are provided just to make the common users life easier. But in case of Low latency this turns out to be a fatty layer and fraction seconds loss around each operation. So a lucrative option for gaining few fraction seconds per call.
所以核心当然是内核,它可以使用低级操作系统进行交互。提供高级 API 只是为了让普通用户的生活更轻松。但在低延迟的情况下,结果证明这是一个脂肪层,并且每次操作都会损失几分之一秒。因此,这是每次通话获得几分之一秒的有利可图的选择。
Apart from this another thing to consider is integration. Most of the servers, data centers, exchanges use UNIX not windows so using the clients of same family makes the integration and communication easier.
除此之外,要考虑的另一件事是集成。大多数服务器、数据中心、交换机使用 UNIX 而不是 windows,因此使用同一家族的客户端使集成和通信更容易。
Then you have security issues (many people out there might not agree with this point though) hacking UNIX is not easy compared to hacking WINDOWS. I don't agree licensing must be the issue for banks because they shower money on every single piece of hardware and software and the people who customize them, so buying licenses will not be as bigger the issue when considered what they gain by purchasing.
然后你会遇到安全问题(尽管很多人可能不同意这一点)与入侵 WINDOWS 相比,入侵 UNIX 并不容易。我不同意许可一定是银行的问题,因为他们在每一个硬件和软件以及定制它们的人身上都投入了大量资金,因此考虑到他们通过购买获得的收益,购买许可不会成为更大的问题。