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

itread01 2020-11-06 01:35:44
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 , Tens of millions of orders are sent across 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 All kinds of agreements ) And a variety of formats ( Such as binary system 、SBE、JSON、FIX etc. ). And then , These standardized messages are sent to the algorithm server 、 Statistical engine 、UI、Log Server And various databases ( Get it 、 Files or distributed databases ). 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 will invest in expensive hardware : An overclocking liquid cooling CPU Server pool for (2020 You can buy 56 nucleus 、5.6GHz、1TB Memory server ), Assembled in the main exchange center 、 High order nanosecond network switch 、 Dedicated transoceanic line , Even microwave networks . Common high-frequency trading systems use highly customized Linux The core , And with an operating system bypass , So the data can be directly from the network card " Jump " To the application 、 Based on IPC Inter program communication , Even use FPGA( Programmable single purpose chip ). To programming language , Usually the first thing that comes to mind is C++, It's actually a natural choice in this field .C++ The biggest advantage of is fast execution , Closest to 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 Develop , And use cheap hardware instead of expensive high-level devices . In a small team , Working environment with limited resources and lack of skilled developers ,Java It means that we can iterate software 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 to update their software , 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 test 、 Night building and Jira. Through Java, Developers can focus on business logic , Not like it C++ That debug memory Coredump Or dealing with indicators . and , Because of 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 Reach C++ The 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 machines (JVM). Java Just in time code compilation (Just in Time compiler ), It means that the first time you encounter some code , There may also be compilation delays .Java Memory is managed 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 " Freeze ". 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 of virtual machines 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 , It's called Zing.**Zing yes Oracle Hotspot JVM A powerful alternative .Zing 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 code delivered is completely binary , Can be directly in CPU On the execution of .PHP or Perl It's called interpretive language , Because the translator ( Installed on the target machine ) Compile every line of code while executing . Java In between ; It compiles code into what is called Java Bit group codes , The bit block code can be compiled into binary system when it thinks fit .Java The reason is that code is not compiled at startup , It's about long-term performance optimization . By observing the execution of the application , Analysis of real-time method calls and class initialization ,Java Will 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 A shortcoming . 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 , The code is not optimized " Full speed " Execute .Java There is a trade-off between faster compilation and higher quality compilation ( If the assumption is wrong , There will be a price to recompile ). 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're 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 " Store " To solve these problems in its so-called configuration file . This is called ReadyNow! The unique function of , It means Java Applications always run at optimal speed , Even after a reboot . When you restart the application with 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 , A configuration file can be created in the development environment , To simulate production behavior . And 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 time ,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 influence 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 . Over the years , A lot of GC Algorithms are all trying to do in throughput ( How many? CPU For practical application logic rather than garbage collection ) And GC Make a trade-off between pauses . 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 . therefore , notice Java It is 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 , There will be less to clear . An old technology 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 buffered queuing system , In a lockless setting , There are many threads to 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 . In this case , 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 about Java The size of the heap ( Up to 8TB). This is done by... While the application is still running , Concurrent mapping and memory compression . Besides , It doesn't need to modify any code , Delays and speed improvements are out of the box , No need for lengthy configuration . In this case ,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 to 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 wisdom GC Usually occurs in parallel with minimal or no actual pause . ## Summary Java While enjoying simplicity and business oriented features , It can still achieve high efficiency and low latency . Although C++ Still available for specific underlying components , Such as drivers 、 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 ]( From [ Whoosh download ](http://www.souso

  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课程百度云