CN101282300A - Method for processing HTTP packet based on non-blockage mechanism - Google Patents

Method for processing HTTP packet based on non-blockage mechanism Download PDF

Info

Publication number
CN101282300A
CN101282300A CNA2008101012439A CN200810101243A CN101282300A CN 101282300 A CN101282300 A CN 101282300A CN A2008101012439 A CNA2008101012439 A CN A2008101012439A CN 200810101243 A CN200810101243 A CN 200810101243A CN 101282300 A CN101282300 A CN 101282300A
Authority
CN
China
Prior art keywords
message
http
data buffering
data
thread
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
CNA2008101012439A
Other languages
Chinese (zh)
Other versions
CN101282300B (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.)
Beihang University
Beijing University of Aeronautics and Astronautics
Original Assignee
Beihang University
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 Beihang University filed Critical Beihang University
Priority to CN2008101012439A priority Critical patent/CN101282300B/en
Publication of CN101282300A publication Critical patent/CN101282300A/en
Application granted granted Critical
Publication of CN101282300B publication Critical patent/CN101282300B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

A method for processing HTTP message based on a non-blocking mechanism comprises: A) while reading incident is triggered, reading the HTTP message and storing to the data buffer; B) judging whether the message needs to analyze the message head, if positive, turning to C); otherwise turning to the D); C) judging whether the message head is reached completely, if positive, analyzing the message head; other turning to A); D) judging whether the message body is reached completely; if positive, analyzing the message body, other turning to the A); E) analysis is completed, recycling the data buffer to the data buffer pool. The invention mixes the advantages of the multi-thread and the incidents to achieve the true non-blocking mechanism in the process of HTTP message treatment, which makes the HTTP message reach the zero copy and a traversal so that the invention significantly enhances the processing efficiency of the HTTP message.

Description

