Java is the best language in the world. Java replaces C in high frequency trading++

Wang Zebin 2020-11-06 01:15:04
java best language world. world


High frequency trading

High frequency trading refers to computerized trading that seeks to profit from extremely short-term market changes that people cannot use , such as , A small change in the difference between the bid price and the offer price of a security , Or the tiny price difference of a stock on different exchanges . In high-frequency trading , Automation applications process hundreds of millions of market signals a day , Sending tens of millions of orders on exchanges around the world . To keep the business competitive , The response time must always be microseconds , Especially at the peak of black swan abnormal events .

The typical system structure of high frequency trading system is as follows : Financial transaction signals will be converted into internal market data format ( Transaction use TCP、UDP And so on ) And a variety of formats ( Such as binary 、SBE、JSON、FIX etc. ). then , These standardized messages are sent to the algorithm server 、 Statistical engine 、UI、Log Server And various databases ( cache 、 File or distributed database ). Any delay will result in high cost . for example , Make a decision based on the old price or order too late . In order to gain a microsecond advantage , Most trading participants put in expensive hardware : A liquid cooled one CPU Server pool for (2020 Years can be bought 56 nucleus 、5.6GHz、1TB Memory servers ), Assembled in the main switching data center 、 High end nanosecond network switch 、 Dedicated transoceanic line , Even microwave networks .

Common high-frequency trading systems use highly customized Linux kernel , And with an operating system bypass , In this way, the data can be directly from the network card " Jump " To the application 、 be based on IPC Interprocess communication , Even use FPGA( Programmable single purpose chip ). As for programming languages , Usually the first thing that comes to mind is C++, It's actually a natural choice in this field .C++ The biggest advantage is that it runs fast , Closest to the machine code , And it compiles directly according to the target platform , It has the characteristics of high efficiency and stability .

Use Java Instead of C++

We made a different choice . in the past 14 In the year , We use Java Development , And use cheap hardware instead of expensive high-end devices .
In a small team , A work environment with limited resources and a lack of skilled developers ,Java It means that we can do software iterations quickly , because Java Ecosystem than C Series have faster development efficiency . Improvement measures can be discussed in the morning , And in the afternoon in production 、 Test and release .

Compared to large companies that need weeks or even months of software updates , This is a key advantage . In this field , A mistake can erase a year's profits in seconds , So you can't compromise on quality . We use a lot of open source libraries and projects , Implement a strict agile development environment , Including the use of Jenkins、Maven、 unit testing 、 Night building and Jira. adopt Java, Developers can focus on business logic , Not like it C++ Debug memory that way Coredump Or dealing with pointers . and , because Java Powerful memory management , Junior programmers can also be immediately involved in developing code , And the risk is controllable .

As long as you have good design patterns and clean coding habits , You can use it Java achieve C++ Delay of . We all know , send Java The reason why software development is powerful and convenient , It's also the main reason for its shortcomings , That's it Java virtual machine (JVM).

Java Just in time compilation code (Just in Time compiler ), It means the first time you encounter some code , There may also be compilation delays .Java The way to manage memory is by allocating memory blocks in heap space . Every once in a while , It will clean up the space , Delete old objects , Make room for new objects . The main problem is , For accurate statistics , Application threads need to be instantaneously " frozen ". This process is called garbage collection (GC).GC It's low latency application developers who give up Java The main reason is .

On the market Java The most common and standard virtual machine is Oracle Hotspot JVM, It's in Java It's widely used in the community , Mainly for historical reasons . For very demanding applications ,Azul Systems Provides a great alternative , be called Zing.Zing yes Oracle Hotspot JVM A powerful alternative .Zing It's solved GC Pause and JIT Compilation problems .

Let's look at the use of Java The inherent problems and possible solutions .

understand Java Just in time compiler

image C++ Such a language is called a compiled language , Because the delivered code is completely binary , Can be directly in CPU On the implementation .PHP or Perl It's called interpretive language , Because the interpreter ( Installed on the target machine ) Compile every line of code while running .

Java In between ; It compiles the code into what's called Java Bytecode , Bytecode can be compiled into binary when it thinks fit .Java The reason you don't compile code at startup , It's about long-term performance optimization . By observing the operation of the application , Analysis of real-time method calls and class initialization ,Java Can compile part of the code that is often called . It may even make assumptions based on experience ( This part of the code will never be called , Or the object is always a String).

therefore , The actual compiled code is very fast , But there are still 3 Disadvantages .

