CN110928680A - Order memory allocation method suitable for security trading system - Google Patents

Order memory allocation method suitable for security trading system Download PDF

Info

Publication number
CN110928680A
CN110928680A CN201911090592.XA CN201911090592A CN110928680A CN 110928680 A CN110928680 A CN 110928680A CN 201911090592 A CN201911090592 A CN 201911090592A CN 110928680 A CN110928680 A CN 110928680A
Authority
CN
China
Prior art keywords
order
memory pool
memory
stock
pool
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201911090592.XA
Other languages
Chinese (zh)
Other versions
CN110928680B (en
Inventor
林琨
王泊
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Stock Exchange Technology Co Ltd
Original Assignee
Shanghai Stock Exchange Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Stock Exchange Technology Co Ltd filed Critical Shanghai Stock Exchange Technology Co Ltd
Priority to CN201911090592.XA priority Critical patent/CN110928680B/en
Publication of CN110928680A publication Critical patent/CN110928680A/en
Application granted granted Critical
Publication of CN110928680B publication Critical patent/CN110928680B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q30/00Commerce
    • G06Q30/06Buying, selling or leasing transactions
    • G06Q30/0601Electronic shopping [e-shopping]
    • G06Q30/0633Lists, e.g. purchase orders, compilation or processing
    • G06Q30/0635Processing of requisition or of purchase orders
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange

Abstract

The invention relates to the technical field of computer data processing, in particular to an order memory allocation method suitable for a security trading system, which comprises the following steps: s1: the allocation of the memory is respectively carried out according to the isolation of single stock, and the orders of each stock with the same price gear are sequentially allocated from a series of micro memory pools; s2, when a micro memory pool is fully allocated, the system allocates a new memory pool from a order block memory pool owned by each stock for subsequent new order allocation; s3: when a system is started, a memory pool which is allocated to a single block memory pool needs to be preset; the invention enables the access to the orders to basically fall in the first-level cache of the CPU when matching transaction is carried out, which is 100 times faster than the prior art, and the access can fall in the third-level cache only once when every 273 orders are matched, even in the third-level cache, the access time delay is ten times faster than the prior scheme.

Description

Order memory allocation method suitable for security trading system
Technical Field
The invention relates to the technical field of computer data processing, in particular to an order memory allocation method suitable for a security trading system.
Background
In the trading process of the security trading system, an order container needs to be maintained in a memory, all orders which are not yet traded are stored in the order container, and the order container is marked as an order book (OrderBook).
In an "order book", all orders with equal prices and the same buying and selling directions are regarded as the same order, orders belonging to the same gear need to be concatenated with a chain table, and a data structure (denoted as a priceLeader) is used to store the information of the chain table and store the summary information (price, total number of placed orders, number of remaining outstanding shares, number of committed shares) of all orders in the price gear, as shown in fig. 1. An order book includes a set of two priceleaders with opposite buying and selling directions, which are denoted as leader bookbuy Buy and leader bookSell, and the structure of the order book is shown in FIG. 2.
Since there is a limit of the minimum price change unit (denoted as tickSize) in the trading rule of the stock, the price step number (denoted as levelCount) can be calculated by the following formula within the range of fluctuation range formed by the highest price (denoted as highLimit) and the lowest price (denoted as lowLimit) of a single stock: levelCount int ((highLimit-lowLimit)/tickSize) + 1.
In the process of trading, every time a new order (denoted as newOrder) is received, the system tries to match the order in the optimal price gear opposite to the trading direction, if the optimal price gear opposite to the trading direction does not meet the price set by the newOrder or only partial quantity of the newOrder is matched, the system allocates a piece of memory for the newOrder, the structure of the memory is a technical order (denoted as Techorder), the order business information of the newOrder is copied in the Techorder, the index information of the Techorder in the order book is recorded, and then the Techorder is inserted into the list of outstanding orders recorded by the priveLeader to which the Techorder belongs to wait for being matched by other new orders in the future.
The size of the memory is expressed in bytes, one byte is indicated by capital letter "B", 1024 bytes are indicated by "KB", 1024 "KB" are indicated by "MB", and 1024 "MB" are indicated by "GB". The minimum unit can be accurate to 0.1 nanoseconds when measuring time in the calculation. We use "ns" for nanoseconds, "us" for microseconds, ms for milliseconds, and s for seconds.
The current method of allocating TechOrder in memory is to allocate from a shared memory pool of the entire host. The trading process of one host computer can be responsible for the matching operation of hundreds of stocks, and all TechOrder of the stocks can share one memory pool.
The order of each stock to the host is random, and the memory address of TechOrder allocated from the shared memory each time is also random. All orders for the same stock are not substantially allocated on contiguous memory addresses in shared memory, the span of addresses (MemSpan) can be calculated by the size of each order (orderSize) and the total number of orders for the day (orderCount): the MemSpan ═ orderSize @ orderCount.
The amount of orders processed per day on a trading host is 2000 million, calculated from an order size of 120 bytes, and the calculated memory address span is 2.23 GB. When matching a deal, the order of each stock is matched according to the price sequence and the time sequence of the order entering an order book; orders with the same price gear are matched firstly when entering an order book.
Taking the configuration of the Intel Core i7 CPU by the host computer as an example, when a new order is matched with a plurality of orders in the gear of an opponent in turn, according to the condition that the existing TechOrder is randomly distributed on different physical addresses, when the CPU reads the matched orders in turn, the spanning memory range exceeds the size of the primary cache (32KB), the size of the secondary cache (512KB) and even the size of the tertiary cache (4-32MB) of the CPU, so that the CPU is used for reading the matched orders in main memory.
The access delays corresponding to the first, second and third levels of cache and the main memory of the CPU are respectively as follows: 0.9ns, 2.8ns, 12.9ns, 120 ns.
It can be seen that, in the existing techloder memory allocation method, each time when the next matched order is accessed, the CPU needs to consume 120ns for waiting, so that the overall delay of the trading system is increased, and the throughput of the trading system is reduced.
Disclosure of Invention
The invention aims to solve the defects of the prior art and provides an order memory allocation method suitable for a security trading system, wherein TechOrder in the same gear is allocated on continuous memory addresses and is positioned in a cache span range of a CPU (central processing unit), so that the time for accessing each matched order is shortened to be 0.9 ns-12.9 ns.
In order to achieve the above object, an order memory allocation method suitable for a security trading system is designed, which is characterized in that the method specifically comprises the following steps:
s1: the allocation of the memory is respectively carried out according to the isolation of single stock, and the orders of each stock with the same price gear are sequentially allocated from a series of micro memory pools;
s2, when a micro memory pool is fully allocated, the system allocates a new memory pool from a order block memory pool owned by each stock for subsequent new order allocation;
s3: when a system is started, a memory pool which is allocated to a single block memory pool needs to be preset;
and S4, in addition to the pre-allocation during starting, the system dynamically allocates a new memory pool to be added into the memory pool of the order block for management according to the growing condition of the order during running.
The size of the micro memory pool is the size of the first-level cache of the CPU.
The memory size of a single block memory pool completely falls within the range of the CPU third-level cache.
Each stock has a block memory pool, the unit of management is a local order memory pool, and each free order slot of the local order memory pool is used for distributing to each order.
The method specifically comprises the following steps: allocating a block of memory to a new order is to try to allocate from the free order slot in the local order memory pool linked to the corresponding price position, and when there is no local order memory pool containing a free order slot in this position, the free memory pool is taken from the order block memory pool of this stock to be linked into the price position memory pool list, and the free order slot is taken from the new memory pool to be allocated to the new order.
Compared with the prior art, the invention has the advantages that:
1. the invention enables the access to the orders to basically fall in the first-level cache of the CPU when matching transaction is carried out, which is 100 times faster than the prior art, and the access can fall in the third-level cache only once when every 273 orders are matched, even in the third-level cache, the access time delay is ten times faster than the prior scheme.
2. The matching efficiency is greatly improved, so that the system has higher order processing throughput and lower time delay.
3. The hierarchical memory pool which is particularly optimized according to the natural rule of order distribution is realized, namely, the hierarchical memory pool has a large order memory pool, and simultaneously, the hierarchical memory pool follows the design idea of mechanical sympathy and the order on each gear is compatible with the CPU cache as far as possible. Compared with the memory pool of the fixed size order configured before the system is started, the memory pool supporting the dynamic expansion order can dynamically support more orders and deal with the burst security statement amount.
Drawings
FIG. 1 is a schematic flow chart of the process of the present invention 1;
FIG. 2 is a schematic flow chart of the process of the present invention 2
Detailed Description
The present invention will be further described with reference to the accompanying drawings, the principles of which will be apparent to those skilled in the art. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Referring to fig. 1: the figures referred to by the numbers have the following meanings: 1. the order book structure comprises 2 a purchase and sale price gear set contained in the order book, 3 an order block internal storage pool specific to the order book, 4 a buyer price gear set, 5 a buyer price gear set, 6 a single block internal storage pool structure, 7 a price gear bidirectional linked list, 8 a residual non-transaction report quantity of all orders from the purchase and sale direction, and 9 a bidirectional linked list consisting of all unallocated order blocks in the internal storage pool.
Referring to fig. 2: the figures referred to by the numbers have the following meanings: 6. the method comprises the steps of ordering a block memory pool structure, 9, a doubly linked list of all unallocated order blocks in the memory pool, 10, an unallocated order block structure in the memory pool 11, a doubly linked list element for linking the order block, including a pointer to a previous linked list element of the element, a pointer to a next linked list element, 12, a pointer for saving a price position when the order block is allocated to a price position in the future, 13, recording how many orders have been allocated from a 15. technorders array by the value when the order is allocated from the order block, 14, the unallocated order structure on the order block is in a subscript position in the 15. technorders array, the allocation is started from the position next time, and recording all orders which can be allocated to the price position on the order block.
The TechOrder memory allocation method comprises the following steps:
the allocation of the memory is respectively carried out according to the isolation of a single stock; each order for a stock in the same price tier is allocated sequentially from a series of micro-memory pools (orderChunk) as shown in fig. 2, the size of which is the size of the CPU level cache. Based on the order size and the size of the CPU level cache described in the background, we can calculate the number of orders that an orderChunk can allocate (denoted as orderprecchunk) as follows: OrderPreChunk 32 KB/120B.
OrderPreChunk equals approximately 273 orders, number group size OrderPreChunk in element number 15 in FIG. 2.
When an orderChunk is fully allocated, the system will allocate a new orderChunk from a respective order block memory pool (denoted orderChunkPool) owned by each stock for subsequent new order allocation, as shown in FIG. 1.
Existing systems have an average of approximately thirty thousand orders per stock per day, and the memory size (Mempool) of a single orderChunkPool can be calculated as follows: the Mempool is 30000 × 120B, and 3.42MB, which may fall completely within the CPU level three buffer range.
The number of orderChunks (denoted orderChunkCountpool) that need to be pre-assigned to a single orderChunkPool at system start-up can be calculated as: orderChunkCountpool 30000/OrderPreChunk.
orderChunkCountpool equals 109, and in addition to the pre-allocation at startup, the system will dynamically allocate new orderChunk to add to orderChunkpool for management at runtime according to the order growth.
The first embodiment is as follows: each stock has an OrderChunkPool, which is the order block memory pool, and the unit of management is OrderChunk; OrderChunk is a local order memory pool, and the unit of management is each free order Slot, or Slot, for allocation to individual orders.
Allocating a block of memory to NewOrder is an attempt to allocate from the Slot that has been linked to be free in the OrderChunk at the corresponding price position, where there is no OrderChunk with a free Slot, and we will chain the free OrderChunk from the OrderChunk of this stock into this price position OrderChunk list and allocate the free Slot to NewOrder from above this new OrderChunk.
OrderChunk uses a way of allocating a large block of memory in the pre-allocation stage, and cutting the block of memory into OrderChunk blocks, so that the blocks of memory are also limited to a certain range of memory addresses. And the method is compatible with the third-level and fourth-level caches of the CPU as much as possible.
Example two: the order memory allocation method is implemented in the first-stage project of the upgrade construction of the Shanghai securities exchange-exchange system, and the performance improvement is achieved, the source code is located in an internal code warehouse address GTS/order book.git, the main logic is realized in order _ chunk.go, and the following is a part of the source code of order _ chunk.go:
Figure BDA0002266734090000071
Figure BDA0002266734090000081
Figure BDA0002266734090000091

Claims (5)

1. an order memory allocation method suitable for a security trading system is characterized by comprising the following steps:
s1: the allocation of the memory is respectively carried out according to the isolation of single stock, and the orders of each stock with the same price gear are sequentially allocated from a series of micro memory pools;
s2, when a micro memory pool is fully allocated, the system allocates a new memory pool from a order block memory pool owned by each stock for subsequent new order allocation;
s3: when a system is started, a memory pool which is allocated to a single block memory pool needs to be preset;
and S4, in addition to the pre-allocation during starting, the system dynamically allocates a new memory pool to be added into the memory pool of the order block for management according to the growing condition of the order during running.
2. A method as claimed in claim 1, wherein the size of said micro memory pool is the size of said CPU level buffer.
3. A method as claimed in claim 1, wherein the memory size of a single order block memory pool falls completely within the CPU level three cache range.
4. A method of allocating order memory for a security trading system as claimed in claim 1, wherein each stock has an order block memory pool, the unit of management is a local order memory pool, each free order slot of the local order memory pool is used for allocating to an individual order.
5. The method as claimed in claim 4, wherein said method comprises the following steps: allocating a block of memory to a new order is to try to allocate from the free order slot in the local order memory pool linked to the corresponding price position, and when there is no local order memory pool containing a free order slot in this position, the free memory pool is taken from the order block memory pool of this stock to be linked into the price position memory pool list, and the free order slot is taken from the new memory pool to be allocated to the new order.
CN201911090592.XA 2019-11-09 2019-11-09 Order memory allocation method suitable for securities trading system Active CN110928680B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911090592.XA CN110928680B (en) 2019-11-09 2019-11-09 Order memory allocation method suitable for securities trading system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911090592.XA CN110928680B (en) 2019-11-09 2019-11-09 Order memory allocation method suitable for securities trading system

Publications (2)

Publication Number Publication Date
CN110928680A true CN110928680A (en) 2020-03-27
CN110928680B CN110928680B (en) 2023-09-12

Family

ID=69853661

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911090592.XA Active CN110928680B (en) 2019-11-09 2019-11-09 Order memory allocation method suitable for securities trading system

Country Status (1)

Country Link
CN (1) CN110928680B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114037506A (en) * 2021-10-21 2022-02-11 深圳市道旅旅游科技股份有限公司 Work order distribution method, device, equipment and medium

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1722106A (en) * 2004-07-13 2006-01-18 中兴通讯股份有限公司 Method for internal memory allocation in the embedded real-time operation system
US20070288526A1 (en) * 2006-06-08 2007-12-13 Emc Corporation Method and apparatus for processing a database replica
CN102253897A (en) * 2011-07-26 2011-11-23 大唐移动通信设备有限公司 Method and device for managing memory pool
CN102915276A (en) * 2012-09-25 2013-02-06 武汉邮电科学研究院 Memory control method for embedded systems
CN103176911A (en) * 2011-12-20 2013-06-26 陕西银河网电科技有限公司 Embedded type software security memory management method
CN103810115A (en) * 2012-11-15 2014-05-21 深圳市腾讯计算机系统有限公司 Management method and device of memory pool
CN105094997A (en) * 2015-09-10 2015-11-25 重庆邮电大学 Method and system for sharing physical memory among cloud computing host nodes
CN105302738A (en) * 2015-12-09 2016-02-03 北京东土科技股份有限公司 Method and device for distributing memory
CN106681842A (en) * 2017-01-18 2017-05-17 迈普通信技术股份有限公司 Management method and device for sharing memory in multi-process system
CN108132842A (en) * 2017-12-15 2018-06-08 天津津航计算技术研究所 A kind of embedded software internal storage management system
CN110264353A (en) * 2019-05-28 2019-09-20 必成汇(成都)科技有限公司 High Availabitity trade match system memory-based and method

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1722106A (en) * 2004-07-13 2006-01-18 中兴通讯股份有限公司 Method for internal memory allocation in the embedded real-time operation system
US20070288526A1 (en) * 2006-06-08 2007-12-13 Emc Corporation Method and apparatus for processing a database replica
CN102253897A (en) * 2011-07-26 2011-11-23 大唐移动通信设备有限公司 Method and device for managing memory pool
CN103176911A (en) * 2011-12-20 2013-06-26 陕西银河网电科技有限公司 Embedded type software security memory management method
CN102915276A (en) * 2012-09-25 2013-02-06 武汉邮电科学研究院 Memory control method for embedded systems
CN103810115A (en) * 2012-11-15 2014-05-21 深圳市腾讯计算机系统有限公司 Management method and device of memory pool
CN105094997A (en) * 2015-09-10 2015-11-25 重庆邮电大学 Method and system for sharing physical memory among cloud computing host nodes
CN105302738A (en) * 2015-12-09 2016-02-03 北京东土科技股份有限公司 Method and device for distributing memory
CN106681842A (en) * 2017-01-18 2017-05-17 迈普通信技术股份有限公司 Management method and device for sharing memory in multi-process system
CN108132842A (en) * 2017-12-15 2018-06-08 天津津航计算技术研究所 A kind of embedded software internal storage management system
CN110264353A (en) * 2019-05-28 2019-09-20 必成汇(成都)科技有限公司 High Availabitity trade match system memory-based and method

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
JAEYOUNG DO JAEYOUNG DO UNIVERSITY OF WISCONSIN-MADISON, MADISON, WI, USA VIEW PROFILE: "Turbocharging DBMS buffer pool using SSDs", PROCEEDINGS OF THE 2011 ACM SIGMOD INTERNATIONAL CONFERENCE ON MANAGEMENT OF DATA *
刘翔;童薇;刘景宁;冯丹;陈劲龙;: "动态内存分配器研究综述", no. 10 *
姚金成;张世栋;史玉良;李庆忠;: "基于Chunk Folding的多租户数据库缓存管理机制" *
笑笑东风: "Buffer Poll基础知识", pages 1 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114037506A (en) * 2021-10-21 2022-02-11 深圳市道旅旅游科技股份有限公司 Work order distribution method, device, equipment and medium

Also Published As

Publication number Publication date
CN110928680B (en) 2023-09-12

Similar Documents

Publication Publication Date Title
US10303596B2 (en) Read-write control method for memory, and corresponding memory and server
TW457427B (en) Method and system for dynamically partitioning a shared cache
CN100375067C (en) Local space shared memory method of heterogeneous multi-kernel microprocessor
US4707784A (en) Prioritized secondary use of a cache with simultaneous access
CN101382953B (en) Interface system for accessing file system in user space and file reading and writing method
US6088705A (en) Method and apparatus for loading data into a database in a multiprocessor environment
US9189389B2 (en) Memory controller and memory system
US20070156997A1 (en) Memory allocation
EP1808779B1 (en) Bundling database
US6742078B1 (en) Management, data link structure and calculating method for flash memory
CN101986649B (en) Shared data center used in telecommunication industry billing system
EP0032956B1 (en) Data processing system utilizing hierarchical memory
US6381686B1 (en) Parallel processor comprising multiple sub-banks to which access requests are bypassed from a request queue when corresponding page faults are generated
CN101369245A (en) System and method for implementing a memory defect map
CN112598517B (en) Electronic commerce transaction matching method and system for large-scale concurrent requests
CN106775462A (en) A kind of method and apparatus that memory copying is reduced during read-write
CN101661437A (en) By-pass conversion buffer as well as method and device for matching addresses in same
CN110928680A (en) Order memory allocation method suitable for security trading system
US20090150642A1 (en) Indexing Page Attributes
CN104182359A (en) Buffer allocation method and device thereof
US6704753B1 (en) Method of storage management in document databases
KR100288680B1 (en) Method of controlling memory and apparatus of controlling the same
Simons Cheap computers bridge digital divide
JPS601670B2 (en) Processing data transmission method
JP2913591B2 (en) How to get an online journal

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant