CN110062035A - A kind of http request method and apparatus based on deque - Google Patents
A kind of http request method and apparatus based on deque Download PDFInfo
- Publication number
- CN110062035A CN110062035A CN201910260637.7A CN201910260637A CN110062035A CN 110062035 A CN110062035 A CN 110062035A CN 201910260637 A CN201910260637 A CN 201910260637A CN 110062035 A CN110062035 A CN 110062035A
- Authority
- CN
- China
- Prior art keywords
- data
- round
- robin queue
- http request
- queue
- 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.)
- Pending
Links
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/02—Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/50—Network services
- H04L67/56—Provisioning of proxy services
- H04L67/568—Storing data temporarily at an intermediate stage, e.g. caching
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer And Data Communications (AREA)
Abstract
The present invention provides a kind of http request method and apparatus based on deque, wherein, the http request method based on deque, includes the following steps: the SDK interface of application layer call operation systemic presupposition, and http request data are passed in pending round-robin queue by the SDK interface;Start execution thread, take out the http request data in pending round-robin queue and http request is sent to server by third party's network request tool;The response data for receiving server feedback, response data is passed in round-robin queue to be returned, and starting returns to thread, and response data is taken out from the round-robin queue to be returned and returns to the response data to application layer.Http request efficiency can be improved in the present invention, makes client end response more smooth rapidly.
Description
Technical field
The present invention relates to network communication technology field, especially a kind of http request method and apparatus based on deque.
Background technique
In software communication field, client and background service need to interact by network request, and front end applications need
Client is presented to from background service acquisition data and uploads data to backstage and carries out data processing, is realized in this way
Data transmitting is offering customers service.
The interface of client docking background server is usually packaged into SDK packet, reuses there is no need to application end and respectively puts down
The HTTP facility of platform separately is requested, and application developer carries out interface calling according to SDK document and interacts with background service.But
It is that SDK interface provided by client is often obstructive type, is easy to cause response stuck when encountering consuming task, influences
User experience.
Summary of the invention
The present invention provides a kind of http request method and apparatus based on deque, and http request efficiency can be improved, allow
Client end response is more smooth rapidly.
According to the first aspect of the invention, the present invention provides a kind of http request method based on deque, including as follows
Step: http request data are passed to pending by the SDK interface of application layer call operation systemic presupposition by the SDK interface
In round-robin queue;Start execution thread, takes out the http request data in pending round-robin queue and asked by third party's network
Tool is asked to send http request to server;The response data for receiving server feedback, is passed to circulation to be returned for response data
In queue, starting return thread, response data is taken out from the round-robin queue to be returned and return the response data to
Application layer.
Preferably, before http request data are passed to pending round-robin queue by the SDK interface, for it is described to
Execute round-robin queue's application caching;It is the round-robin queue to be returned before response data is passed to round-robin queue to be returned
Application caching.
Preferably, data are packaged using preset property when application queue is buffered, and use preset property logarithm
According to progress memory alignment.
Preferably, it data incoming and is taken out according to default in the pending round-robin queue and round-robin queue to be returned
Sequence carry out.
It preferably, further include following steps before the SDK interface of the application layer call operation systemic presupposition: to institute
It states SDK interface and carries out initial configuration.
Preferably, third party's network request tool is curl tool.
According to the second aspect of the invention, the present invention provides a kind of http request device based on deque, comprising: interface
Calling module, it is by the SDK interface that http request data are incoming wait hold for the SDK interface of call operation systemic presupposition
In row round-robin queue;Request sending module takes out the data in pending round-robin queue and by for starting execution thread
Triple net requests tool to send http request to server;Data return module, for receiving the number of responses of server feedback
According to response data being passed in round-robin queue to be returned, starting returns to thread, by response data from the round-robin queue to be returned
Middle taking-up simultaneously returns to the response data to application layer.
It preferably, further include executing Queue module, for by the SDK interface that http request data are incoming wait hold
Before row round-robin queue, for pending round-robin queue's application caching;It further include returning to Queue module, for by number of responses
According to before being passed to round-robin queue to be returned, cached for round-robin queue's application to be returned.
It preferably, further include data processing module, for being carried out using preset property to data in application queue buffering
Encapsulation, and memory alignment is carried out to data using preset property.
Preferably, it data incoming and is taken out according to default in the pending round-robin queue and round-robin queue to be returned
Sequence carry out.
In the present invention, is stored since Liang Ge round-robin queue is respectively adopted and execute data and returned data, and respectively by two
A thread executes operation, carries out asynchronous call without application end, substantially increases the efficiency for receiving request and returned data, allow and answer
More smooth rapidly with end response, the user experience is improved.
Detailed description of the invention
Fig. 1 is the flow chart of the http request method based on deque of an embodiment of the present invention;
Fig. 2 is the structural schematic diagram of the http request device based on deque of an embodiment of the present invention.
Specific embodiment
Below by specific embodiment combination attached drawing, invention is further described in detail.
The embodiment of the present invention provides a kind of http request method based on deque, and this method is applied to terminal device, eventually
End equipment specifically can be mobile phone, PC, tablet computer and wearable device etc., as shown in Figure 1, this method specifically includes
Following steps:
S101: the SDK interface of application layer call operation systemic presupposition, the third party APP that specifically can be in application layer are answered
It is gone to call the SDK interface with program, http request data is passed in pending round-robin queue by the SDK interface.
When user needs to request network data, operational order, operation of the application layer according to user can be issued in application layer
Instruction generates http request data, which will be passed to next layer.In general, http request data are believed comprising requesting party
The information such as breath, Requested Party information and request content.By taking browser as an example, the site link of user operates, page furbishing operates,
Page back operation etc. characterizes the network request demand of user, and browser can submit corresponding request data, generally comprise this
The data informations such as the ground address ip, Requested Party address.
Http request data call operating system preset SDK interface of the front end applications according to user, then pass through SDK interface
The http request data are passed in pending round-robin queue.The high level languages back office interface SDK such as C/C++ can be used,
The kit that backstage api interface is packaged into SDK, and is compiled into corresponding platform and can run is supplied to each platform and uses, due to
Interface has been dressed up into SDK packet, has not needed application end and reuse the HTTP facility of respective platform separately to be requested, has realized primary development one
Secondary test is used for multiple times, and improves the development efficiency of application end.For linux system, needed after the completion of coding in linux environment
The compilation tool of lower configuration related platform, and compile out corresponding library.
S201: starting execution thread takes out the data in pending round-robin queue and by third party's network request tool
Http request is sent to server.
After http request data are passed to pending round-robin queue, operating system will start preset execution thread,
Execution thread takes out http request data from pending round-robin queue, third party's network request tool is enabled, by third party
Http request data are packaged as request message by request tool, and request message includes that the address of Requested Party (specifically can be IP
Number, domain name, port numbers etc.), the information such as the application name, coded format, the attribute relevant to linking that issue request.Request
Message will be sent to the server of Requested Party, waiting for server feedback data, and specific request method can be GET request
Or POST request.
S301: receiving the response data of server feedback, and response data is passed in round-robin queue to be returned, and starting returns
Response data is taken out from the round-robin queue to be returned and returns to the response data to application layer by thread.
Execution thread will remain operational, the response data of waiting for server feedback.Terminal device is receiving server
After response data, execution thread is cached to operating system application queue, with the response data that service device is fed back, specifically,
Response data is passed in round-robin queue to be returned, wait-for-response data are further processed.Response data is with message shape
Formula is sent, and response message is mainly made of statusline, response head, response this three parts of text, and statusline indicates data response
State, response head then include the letters such as server application software information, the type for responding text, the length for responding text
Breath.Execution thread can monitor the response time, be greater than the predetermined time when the response time, characterize response data reception failure, then may be used
To retransmit http request data.Later, response data is continued waiting for, after receiving response data of the server to feedback, will be rung
Data are answered to be passed in round-robin queue to be returned.
After response data is passed to round-robin queue to be returned, execution thread terminates, and returns to thread starting, returning to thread will be to
The response data returned in round-robin queue is taken out and returns to corresponding data to application layer, to show requested number in front end applications
According to will show requested webpage information in browser by taking browser as an example.
In one embodiment, it during http request data are passed to pending round-robin queue and will respond
During data are passed to round-robin queue to be returned, preset property are respectively adopted, http request data and response data are carried out
Encapsulation.
Specifically, atomicity encapsulation can be carried out to data structure using the new features std::atomic of C++11, std::
Atomic<T>template class can make Object Operations atomic operation, avoid multithreading race problem, can using std::atomic
Realize designing without lock for data structure.For the data types such as bool, int, char can be encapsulated as atomic_bool,
The atomic data types such as atomic_int, atomic_char.
And memory alignment can be carried out to data using preset property, specifically, using the new of C++11 in encapsulation process
Characteristic std::aligned_storage is aligned memory size.Std::aligned_storage can regard a memory as to it
Buffer area, prototype is as follows:
Template<std::size_t Len, std::size_t Align=/* default-alignment*/>
struct aligned_storage;
Len indicates that the sie of institute's storage class, Align indicate the memory alignment size of the type.
Std::max_align_t is used to return the maximum default memory alignment type of current platform, and malloc is returned
Memory, alignment should be consistent with the alignment size of max_align_t type.It can be obtained by following mode current flat
The maximum default memory of platform is aligned number:
std::cout<<alignof(std::max_align_t)<<std::endl;
Std::align is used to obtain the address for meeting specified memory requirement in a bulk of memory.
Further, it data incoming and is taken out according to preset in pending round-robin queue and round-robin queue to be returned
Sequence carries out.Specifically can when into team and team out using preset property to the sequence of team is ranked up into team and out, guarantee institute
There is subsequent read operation that must could execute after the completion of single threading operation.In a specific embodiment, C can be used
++ 11 new features std::memory_order_acquire is configured.Std::memory_order will be specified conventional non-
How atom internal storage access surrounds atomic operation sequence, and the default behavior of all atomic operations provides sequence consistent sequence in library.
On the basis of the above embodiments, further include following steps before step S101: the SDK interface is carried out just
Beginningization configuration.Initial configuration includes the cache size for setting queue, callback method, domain name, printing rank, transport protocol etc.
Information.
Wherein, above-mentioned third party's network request tool can be curl tool, and curl is a kind of visitor for being detached from browser
Family end network communication tool supports the various protocols such as HTTP and HTTPS, has many advantages, such as that fast response time, compatibility are strong.
According to the second aspect of the invention, the present invention provides a kind of http request device based on deque, such as Fig. 2 institute
Show, comprising: interface calling module 11 is used for the preset SDK interface of calling system, is asked the http by the SDK interface
Data are asked to be passed in pending round-robin queue;Request sending module 21 takes out pending round-robin queue for starting execution thread
In data and by third party's network request tool to server send http request;Data return module 31, for receiving
Response data is passed in round-robin queue to be returned by the response data of server feedback, starting return thread, by response data from
It is taken out in the round-robin queue to be returned and returns to the response data to application layer.
In one embodiment, further include executing Queue module, for by the SDK interface by http request data
It is passed to before pending round-robin queue, for pending round-robin queue's application caching;Further include returning to Queue module, is used for
Before response data is passed to round-robin queue to be returned, for round-robin queue's application caching to be returned.
It in one embodiment, further include data processing module, for using preset property pair in application queue buffering
Data are packaged, and carry out memory alignment to data using preset property.
In one embodiment, it data incoming and is taken out equal in the pending round-robin queue and round-robin queue to be returned
It is carried out according to preset sequence.
In one embodiment, further include initial configuration module, be used for before the preset SDK interface of calling system, it is right
The SDK interface carries out initial configuration.
In one embodiment, above-mentioned third party's network request tool is curl tool.
The explanation of the embodiment of the above-mentioned http request device part based on deque, specifically can be with reference to based on deque
Http request method part embodiment, this will not be repeated here.
The above content is specific embodiment is combined, further detailed description of the invention, and it cannot be said that this hair
Bright specific implementation is only limited to these instructions.For those of ordinary skill in the art to which the present invention belongs, it is not taking off
Under the premise of from present inventive concept, a number of simple deductions or replacements can also be made.
Claims (10)
1. a kind of http request method based on deque, which comprises the steps of:
Http request data are passed to pending follow by the SDK interface by the SDK interface of application layer call operation systemic presupposition
In ring queue;
Start execution thread, take out the http request data in pending round-robin queue and by third party's network request tool to
Server sends http request;
The response data for receiving server feedback, response data is passed in round-robin queue to be returned, and starting returns to thread, will be rung
It answers data to take out from the round-robin queue to be returned and returns to the response data to application layer.
2. according to the method described in claim 1, it is characterized by:
It is the pending circulation team before http request data are passed to pending round-robin queue by the SDK interface
Column application caching;
Before response data is passed to round-robin queue to be returned, for round-robin queue's application caching to be returned.
3. according to the method described in claim 2, it is characterized by:
Data are packaged using preset property in application queue buffering, and memory pair is carried out to data using preset property
Together.
4. the method according to claim 1, wherein in the pending round-robin queue and round-robin queue to be returned
The incoming and taking-up of data is carried out according to preset sequence.
5. method according to claim 1-4, which is characterized in that in the application layer call operation systemic presupposition
SDK interface before, further include following steps:
Initial configuration is carried out to the SDK interface.
6. method according to claim 1-4, it is characterised in that:
Third party's network request tool is curl tool.
7. a kind of http request device based on deque characterized by comprising
Interface calling module, for the SDK interface of call operation systemic presupposition, by the SDK interface by http request data
It is passed in pending round-robin queue;
Request sending module takes out the data in pending round-robin queue and by third party's network for starting execution thread
Request tool sends http request to server;
Response data is passed in round-robin queue to be returned by data return module for receiving the response data of server feedback,
Starting returns to thread, and response data is taken out from the round-robin queue to be returned and returns to the response data to application layer.
8. device according to claim 7, it is characterised in that:
It further include executing Queue module, for http request data to be passed to pending round-robin queue by the SDK interface
It before, is pending round-robin queue's application caching;
Further include returning to Queue module, for before response data is passed to round-robin queue to be returned, to be returned is followed to be described
Ring queue application caching.
9. device according to claim 8, it is characterised in that:
Further include data processing module, for using preset property to be packaged data when application queue buffers, and uses
Preset property carries out memory alignment to data.
10. device according to claim 7, it is characterised in that:
The incoming and taking-up of data is carried out according to preset sequence in the pending round-robin queue and round-robin queue to be returned.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910260637.7A CN110062035A (en) | 2019-04-02 | 2019-04-02 | A kind of http request method and apparatus based on deque |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910260637.7A CN110062035A (en) | 2019-04-02 | 2019-04-02 | A kind of http request method and apparatus based on deque |
Publications (1)
Publication Number | Publication Date |
---|---|
CN110062035A true CN110062035A (en) | 2019-07-26 |
Family
ID=67318191
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910260637.7A Pending CN110062035A (en) | 2019-04-02 | 2019-04-02 | A kind of http request method and apparatus based on deque |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN110062035A (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110928604A (en) * | 2019-11-11 | 2020-03-27 | 北京天融信网络安全技术有限公司 | Password card asynchronous calling method based on lockless ring-shaped queue |
CN111711650A (en) * | 2020-04-17 | 2020-09-25 | 北京奇艺世纪科技有限公司 | Network request scheduling method, device, equipment and storage medium |
CN112291307A (en) * | 2020-10-12 | 2021-01-29 | 北京思明启创科技有限公司 | Data request processing method and device and electronic equipment |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102541659A (en) * | 2011-12-30 | 2012-07-04 | 重庆新媒农信科技有限公司 | Method and device for processing of server service requests |
CN103316472A (en) * | 2013-05-17 | 2013-09-25 | 南京睿悦信息技术有限公司 | Android device gas platform system based on Bluetooth handle and implementation method of Android device gas platform system |
CN104378221A (en) * | 2013-08-14 | 2015-02-25 | 沈阳中科博微自动化技术有限公司 | Asynchronous calling method applied to integrated circuit production line monitoring system |
CN107948204A (en) * | 2017-12-29 | 2018-04-20 | 咪咕文化科技有限公司 | One key login method and system, relevant device and computer-readable recording medium |
-
2019
- 2019-04-02 CN CN201910260637.7A patent/CN110062035A/en active Pending
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102541659A (en) * | 2011-12-30 | 2012-07-04 | 重庆新媒农信科技有限公司 | Method and device for processing of server service requests |
CN103316472A (en) * | 2013-05-17 | 2013-09-25 | 南京睿悦信息技术有限公司 | Android device gas platform system based on Bluetooth handle and implementation method of Android device gas platform system |
CN104378221A (en) * | 2013-08-14 | 2015-02-25 | 沈阳中科博微自动化技术有限公司 | Asynchronous calling method applied to integrated circuit production line monitoring system |
CN107948204A (en) * | 2017-12-29 | 2018-04-20 | 咪咕文化科技有限公司 | One key login method and system, relevant device and computer-readable recording medium |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110928604A (en) * | 2019-11-11 | 2020-03-27 | 北京天融信网络安全技术有限公司 | Password card asynchronous calling method based on lockless ring-shaped queue |
CN110928604B (en) * | 2019-11-11 | 2023-05-02 | 北京天融信网络安全技术有限公司 | Password card asynchronous calling method based on lock ring-free queue |
CN111711650A (en) * | 2020-04-17 | 2020-09-25 | 北京奇艺世纪科技有限公司 | Network request scheduling method, device, equipment and storage medium |
CN111711650B (en) * | 2020-04-17 | 2022-07-12 | 北京奇艺世纪科技有限公司 | Network request scheduling method, device, equipment and storage medium |
CN112291307A (en) * | 2020-10-12 | 2021-01-29 | 北京思明启创科技有限公司 | Data request processing method and device and electronic equipment |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110351342A (en) | Service order processing method, device, computer equipment and storage medium | |
US20200057658A1 (en) | Method and system for loading resources | |
EP3731161A1 (en) | Model application method and system, and model management method and server | |
US10218775B2 (en) | Methods for servicing web service requests using parallel agile web services and devices thereof | |
CN110062035A (en) | A kind of http request method and apparatus based on deque | |
EP2913767A1 (en) | Page processing method, apparatus and system | |
CN113360807B (en) | Page display method and device of mixed-mode mobile application and related equipment | |
EP2590071A1 (en) | Storage device including software development kit that supports multiple types of platforms and multiple programming languages | |
US7970814B2 (en) | Method and apparatus for providing a synchronous interface for an asynchronous service | |
CN108900627B (en) | Network request method, terminal device and storage medium | |
CN107862810A (en) | A kind of self-aided terminal control system based on browser | |
US20150188981A1 (en) | Page processing method, apparatus, and system | |
US20150200884A1 (en) | System and method for selecting a file stored on a cloud server | |
CN111859210B (en) | Image processing method, device, equipment and storage medium | |
CN111427899A (en) | Method, device, equipment and computer readable medium for storing file | |
CN103905484B (en) | Handle the method and device of hypertext transfer protocol requests | |
CN107317788A (en) | Real time data method for pushing and device | |
CN110807535A (en) | Construction method and construction device of unified reservation platform and unified reservation platform system | |
CN116781586A (en) | gRPC flow analysis method, device, equipment and medium | |
US8280950B2 (en) | Automatic client-server code generator | |
CN113760274B (en) | Front-end assembly logic injection method and device | |
CN113779122B (en) | Method and device for exporting data | |
CN111937366B (en) | Web request processing method and device | |
US10645196B1 (en) | Multicomponent software-controllable system and a method for interaction of server-client processes and a machine-readable carrier for performing the method | |
CN113791777A (en) | Picture display method and device, computer readable storage medium and electronic equipment |
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 | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20190726 |
|
RJ01 | Rejection of invention patent application after publication |