1、 A method needs to be called a certain number of times to reach the compilation threshold , Then it can be optimized and compiled ( This restriction can be configured , But usually it is 10000 About calls ). Before that , Code that is not optimized doesn't use " Full speed " function .Java There is a trade-off between faster compilation and higher quality compilation ( If the assumption is wrong , There will be a cost of recompiling ).

2、 When Java When the application restarts , Back to the beginning , You have to wait until you reach this threshold again .

3、 Some applications ( Like our scene ) There are some less frequent but critical approaches , These methods will only be called a few times , But when they are called , It needs to be extremely fast ( think about it , A risk or stop loss function is called only in an emergency ).

Azul Zing By making it JVM The state of the compiled method and class " preservation " To solve these problems in what it calls a configuration file . This is called ReadyNow! The unique function of , signify Java Applications always run at optimal speed , Even after a reboot . When you restart an application using an existing configuration file ,Azul JVM It immediately calls its previous results and compiles the annotated method directly , So it solved Java Preheating problem .

Besides , You can create a configuration file in the development environment , To simulate production behavior . then , The optimized configuration file can be deployed in the production environment , Because all critical paths are compiled and optimized .Zing The delay of is fairly stable over time . The percentile distribution shows that ,1% In the time of ,Hotspot JVM The resulting delay is Zing JVM Of 16 times .

Solve garbage collection (GC) The question of pause

In the garbage collection process , The entire application may freeze for milliseconds to seconds ( Latency increases with code complexity and heap size ), What's worse is , You can't control when this happens . While pausing an application for a few milliseconds or even seconds, for many Java It may be acceptable for applications , But it's a disaster for low latency applications , Whether it's a car 、 Aerospace 、 Health care or Finance .

GC The impact of Java It's a big topic among developers ; A complete garbage collection is often called "stop-the-world", Because it freezes the entire application .
these years , many GC Algorithms are trying to achieve throughput ( How many? CPU For practical application logic rather than garbage collection ) And GC Make a trade-off between .

since Java 9 since ,G1 The collector has always been the default GC, The main idea is to divide according to the time target provided by users GC Pause time . It usually provides a short pause time , But the cost is lower throughput . Besides , The pause time increases with the size of the heap .Java Provides a number of settings to adjust its garbage collection ( as well as JVM), From heap size to collection algorithms , And assigned to GC Number of threads for . therefore , notice Java It's common that applications are configured with a large number of custom options .

Many developers have turned to various technologies to completely avoid GC. The main idea is , If you create fewer objects , Fewer objects need to be cleaned up . An old technique is to use an object pool of reusable objects . for example , A database connection pool will hold 10 References to open connections , Be prepared to use when needed .

Multithreading usually requires locks , This can cause synchronization delays and pauses ( Especially when they share resources ). A popular design is a ring buffer queue system , In a lockless setting , There are many threads that write and read . Some experts even choose to implement it entirely on their own Java memory management , Manage your own memory allocation , Although it solved a problem , But it brings more complexity and risk . under these circumstances , Obviously, other things should be considered JVM, So we decided to try Azul Zing JVM. Soon , We've achieved very high throughput , The pause is negligible .

This is because Zing A unique collector is used , be called C4(Continuurrentously Concurrent Compacting Collector), It allows garbage collection without pauses , And don't care Java The size of the heap ( Up to 8TB). This is done by... While the application is still running , Concurrent mapping and compression of memory to achieve . Besides , It doesn't need to change any code , Delays and speed improvements are out of the box , No need for lengthy configuration . under these circumstances ,Java Programmers can enjoy the best of both worlds , You can enjoy Java The simplicity of ( No need to be paranoid about creating new objects ), You can enjoy it again Zing The underlying performance of , Make the delay of the whole system highly predictable .

Thanks a lot GC easy, A generic GC Log Analyzer , We can use it in real-world automated trading applications ( In a simulated environment ) Quickly compare the two JVM. In the application of high frequency trading , Use Zing Of GC Than using standard Oracle Hotspot JVM Small 180 About times . What's more impressive is ,GC The pause usually corresponds to the actual application pause time , and Zing intelligence GC Usually occurs in parallel with minimal or no actual pause .

summary

Java While enjoying simplicity and business oriented features , High performance and low latency can still be achieved . although C++ Still available for specific underlying components , Such as driver 、 database 、 Compilers and operating systems , But most of them can be used in reality Java To develop , Including demanding applications like high-frequency trading .

java jdk download come from Swish Download

版权声明
本文为[Wang Zebin]所创,转载请带上原文链接,感谢

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云