A kind of HTTP message processing method based on non-blockage mechanism
Technical field
The present invention relates to a kind of HTTP message processing method based on non-blockage mechanism, mainly is to be used for the http server system.
Background technology
Large-scale http server must be handled concurrent request with the scale that can not expect.Concurrent network requests and large-scale offered load require to realize a concurrent performance height, the server system that scalability is strong.
At present, make up a high performance http server system, the most general mode has two kinds: based on the realization of multithread mode with based on event driven implementation.Based on the realization of multithread mode, though can solve wait that obstruction causes, effectively utilize system concurrency, shorten subscriber response time, thread is a kind of important system resource, the thread of distribution is many more, the expense of system is also just big more.For a given system, the thread that it can be supported has a threshold value, surpasses this threshold value, and its performance just has significantly and reduces.The way of a solution adopts thread pool exactly, so just can effectively save the overhead of thread creation, switching and recovery, yet, if in the face of large-scale offered load, obviously, the request that surpasses number of threads can only wait for, and system spends the time on thread scheduling can be greater than the time of network operation.
Based on event driven implementation, Reactor pattern and Non-Blocking I have effectively been utilized, when various IO incidents in a single day ready, just trigger application program and receive and do respective handling, dispose and return immediately, application program is no longer waited for the IO request, so just can simulate multi-thread concurrent with single thread.This method is referred to as traditional unblock method.Though it has avoided not having to utilize the concurrent ability of SMP (Symmetrical Multi-Processing) system's multiprocessor owing to the overhead that blocks the thread creation, switching and the recovery that cause.Simultaneously,, thereby increased the possibility of single point failure, also improved the complexity of programming accordingly because a thread need be handled all requests.
Effective way is the advantage in conjunction with multithreading and event-driven, designs a kind of model of mixing.This respect, Matt Welsh it high concurrent network frame SandStorm and use embodiment early arranged in the Haboob server.But he does not make full use of the characteristics of unblock, accomplishes zero-copy and traversal once as far as possible, and in certain sense, it is just based on the hybrid http server of Non-Blocking I.
Summary of the invention
The objective of the invention is: a kind of HTTP message processing method based on non-blockage mechanism is provided, this method stipulated in the http server as how the mode of unblock handle the HTTP message, thereby the effect that reaches zero-copy and once travel through is to improve the treatment effeciency of HTTP message greatly.
For achieving the above object, the present invention takes following technical scheme: its prerequisite is the threading model of setting up based on the http server of non-blockage mechanism, as shown in Figure 1, the threading model of this server comprises four assemblies, be the select thread, be responsible for intercepting the generation of various Non-Blocking I incidents and be responsible for and client connects; Thread pool, it is made up of a plurality of worker threads, and each worker thread includes an event queue, and it is task that each event queue is deposited polytype incident, has promptly mixed the advantage of multithreading and event-driven in realization; Connect---the thread mapping table, its key value is for connecting, and its value value is a thread, according to this mapping table, thereby makes all tasks of a connection carry out in a thread, thereby has avoided because the asynchronous mistake that causes; The data buffering pond is a data structure of depositing message, and it is made up of two data buffer chains, and one is the busy chain, the set of the data buffering that using of expression, and it two be the free chain, represents to have existed but the buffered collection that was not used at that time.Therefore, the data buffering pond is made up of a plurality of data bufferings, and each data buffering is only preserved the message of a connection in some moment, when the process message that reads the distribute data buffering disposes, this Buffer Pool reclaims corresponding data buffering, has avoided the expense of next reallocation and destruction.On this threading model basis, the processing procedure of a data message may further comprise the steps:
A, when reading Event triggered, read the HTTP message, it is deposited in the data buffering;
B, judging whether this message needs the analytic message head, is then to change C, otherwise changes D;
C, judge whether complete arrival of heading, be analytic message head then, otherwise change A;
D, judge the whether complete arrival of message body, be analytic message body then, otherwise change A;
E, parsing finish, and data buffering is recycled to the data buffering pond.
The present invention's advantage compared with prior art is: the present invention is by thread pool and event queue, mixed the advantage of multithreading and event-driven, by connecting---the mapping table of thread, the message that has guaranteed a connection reads, packet parsing, message response are finished in a thread, thereby lays a good foundation for the HTTP message processing method of unblock.In addition, the data buffering descriptor promptly points to the definition of pointer, parsing progress sign, m-position, p-position and the f-position of data buffering, make the HTTP message in the process of resolving, accomplish as far as possible zero-copy and once the traversal, realize real non-blockage mechanism, improved the treatment effeciency of HTTP message greatly.
Description of drawings
Fig. 1 is the http server threading model that the present invention is based on non-blockage mechanism.
Fig. 2 is the unblock processing method of HTTP message of the present invention;
Embodiment
Non-blockage mechanism disclosed by the invention, not only be meant in the process of transmitting that reads and respond of foundation, the data of request, no longer wait for the IO request to finish but directly return this be Non-Blocking I, the unblock method that also is included in the resolving of data is asynchronous analytical algorithm.
HTTP message processing method based on non-blockage mechanism disclosed by the invention is based on the threading model of http server based on non-blockage mechanism shown in Figure 1, and promptly http server is handled the process of HTTP message as non-blockage mechanism how.Select thread and traditional listener thread are different, it not only is used for intercepting generation such as accept, read, the write etc. of various Non-Blocking I incidents, and its also is responsible for and client connects and promptly handles the write incident of accept incident and part simultaneously.The same with Haboob, the advantage based on event driven Non-Blocking I and multithreading has been merged in the present invention, has designed a kind of compound model, and different is, each thread of the present invention all has an event queue, and can deposit polytype incident in this event queue.When it receives the read incident, be inserted into the event queue of worker thread, come reading of data by worker thread, data read finishes, if the work at present thread also switches, follows resolution data, otherwise generates the parsing incident, is inserted in the event queue.When a request analysis finishes, worker thread begins to construct its response message and sends, and in the process that sends, if data can't once send, so then needs to write incident to the registration of select thread, finishes remaining transmission work by the select thread.Therefore, the event queue safeguarded of worker thread can have the incident of three types of read, parse, response.Like this, the processing procedure of a connection is divided into different incidents and carries out, and such event definition is a task.Therefore, the present invention can come a plurality of connections of concurrent processing with a thread, and all tasks of a connection are then carried out in non-conterminous mode in event queue.In order to improve concurrency, the present invention has still adopted thread pool, the scheduling of thread must be according to connection---the mapping table of thread, and finish in a thread with the above-mentioned three types incident of guaranteeing a connection, thereby avoided because the asynchronous mistake that causes.
Reason owing to Non-Blocking I, the message that server end is once received might not be an intactly HTTP message, for the repeatedly copy of avoiding data and the overhead that repeatedly travels through as far as possible, the present invention preserves the data that read with the data buffering of big or small dynamic change, this data buffering derives from the data buffer zone, define three positions and a parsing progress sign simultaneously, three positions are m-position, p-position and f-position, write down the position of effectively having resolved, the end position of current position of resolving and current message segment respectively.As shown in Figure 2, disclosed by the invention based on non-blockage mechanism HTTP message processing method, specifically may further comprise the steps:
1, when reading Event triggered, reads the HTTP message, it is deposited in the data buffering;
2, judge whether this message needs the analytic message head, and being then changes 3, otherwise change 4;
3, judge whether complete arrival of heading, be analytic message head then, otherwise change 1;
4, judge the whether complete arrival of message body, be analytic message body then, otherwise change 1;
5, parsing finishes, and data buffering is recycled to the data buffering pond;
Below further describe.
1. in above-mentioned the 1st step, when reading Event triggered, the select thread obtains the incident of reading, and finishes reading of message data by worker thread, and is saved in the buffering.
The distribution method of data buffering is as follows:
A. if exist buffer joint in the free chain, then delete the tail of the queue node from the free chain, the tail of the queue at the busy chain adds a node simultaneously.
B. if do not have buffer joint in the free chain, then from current internal memory, obtain a data buffering, and add a node at the tail of the queue of busy chain.
The using method of data buffering is as follows:
A. when the message segment of a connection arrives for the first time, distribute the data buffering of an initial size, and initialization m-position, p-position and f-position position are 0;
C. if current buffering is large enough to hold this message segment, data are read in the data buffering, be attached in the buffering area that begins from f-position, reading the end position of revising current message segment that finishes is f-position;
D. if current buffering is held this message segment inadequately, then distribute the another one data buffering to form buffer chain,, change b to deposit remaining message segment;
E. data parsing finishes, and the data buffering chain is recycled in the data buffering pond.
Judge the processing progress of current request message, and call corresponding with it message processing method.
2. indicate according to the parsing progress and judge whether needs analytic message head of this HTTP message, also resolve to finish and then change step 3, finish, then change step 4 if parsing progress sign explicit message head has been resolved if the parsing progress indicates the explicit message head;
3, the processing method of heading
If the processing progress of current message shows the heading that also is untreated, then the processing procedure of heading is as follows:
If a. contain in the message "/r/n/r/n ", then heading reads completely, then carries out next step;
B. from buffering, read message;
If c. current character is the space, then the message between m-position and the p-position is taken out, it is kept in the analysis result, at last m-position is revised as p-position and returns b);
If d. m-position<=p-position, and p-position<=f-position repeats b, c operation, the request row in heading is resolved and is finished;
If e. current character is ": ", then the message between m-position and the p-position is taken out, it is saved among the name, simultaneously m-position is revised as p-position and returns b;
If f. current character is "/r/n ", then the message between m-position and the p-position is taken out, it is saved among the value, simultaneously with (name, value) attribute is revised as m-position p-position at last and returns b being saved among the header; Wherein the related name of step e and f is a variable of preserving heading attribute-name field, and value is the variable of preservation heading attribute value field, and header is the mapping table of name and value;
G. repeating b, e, f operation, is that the heading parsing finishes up to the next position of current character for "/r/n ", revises the parsing progress and indicates;
The HTTP mh is judged the processing progress of current request message, and calls corresponding with it message processing method.
4, the processing method of message body
If the processing progress of current message shows the message body that also is untreated, then the processing procedure of message body is as follows:
A. initialization p-position is m-position;
If the message segment b. between f-position and the p-position is less than the indicated length of Content-length, then heading is imperfect, and program is returned, otherwise carries out next step;
C. the message between p-position and the f-position is taken out, be saved in the analysis result, parsing finishes, and revises the parsing progress and indicates.
5, parsing finishes, and data buffering is recycled to the data buffering pond.Promptly delete the respective nodes in the busy chain, and the tail of the queue in the free chain adds a node.Therefore, there is message to read, when needing data buffering, can directly from the free chain, obtains, avoided repeatedly from the overhead of Memory Allocation the overhead of also having avoided internal memory to reclaim simultaneously when next time.

Claims (4)

1, a kind of HTTP message processing method based on non-blockage mechanism, it is characterized in that: prerequisite is the threading model of setting up based on the http server of non-blockage mechanism, the threading model of this server comprises four assemblies, be the select thread, be responsible for intercepting the generation of various Non-Blocking I incidents and be responsible for and client connects; Thread pool, it is made up of a plurality of worker threads, and each worker thread includes an event queue, and it is task that each event queue is deposited polytype incident; Connect---the thread mapping table, its key value is for connecting, and its value value is a thread, according to this mapping table, makes all tasks of a connection carry out in a thread; The data buffering pond is a data structure of depositing message, and it is made up of two data buffer chains, and one is the busy chain, the set of the data buffering that using of expression, and it two be the free chain, represents to have existed but the buffered collection that was not used at that time.Therefore, the data buffering pond is made up of a plurality of data bufferings, and each data buffering is only preserved the message of a connection in some moment, when the process message that reads the distribute data buffering disposes, this Buffer Pool reclaims corresponding data buffering, has avoided the expense of next reallocation and destruction; On this threading model basis, the processing procedure of a data message may further comprise the steps:
(1) when reading Event triggered, the select thread obtains the incident of reading, and finishes reading of HTTP message by worker thread, and is saved in the buffering;
(2) judge whether this HTTP message needs the analytic message head, be then to change step (3), otherwise change step (4);
(3) judge the whether complete arrival of this HTTP heading, be analytic message head then, otherwise change step (1);
(4) judge the whether complete arrival of this HTTP message body, be analytic message body then, otherwise change step (1);
(5) parsing finishes, and data buffering is recycled to the data buffering pond.
2, a kind of HTTP message processing method according to claim 1 based on non-blockage mechanism, it is characterized in that: the using method of the data buffering of described step (1) is as follows:
A. when the message segment of a connection arrives for the first time, the data buffering that distributes an initial size, and initialization m-position, p-position and f-position position are 0, m-position wherein, p-position and f-position have write down the end position of position, current position of resolving and the current message segment of effectively having resolved respectively;
B. if current buffering is large enough to hold this message segment, data are read in the data buffering, be attached in the buffering area that begins from f-position, reading the end position of revising current message segment that finishes is f-position;
C. if current buffering is held this message segment inadequately, then distribute the another one data buffering to form buffer chain,, change step b to deposit remaining message segment;
D. packet parsing finishes, and the data buffering chain is recycled in the data buffering pond.
3, a kind of HTTP message processing method based on non-blockage mechanism according to claim 1 is characterized in that: the processing procedure of heading is as follows in the described step (3):
If a. contain in the message "/r/n/r/n ", then heading reads completely, then carries out next step;
B. from buffering, read message;
If c. current character is the space, then the message between m-position and the p-position is taken out, it is kept in the analysis result, at last m-position is revised as p-position and returns b; M-position wherein, p-position and f-position have write down the end position of position, current position of resolving and the current message segment of effectively having resolved respectively;
If d. m-position<=p-position, and p-position<=f-position repeats step b, c operation, the request row in heading is resolved and is finished;
If e. current character is ": ", then the message between m-position and the p-position is taken out, it is saved among the name, simultaneously m-position is revised as p-position and returns b;
If f. current character is "/r/n ", then the message between m-position and the p-position is taken out, it is saved among the value, simultaneously with name and value attribute to being saved among the header, at last m-position is revised as p-position and returns b; Wherein the related name of step e and f is a variable of preserving heading attribute-name field, and value is the variable of preservation heading attribute value field, and header is the mapping table of name and value;
G. repeating b, e, f operation, is that the heading parsing finishes up to the next position of current character for "/r/n ", revises the parsing progress and indicates.
4, a kind of HTTP message processing method based on non-blockage mechanism according to claim 1 is characterized in that: the processing procedure of message body is as follows in the described step (4):
A. initialization p-position is m-position;
If the message segment b. between f-position and the p-position is less than the indicated length of Content-length (the heading attribute of indication message body length in the http protocol), then heading is imperfect, then returns, otherwise carries out next step;
C. the message between p-position and the f-position is taken out, be saved in the analysis result, parsing finishes, and revises the parsing progress and indicates.
CN2008101012439A 2008-03-03 2008-03-03 Method for processing HTTP packet based on non-blockage mechanism Expired - Fee Related CN101282300B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2008101012439A CN101282300B (en) 2008-03-03 2008-03-03 Method for processing HTTP packet based on non-blockage mechanism

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2008101012439A CN101282300B (en) 2008-03-03 2008-03-03 Method for processing HTTP packet based on non-blockage mechanism

Publications (2)

Publication Number Publication Date
CN101282300A true CN101282300A (en) 2008-10-08
CN101282300B CN101282300B (en) 2010-12-08

Family

ID=40014583

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2008101012439A Expired - Fee Related CN101282300B (en) 2008-03-03 2008-03-03 Method for processing HTTP packet based on non-blockage mechanism

Country Status (1)

Country Link
CN (1) CN101282300B (en)

Cited By (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102075583A (en) * 2011-01-30 2011-05-25 杭州华三通信技术有限公司 HTTP request message processing method and equipment
CN101714991B (en) * 2009-10-30 2012-06-20 清华大学 Method for realizing heartbeat mechanism
CN103327128A (en) * 2013-07-23 2013-09-25 百度在线网络技术(北京)有限公司 Intermediate data transmission method and system for MapReduce
CN103513990A (en) * 2013-10-11 2014-01-15 安徽科大讯飞信息科技股份有限公司 Method for designing high-performance generally-used network framework for distributed processing
CN104506490A (en) * 2014-11-27 2015-04-08 北京极科极客科技有限公司 Agent method and device under router kernel
CN104796395A (en) * 2014-06-11 2015-07-22 合肥星服信息科技有限责任公司 Processing method for instant large-scale network connection
CN105991676A (en) * 2015-01-30 2016-10-05 阿里巴巴集团控股有限公司 Data acquiring method and data acquiring device
CN108631947A (en) * 2018-05-21 2018-10-09 南京大学 A kind of RDMA network data transmission methods based on correcting and eleting codes
CN112003767A (en) * 2020-08-14 2020-11-27 上海许继电气有限公司 Method for sending simulation message
CN114827035A (en) * 2022-05-05 2022-07-29 浪潮通信信息系统有限公司 Network element communication method, device and computer medium
CN116962512A (en) * 2023-09-20 2023-10-27 北京信安世纪科技股份有限公司 Message processing method, device, storage medium and apparatus

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1183725C (en) * 2003-03-28 2005-01-05 港湾网络有限公司 Broadband communication data transmission method
CN1997030A (en) * 2006-12-13 2007-07-11 武汉虹旭信息技术有限责任公司 Method for HTTP data recovery

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101714991B (en) * 2009-10-30 2012-06-20 清华大学 Method for realizing heartbeat mechanism
CN102075583A (en) * 2011-01-30 2011-05-25 杭州华三通信技术有限公司 HTTP request message processing method and equipment
CN103327128A (en) * 2013-07-23 2013-09-25 百度在线网络技术(北京)有限公司 Intermediate data transmission method and system for MapReduce
CN103513990B (en) * 2013-10-11 2017-01-25 科大讯飞股份有限公司 Method for designing high-performance generally-used network framework for distributed processing
CN103513990A (en) * 2013-10-11 2014-01-15 安徽科大讯飞信息科技股份有限公司 Method for designing high-performance generally-used network framework for distributed processing
CN104796395A (en) * 2014-06-11 2015-07-22 合肥星服信息科技有限责任公司 Processing method for instant large-scale network connection
CN104506490A (en) * 2014-11-27 2015-04-08 北京极科极客科技有限公司 Agent method and device under router kernel
CN105991676A (en) * 2015-01-30 2016-10-05 阿里巴巴集团控股有限公司 Data acquiring method and data acquiring device
CN105991676B (en) * 2015-01-30 2019-04-09 阿里巴巴集团控股有限公司 The acquisition methods and device of data
CN108631947A (en) * 2018-05-21 2018-10-09 南京大学 A kind of RDMA network data transmission methods based on correcting and eleting codes
CN112003767A (en) * 2020-08-14 2020-11-27 上海许继电气有限公司 Method for sending simulation message
CN114827035A (en) * 2022-05-05 2022-07-29 浪潮通信信息系统有限公司 Network element communication method, device and computer medium
CN116962512A (en) * 2023-09-20 2023-10-27 北京信安世纪科技股份有限公司 Message processing method, device, storage medium and apparatus
CN116962512B (en) * 2023-09-20 2024-01-05 北京信安世纪科技股份有限公司 Message processing method, device, storage medium and apparatus

Also Published As

Publication number Publication date
CN101282300B (en) 2010-12-08

Similar Documents

Publication Publication Date Title
CN101282300B (en) Method for processing HTTP packet based on non-blockage mechanism
DE60030767T2 (en) DATA ALLOCATION TO THREADS IN A MULTI-THREADED NETWORK PROCESSOR
Larson et al. Memory allocation for long-running server applications
CA2517156C (en) System and method for dynamic ordering in a network processor
US20120117075A1 (en) Systems and methods for grouped request execution
DE112012003961T5 (en) Simultaneous processing of queued messages
CN110908788A (en) Spark Streaming based data processing method and device, computer equipment and storage medium
CN106454354B (en) A kind of AVS2 parallel encoding processing system and method
DE102012210895A1 (en) Predicting the unordered parallel processing of thread instructions in a multithreaded processor
JP4000223B2 (en) Information search method, information search system, and search management apparatus for the system
CN110995678A (en) Industrial control network-oriented efficient intrusion detection system
CN109711323A (en) A kind of live video stream analysis accelerated method, device and equipment
CN1898647A (en) Processing architecture having passive threads and active semaphores
Li et al. {MilliSort} and {MilliQuery}:{Large-Scale}{Data-Intensive} Computing in Milliseconds
CN111416858B (en) Media resource processing platform, method, device and server
CN113342839A (en) Data processing method and device, terminal equipment and storage medium
CN112613276A (en) Parallel execution method and system for streaming document analysis
Denis Scalability of the NewMadeleine communication library for large numbers of MPI point-to-point requests
EP1214652A2 (en) Efficient event waiting
CN111131243B (en) DPI system strategy processing method and device
Johnson et al. A comparison of fast and low overhead distributed priority locks
Lu et al. Performance characterization and acceleration of big data workloads on OpenPOWER system
CN114756629A (en) Multi-source heterogeneous data interaction analysis engine and method based on SQL
CN113778674A (en) Lock-free implementation method of load balancing equipment configuration management under multi-core
CN110647357B (en) Synchronous multithread processor

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
C17 Cessation of patent right
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20101208

Termination date: 20140303