CN103795569A - Server connection method and device based on connection pool - Google Patents

Server connection method and device based on connection pool Download PDF

Info

Publication number
CN103795569A
CN103795569A CN201410030973.XA CN201410030973A CN103795569A CN 103795569 A CN103795569 A CN 103795569A CN 201410030973 A CN201410030973 A CN 201410030973A CN 103795569 A CN103795569 A CN 103795569A
Authority
CN
China
Prior art keywords
server
connection
connection example
operation system
management module
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
Application number
CN201410030973.XA
Other languages
Chinese (zh)
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.)
IZP (BEIJING) TECHNOLOGIES Co Ltd
Original Assignee
IZP (BEIJING) TECHNOLOGIES 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 IZP (BEIJING) TECHNOLOGIES Co Ltd filed Critical IZP (BEIJING) TECHNOLOGIES Co Ltd
Priority to CN201410030973.XA priority Critical patent/CN103795569A/en
Publication of CN103795569A publication Critical patent/CN103795569A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Computer And Data Communications (AREA)

Abstract

The invention provides a server connection method and device based on a connection pool. The connection method comprises the steps: monitoring each set of server in a server cluster in real time and acquiring on-line server information; receiving a request for establishing connection with the server, wherein the request is sent by a service system; selecting a strategy of selecting a server according to the request; selecting an on-line server according to the strategy and the on-line server information; judging whether an unoccupied connection example of the selected server is saved; if yes, directly selecting the connection example; if not, acquiring a new connection example, establishing connection with the selected on-line server, adding and connecting a corresponding socket handle to the new connection example, and selecting the connection example; returning the socket handle to the service system through a corresponding interface according to the request for establishing connection, and establishing connection of the service system and the selected server. By means of the server connection method and device based on the connection pool, a server resource can be reasonably utilized, and reliable connection can be established.

Description

A kind of server method of attachment and device based on connection pool
Technical field
The present invention relates to network communications technology field, particularly relate to a kind of server method of attachment and device based on connection pool.
Background technology
Internet industry data traffic is in continuous surge, and advertisement delivery system, receiving after large batch of User Page request, need to be carried out different advertisement serving policies to each user.For large request flow like this, advertisement delivery system need to reach fast, carry out data interaction at each intermodule reliably, just must realize based on TCP(Transmission Control Protocol, transmission control protocol) the network service of concurrent, the low delay of height.And this network service can realize by the pond that is integrated and connected in the modules in advertisement delivery system, provide fast connection by connection pool for data interaction, realize the network service of high concurrent, low delay.
The basic thought of connection pool is in the time that operation system is initialized, server is connected and is stored in connection pool as object, in the time that operation system need to connect with server, operation system does not need to set up new being connected with a certain server in server cluster, but from connection pool, takes out an idle connecting object of having set up.After finishing using, operation system is also not cancelled connection, but connection is put back in connection pool, uses for next request access.
And existing connection pool is in the time of design, just the server info of appointment is configured in connection pool, and has only considered the assignment problem of connection resource.Also just say so, store and being connected of configured server in the connection pool of operation system, in the time that operation system request connects, from connection pool, random connection of taking out a server, offers operation system by this connection.
Visible, adopt the existing server method of attachment based on connection pool in the time setting up being connected between operation system and server, the distribution of just simply carrying out connection resource offers operation system and connects, and in the time being configured to server in connection pool and going wrong, still the connection of the server going wrong can be offered to operation system, cannot guarantee the reliability connecting.Simultaneously, the existing this method connecting can not be distributed connection in conjunction with the present situation of each server, be random fech connection from connection pool, the server of the connection correspondence of selective extraction offers operation system, can not reasonably utilize server resource.
Summary of the invention
The invention provides a kind of server method of attachment and device based on connection pool, the poor problem of connection reliability that cannot reasonably utilize server resource and be set up to solve existing method of attachment.
In order to address the above problem, the invention discloses a kind of server method of attachment based on connection pool, comprising: the each station server in monitoring server cluster in real time, obtains line server information; Receive the request connecting with server that operation system sends; The request connecting described in foundation, selects a strategy of selecting server; According to described strategy and line server of described line server Information Selection; Judge whether to preserve the unappropriated connection example of selected line server; If preserved described connection example, directly select described connection example, wherein, saved each described connection example is to there being socket handle; If do not preserve described connection example, obtain a new connection example, set up and being connected of selected line server by described new connection example, add extremely described new connection example of socket handle corresponding to described connection; The new connection example of described socket handle has been added in selection; For the described request connecting, socket handle corresponding selected connection example is returned to described operation system by corresponding interface, set up being connected of described operation system and selected line server according to described socket handle.
Preferably, each station server in described real-time monitoring server cluster, after obtaining line server information step, also comprise: whether can use according to setting each line server of rule detection, delete the server info that disabled line server is corresponding.
Preferably, described server info comprises: central processing unit load, free memory; The request connecting described in described foundation, select one to select the strategy step of server to comprise: according to described in the request that connects, select the strategy of the server of a selection central processing unit least-loaded, free memory maximum; The step of the described strategy of described foundation and a line server of described line server Information Selection comprises: according to one of described strategy and described line server Information Selection online and the server of central processing unit least-loaded, free memory maximum.
Preferably, described in, judge whether that the unappropriated connection case step of having preserved selected line server comprises: the connection example that has judged whether to preserve selected line server; If preserved described connection example, further judge whether described connection example is connected and takies by other that set up with described operation system; If described connection example is unoccupied, judged result is to have preserved the unappropriated connection example of selected line server.
Preferably, each station server in described real-time monitoring server cluster, before obtaining line server information step, also comprise: receive the long connection of described operation system input or the link order of short connection, the connection of setting up respective type according to described link order.
Preferably, after the described socket handle of described foundation is set up the Connection Step of described operation system and selected line server, also comprise: in the time disconnecting with being connected of selected line server, delete the socket handle in described selected connection example, obtain a new connection example.
In order to address the above problem, the invention also discloses a kind of server jockey based on connection pool, comprising: cluster monitoring module, for each station server of real-time monitoring server cluster, obtain line server information; Connection management module, the request connecting with server sending for receiving operation system; Policy management module, for the request connecting described in foundation, selects a strategy of selecting server; Cluster management module, for the described strategy of foundation and line server of described line server Information Selection; Described cluster management module, also for judging whether to have preserved the unappropriated connection example of selected line server; If preserved described connection example, directly select described connection example, wherein, saved each described connection example is to there being socket handle; If do not preserve described connection example, obtain a new connection example, set up and being connected of selected line server by described new connection example, add extremely described new connection example of socket handle corresponding to described connection; The new connection example of described socket handle has been added in selection; Described connection management module, also for for the described request connecting, socket handle corresponding selected connection example being returned to described operation system by corresponding interface, set up being connected of described operation system and selected line server according to described socket handle.
Preferably, server jockey based on connection pool also comprises: health detection module, for after described cluster monitoring module is obtained line server information, whether can use according to setting each online server of rule detection, delete the server info that disabled line server is corresponding.
Preferably, described server info comprises: central processing unit load, free memory; Described policy management module according to described in the request that connects, while selecting one to select server tactful: the request connecting described in foundation, select the strategy of the server of a selection central processing unit least-loaded, free memory maximum; Described cluster management module is according to described strategy during with a line server of described line server Information Selection: according to one of described strategy and the selection of described online server info online and the server of central processing unit least-loaded, free memory maximum.
Preferably, described cluster management module, also for the each station server at the real-time monitoring server of described cluster monitoring module, before obtaining line server information, receive the long connection of described operation system input or the link order of short connection, the connection of setting up respective type according to described link order; Described cluster management module, also for set up being connected of described operation system and described line server in described connection management module after, in the time disconnecting with being connected of described online server, the socket handle of deleting in described selected connection example obtains a new connection example, and the described new connection example obtaining is returned to described connection management module; Described connection management module, the described new connection example of also giving back for receiving described cluster management module.
Compared with prior art, the present invention has the following advantages:
Server connection scheme based on connection pool provided by the invention, monitoring server cluster in real time, and obtain the information of line server, then from online server, select a server and operation system to connect, the server that has guaranteed to offer operation system is all online, avoid in existing connection scheme, the server going wrong being offered the problem of operation system, and then guaranteed the reliability connecting.The scheme connecting provided by the invention, the server connecting according to selection strategy and line server Information Selection and operation system, can connect task according to the present situation reasonable distribution of each online server, that has avoided existing in existing connected mode distributes to same station server by multiple connection tasks, and the problem of other server free time.The reliability connecting not only can be guaranteed by connection scheme provided by the invention, the resource of each station server can also be reasonably utilized.
Accompanying drawing explanation
Fig. 1 is according to the flow chart of steps of a kind of server method of attachment based on connection pool of the embodiment of the present invention one;
Fig. 2 is according to the flow chart of steps of a kind of server method of attachment based on connection pool of the embodiment of the present invention two;
Fig. 3 is according to the structured flowchart of a kind of server jockey based on connection pool of the embodiment of the present invention three;
Fig. 4 is a kind of structured flowchart of the system that the server jockey based on connection pool is installed.
Embodiment
For above-mentioned purpose of the present invention, feature and advantage can be become apparent more, below in conjunction with the drawings and specific embodiments, the present invention is further detailed explanation.
Embodiment mono-
With reference to Fig. 1, show according to the flow chart of steps of a kind of server method of attachment based on connection pool of the embodiment of the present invention one.
The step of the server method of attachment of the present embodiment comprises:
Step S102: the each station server in the real-time monitoring server cluster of connection pool, obtains line server information.
Connection pool in the present embodiment is a static library forming by encapsulation, is the network communication module of the concurrent low delay of height based on Transmission Control Protocol, can be applied to the each module in operation system, for example: the each module in advertisement delivery system.Connection pool, by the each station server in server cluster is monitored, obtains online server info, selects a station server and operation system to connect from online server.
Wherein, server info can comprise: one or more information such as server label, central processing unit load, free memory.Those skilled in the art can arrange the particular content that the server info that need to obtain comprises according to the actual requirements, for example: can be by the label that only obtain server is set; Or only obtain label and the free memory information of server.Can upgrade information automatically having obtained connection pool after line server information.
Step S104: connection pool receives the request connecting with server that operation system sends.
When operation system need to connect with a certain station server, send the request connecting to connection pool, connection pool offers corresponding a connection of operation system according to the request of connecting of operation system transmission.
Step S106: the request connecting with server that connection pool sends according to operation system, selects the strategy of a selection server.
Be packaged into the strategy that comprises multiple choices server in the connection pool of static library, for example: the strategy of choosing at random a service; Select the strategy of the server of free memory maximum; Or according to multiple choices strategies such as the strategies of the server of server label size selection server label maximum.In the time that connection pool is applied in concrete operation system, need to select a kind of selection strategy, and this connection pool in the time that selecting server, postorder all to be selected to server according to this strategy.
Step S108: connection pool is according to selection strategy and line server of line server Information Selection.
Connection pool in the time being applied in operation system, corresponding a kind of strategy of selecting server, connection pool obtains this selection strategy, selects a server connecting with operation system according to the online server info obtaining simultaneously.For example: if connection pool is in the time being applied in operation system, the strategy of corresponding selection server is: the strategy of selecting the server of server label maximum according to server label size, connection pool is selecting when server so, and the server of searching server label maximum from line server information is as the server connecting with operation system.
Step S110: connection pool has judged whether to preserve the unappropriated connection example of selected line server; If preserved, perform step S112; If do not preserve, perform step S114.
In connection pool, saved each connection example is to there being socket handle, socket handle corresponding one with server between be connected.When connection pool provides connection for operation system, operation system can return to connection pool by this connection after using connection, connection pool can continue to preserve the socket handle of this connection correspondence, that is to say and can continue to preserve connection example corresponding to socket handle, can continue to safeguard with server between this be connected.
Connection pool is after having selected a server connecting with operation system, can further judge whether to preserve connection example corresponding to this server, if preserved the connection example that one or more these servers are corresponding in connection pool, whether sharedly by other connections of operation system so further judge that each connects example, if there is the connection example not taken by other connections, judge and in connection pool, have unappropriated connection example, if between all and this server of preserving in connection pool to be connected example all shared by other connections of operation system, judge and in connection pool, do not have unappropriated connection example.
Step S112: if preserved unappropriated connection example, connection pool is directly selected unappropriated connection example.
Step S114: if do not preserve unappropriated connection example, connection pool obtains a new connection example, sets up and being connected of selected line server by new connection example, adds the extremely new connection example of socket handle of this connection correspondence; The new connection example of socket handle has been added in selection.
Connection pool can be preserved newly-built this always and connect example, until this between connection pool and online server is connected disconnection.
Step S116: the request connecting with server that connection pool sends for operation system returns to operation system by socket handle corresponding selected connection example by corresponding interface, sets up being connected of operation system and selected line server according to this socket handle.
The server method of attachment based on connection pool providing by the present embodiment, monitoring server cluster in real time, and obtain the information of line server, then from online server, select a server and operation system to connect, the server that has guaranteed to offer operation system is all online, avoid in existing connection scheme, the server going wrong being offered the problem of operation system, and then guaranteed the reliability connecting.The method connecting that the present embodiment provides, the server connecting according to selection strategy and line server Information Selection and operation system, can connect task according to the present situation reasonable distribution of each online server, that has avoided existing in existing connected mode distributes to same station server by multiple connection tasks, and the problem of other server free time.The method of attachment providing by the present embodiment not only can guarantee the reliability connecting, and can also reasonably utilize the resource of each station server.
Embodiment bis-
With reference to Fig. 2, show according to the flow chart of steps of a kind of server method of attachment based on connection pool of the embodiment of the present invention two.
The concrete steps of the server method of attachment of the present embodiment comprise:
Step S202: connection pool receives the long connection of operation system input or the link order of short connection, the connection of setting up respective type according to link order.
Connection pool is packed two kinds of types that connect in the time being packaged into static library, and a kind of to connect another kind be short connection for long.Connection pool is in the time being applied in operation system, and the type that those skilled in the art can select connection pool to connect at postorder according to business scenario, is long connection or short connection.But, it should be noted that, selecting connection pool after a type all can only follow one type in the time that postorder connects.
Wherein, long being connected to: operation system can be returned this connection to connection pool after using the connection that connection pool provides, connection pool can continue to keep with server between be connected; When operation system asks to connect again, the server of selecting when connection pool or when same station server, can directly offer operation system by the connection of operation system return last time.Short being connected to: operation system can be returned this connection to connection pool after using the connection that connection pool provides, connection pool disconnect with server between this be connected; When operation system asks to connect again, the server of selecting when connection pool or when same station server, connection pool also will connect again and between server, then connection could be offered to operation system.
In the present embodiment, setting up the long example that is connected to connection pool describes the step of postorder.
Step S204: the each station server in the real-time monitoring server cluster of connection pool, obtains line server information.
In the present embodiment, connection pool is to obtain line server by the each station server in server cluster being carried out to monitoring in real time.Those skilled in the art should understand, server in connection pool can be by fixing IP(Internet Protocol, Internet protocol) address configuration is in connection pool, can also a part be configured in connection pool by fixed ip address, another part is by monitoring acquisition to server cluster.
In the present embodiment, the each station server of connection pool in real-time monitoring server cluster, when obtaining line server information, also can upgrade each server info, the line server information of obtaining in the present embodiment comprises: central processing unit load, free memory.
Step S206: whether connection pool can be used according to setting each line server of rule detection, deletes the server info that disabled line server is corresponding.
Connection pool is obtaining after line server information, can real-time or the online server of individual platform is detected every setting-up time interval.When detection, can judge whether each online server can be used by the prior mode connecting with each online server, if can successfully connect, determining server can be used, if can not successfully connect, determining server is unavailable, and connection pool can be deleted the server info corresponding to server that can not successfully connect.
Those skilled in the art can set the time interval that online server is detected according to the actual requirements, can be arranged to carry out every 10 minutes one-time detection, also can be arranged to carry out one-time detection every 5 minutes, can also be arranged to other the time interval, not do concrete restriction at this.
Step S208: the request connecting with server that connection pool sends according to operation system, select the strategy of the server of a selection central processing unit least-loaded, free memory maximum.
In connection pool, include the strategy of multiple choices server, in the time being applied in operation system, need to select a kind of strategy.Connection pool in the present embodiment has been selected the strategy of the processor of central processing unit least-loaded, free memory maximum in the time being applied in operation system.Therefore, receiving after the request connecting with server that operation system sends, connection pool provides the strategy of the server of a selection central processing unit least-loaded, free memory maximum.
Step S210: connection pool according to the strategy of selecting and one of line server Information Selection online and the server of central processing unit least-loaded, free memory maximum.
Because the strategy of connection pool corresponding selection server after being applied in operation system is the server of selecting an online and central processing unit least-loaded, free memory maximum, therefore, in the time selecting server, will from line server information, select according to this strategy a qualified server of platform.
Step S212: connection pool has judged whether to preserve the connection example of selected line server; If do not preserve, directly perform step S218; If preserved, perform step S214.
Connection pool, after having selected server, can further judge the connection example of whether having preserved this server in connection pool, and it can be also multiple wherein connect example can being one.Every station server can be set up multiple connections simultaneously, but each connects an only corresponding connection example.
Step S214: in the time having preserved the connection example of selected line server in connection pool, connection pool further judges whether the connection example of the selected line server of preserving is connected and takies by other that set up with operation system; If unoccupied, perform step S216; If occupied, perform step S218.
In connection pool, saved each connection example is to there being link information, and wherein, link information comprises: the server label of socket handle, connection status, connection.The connection example of preserving in connection pool be also equivalent to preserve in connection pool this connection example corresponding with server between be connected.One that in connection pool, may preserve selected line server connects example, also may preserve multiple connection examples, so in the time judging, judge each connection example whether by with operation system between other be connected shared, if all connection examples that selected that station server of preserving is corresponding are all occupied, to perform step S218, unappropriated if connection example corresponding to selected that station server of preserving all exists, perform step S216.
Step S216: in the time that the connection example of the selected line server of preserving in connection pool is unoccupied, directly select described connection example, execution step S220.
Step S218: if do not preserve the connection example of selected online server, or the connection example of preserving is when occupied, connection pool obtains a new connection example, set up and being connected of selected line server by new connection example, add the extremely new connection example of socket handle of this connection correspondence; The new connection example of this socket handle has been added in selection, execution step S220.
When connection pool is set up with being connected of selected line server by new connection example, adopt half asynchronous system, i.e. first unblock connects, if failure becomes block type connection.Wherein, between line server unblock and that select, connect and refer to, no matter whether connection pool, in the time connecting with selected line server, connect and set up, connection pool can also carry out other operations, for example: set up other with other servers and be connected.Block type and line server between connect and refer to, connection pool in the time connecting with selected line server, only connect set up after connection pool just can carry out other operations.
Connection pool is with after being connected of selected line server set up, connection pool can obtain the socket handle of this connection correspondence, and this socket handle is saved in corresponding connection example, this socket handle is returned to operation system and set up being connected between operation system and selected server.
Step S220: the request connecting with server that connection pool sends for operation system returns to operation system by socket handle corresponding selected connection example by corresponding interface, sets up being connected of operation system and selected line server according to this socket handle.
Setting up after being connected of operation system and selected line server, connection pool also can provide corresponding reception, transmission interface for carrying out interacting message between operation system and selected line server.The reception, the transmission interface that in connection pool, provide are provided by socket handle operation system.Between the confession operation system that connection pool provides and selected line server, carry out interacting message interface and adopt half asynchronous transmission, reception mechanism, i.e. first unblock sends or receives, if do not complete, changes block type into and sends or receive.
Operation system is using after this connection and connection can returned to connection pool, connection pool can safeguard this connection can't disconnect with selected line server information between be connected, while again initiating to ask for operation system, use.But, if server goes wrong or connection pool no longer need with server between this while being connected, connection pool disconnection is connected with selected line server, and connection pool can be deleted the socket handle in selected connection example, obtains a new connection example.
The server method of attachment based on connection pool providing by the present embodiment, first, can realize the control that length is connected, secondly, monitoring server cluster in real time, obtain the information of line server and information is upgraded, in real time or according to setting-up time interval, each online server is detected meanwhile, the corresponding server info of server that can not meet connection standard is deleted, the server that has guaranteed to offer operation system is all online and available, avoid in existing connection scheme, the server going wrong being offered the problem of operation system, and then guarantee the reliability connecting.The method of attachment that the present embodiment provides, the server connecting according to selection strategy and line server Information Selection and operation system, can connect task according to the present situation reasonable distribution of each online server, that has avoided existing in existing connected mode distributes to same station server by multiple connection tasks, and the problem of other server free time, the method of attachment providing by the present embodiment not only can guarantee the reliability connecting, and can also reasonably utilize the resource of each station server.Meanwhile, the method for attachment providing in by the present embodiment, in the time connecting with selected server, adopts half asynchronous system first to block connection, connects if failure becomes block type, has improved joint efficiency; Adopt half asynchronous transmission, reception mechanism to improve the efficiency of transmission, receipt message.
Embodiment tri-
With reference to Fig. 3, show the structured flowchart of a kind of server jockey based on connection pool in the embodiment of the present invention three.
The server jockey based on connection pool of the present embodiment comprises: cluster monitoring module 302, for each station server of real-time monitoring server cluster, obtain line server information; Connection management module 304, the request connecting with server sending for receiving operation system; Also be used to cluster management module 308 that new connection example is provided; Policy management module 306, for the request connecting with server sending according to operation system, selects the strategy of a selection server; Cluster management module 308, for strategy and line server of line server Information Selection according to selecting; Cluster management module 308, also for judging whether to have preserved the unappropriated connection example of selected line server; If preserved the unappropriated connection example of selected line server, directly select this connection example, wherein, saved each connection example is to there being socket handle; If do not preserve the unappropriated connection example of selected line server, obtain a new connection example, set up and being connected of selected line server by new connection example, add the extremely new connection example of socket handle of this connection correspondence; The new connection example of this socket handle has been added in selection; Connection management module 304, also for the request connecting with server sending for operation system, socket handle corresponding selected connection example is returned to operation system by corresponding interface, set up being connected of operation system and selected line server according to this socket handle.
Preferably, server jockey based on connection pool also comprises: health detection module 310, for after cluster monitoring module 302 is obtained line server information, whether can use according to setting each online server of rule detection, delete the server info that disabled line server is corresponding.
Preferably, server info comprises: central processing unit load, free memory; The request connecting with server that policy management module 306 sends according to operation system, while selecting one to select server tactful: the request connecting with server sending according to operation system, select the strategy of the server of a selection central processing unit least-loaded, free memory maximum; Cluster management module 308 is during according to selection strategy and a line server of selected line server Information Selection: according to one of the strategy of selecting and the selection of selected online server info online and the server of central processing unit least-loaded, free memory maximum.
Preferably, cluster management module 308 is also for the each station server at cluster monitoring module 302 real-time monitoring servers, before obtaining line server information, receive the long connection of operation system input or the link order of short connection, the connection of setting up respective type according to link order; Cluster management module 308, also for set up being connected of operation system and selected line server in connection management module after, in the time disconnecting with being connected of selected online server, the socket handle of deleting in selected connection example obtains a new connection example, and the new connection example obtaining is returned to connection management module 304; Connection management module 304, the new connection example of also giving back for receiving cluster management module.
The server jockey based on connection pool of the present embodiment is used for realizing the corresponding server method of attachment of aforementioned multiple embodiment of the method, and has the beneficial effect that corresponding method is implemented, and does not repeat them here.
Below in conjunction with concrete application scenarios take a concrete example to the server jockey based on connection pool in the application and this application of installation to after in operation system for operation system foundation is once introduced with the detailed process being connected between server.
As shown in Figure 4, server jockey based on connection pool be a connection pool 402 its be applied in operation system 404, connection pool 402 is divided into 5 modules: connection management module 4022, cluster management module 4024, health detection module 4026, policy management module 4028, cluster monitoring module 40210.The corresponding server cluster 406 of operation system is monitored by cluster monitoring module 40210, and the corresponding interface that operation system provides by connection management module 4022 and server carry out the mutual of message.
Connection pool in this example both can have been supported long connection, also can support short connection, and the thread providing was safe.Connection pool in this example is the static library forming by encapsulation, can have versatility for the each module of advertisement delivery system.Before the detailed process that provides server to connect connection pool is introduced, first the effect of the modules in connection pool is carried out to following simple explanation.
Policy management module 4028: be provided with the strategy of multiple choices server in policy management module, it mainly realizes Server(server) selection strategy of Server in cluster.When operation system sends request to the Serve in Server cluster, policy management module 408 provides one to select the strategy of server to select some suitable Server for connection pool.
Health detection module 4026: main realization checks the health status of each Server in Server cluster, to judge whether a certain Server can use, and revise in cluster management module 404 state of this Server of management, server info corresponding disabled Server is deleted from cluster management module 404.
Cluster management module 4024: mainly realize the condition managing to each Server in Server cluster.While connecting certain Server, increase the link information of this connection correspondence of this Server in corresponding connection example, and this connection example is increased in cluster management module 4024; While disconnecting with being connected of certain Server, delete the link information in the connection example of this connection correspondence, and to give back connection example after deletion link information be that new connection example is to connection management module 4022.Wherein, link information is kept at and connects in example, and link information comprises: the server information of socket handle, connection status, connection, the server information of connection comprises: the label of server.
Connection management module 4022: mainly realize obtaining and giving back and message sends the encapsulation of receiving interface of connection example new in cluster management module 4024.Cluster management module 4024 need to obtain with server between be connected time, from connection manager 4022, obtain a new connection example, in order to preserve with server between link information corresponding to connection, as socket(socket) the server information of handle, connection status, connection etc.; Cluster management module 4024 discharge with a certain server between be connected time,, by after the connection example replacement of this connection correspondence, be returned to connection management module 4022.Wherein, the connection example of resetting that is to say deletes the link information connecting in example, generates a new connection example.
Cluster monitoring module 40210: each online Server in monitoring Server cluster, and the responsible server info that upgrades the online Server obtaining in cluster management module 4024.
Having introduced after the concrete function of the modules comprising in connection pool, introduce the whole concept of the operation system of having applied this connection pool in the time connecting with server below: in the time that operation system will send request to Server cluster, first to connection of connection pool request, connection pool returns to socket handle corresponding to available connection of operation system, and the transmission, the receiving interface that call connection pool by socket handle by operation system carry out interacting message.Introduce the concrete process connecting with server below:
S1: cluster management module 4024 can configure the Server information of appointment, or obtain the server info of online Server by cluster monitoring module, and upgrade the server info of online Server.
S2: health detection module 4026, every setting-up time interval, is carried out status checkout to each Server in cluster management module 4024, and enable(enables) the available Server that newly reaches the standard grade, disable(deletes) roll off the production line or abnormal Server.
S3: the interface that operation system provides by connection management module 4022 sends the request connecting with server to connection pool.
S4: the request connecting that connection management module 4022 sends operation system is sent to cluster management module 4024 asks available connection from an available Server to cluster management module 4024.
S5: suitable Server of policy selection of the selection server that cluster management module 4024 provides by policy management module 408.
S6: judge the link information of whether having safeguarded this Server in cluster management module 4024, namely judged whether to preserve connection example corresponding to this Server, store the link information of this Server in connection example.
S7: if there is no available connection example, 4024 of cluster management modules are obtained a new connection example from connection management module 402, by the new connection example obtaining set up with this Server between be connected, and give cluster management module 4024 and manage these connection examples; If available free available connection example, uses ready-made connection example.
Wherein, idle available connection example is equivalent to the unappropriated connection example of this Server storing in connection management module.Cluster management module 4024 by the new connection example obtaining set up with this Server between be connected time adopt half asynchronous system, first unblock connects, if failure becomes block type connection.
S8: connection management module 4022 returns to operation system by connecting socket handle corresponding to example by corresponding interface.
S9: the socket handle that operation system provides by connection management module 4022 calls the transmission in connection management module 4022, transmission, the reception that receiving interface carries out message.
Transmission in connection management module 4022, receiving interface adopt half asynchronous transmission, reception mechanism, i.e. first unblock sends or receives, if do not complete, change block type into and send or receive.
When operation system uses with after being connected of server, operation system is given back and is connected to connection pool; The new connection example that cluster management module 4024 generates after the connection example of the connection correspondence being finished is reset, and give back connection management module 4022 by being finished the rear new connection example generating of resetting; Connection management module 4022 safeguards that cluster management module 4024 is finished the rear new connection example generating of resetting, so that cluster management module 4024 is obtained new connection to connection management module again, saves input and output spending.
In this example, whole connection pool is packaged into static library, adopts the thought of connection pool, save socket resource; Design and distinguish long and short connection, realize the connection pool to Server cluster monitoring and the decision-making of self-defined selection server, and in connection pool, encapsulated transmission, receiving interface.Connection pool in this example adopts half asynchronous system, and first unblock connects, if failure becomes block type and connects, has improved joint efficiency; Adopt half asynchronous transmission, reception mechanism, i.e. first unblock sends or receives, if do not complete, change block type into and send or receive, and has improved the efficiency of transmission, receipt message.By connection pool in this example can high concurrent, high performance prerequisite under, realize length connect control, cluster monitoring, use convenient, quick, with better function.
Each embodiment in this specification all adopts the mode of going forward one by one to describe, and what each embodiment stressed is and the difference of other embodiment, between each embodiment identical similar part mutually referring to.For device embodiment, because it is substantially similar to embodiment of the method, so description is fairly simple, relevant part is referring to the part explanation of embodiment of the method.
Above server method of attachment and the device based on connection pool provided by the present invention is described in detail, applied specific case herein principle of the present invention and execution mode are set forth, the explanation of above embodiment is just for helping to understand method of the present invention and core concept thereof; , for one of ordinary skill in the art, according to thought of the present invention, all will change in specific embodiments and applications, in sum, this description should not be construed as limitation of the present invention meanwhile.

Claims (10)

1. the server method of attachment based on connection pool, is characterized in that, comprising:
Each station server in monitoring server cluster, obtains line server information in real time;
Receive the request connecting with server that operation system sends;
The request connecting described in foundation, selects a strategy of selecting server;
According to described strategy and line server of described line server Information Selection;
Judge whether to preserve the unappropriated connection example of selected line server;
If preserved described connection example, directly select described connection example, wherein, saved each described connection example is to there being socket handle;
If do not preserve described connection example, obtain a new connection example, set up and being connected of selected line server by described new connection example, add extremely described new connection example of socket handle corresponding to described connection; The new connection example of described socket handle has been added in selection;
For the described request connecting, socket handle corresponding selected connection example is returned to described operation system by corresponding interface, set up being connected of described operation system and selected line server according to described socket handle.
2. method according to claim 1, is characterized in that, the each station server in described real-time monitoring server cluster, after obtaining line server information step, also comprises:
Whether can use according to setting each line server of rule detection, delete the server info that disabled line server is corresponding.
3. according to the method described in claim 1 or 2 any one, it is characterized in that, described server info comprises: central processing unit load, free memory; The request connecting described in described foundation, select one to select the strategy step of server to comprise:
According to described in the request that connects, select the strategy of the server of a selection central processing unit least-loaded, free memory maximum;
The step of the described strategy of described foundation and a line server of described line server Information Selection comprises:
According to one of described strategy and described line server Information Selection online and the server of central processing unit least-loaded, free memory maximum.
4. method according to claim 3, is characterized in that, described in judged whether to preserve selected line server unappropriated connection case step comprise:
Judge whether to preserve the connection example of selected line server; If preserved described connection example, further judge whether described connection example is connected and takies by other that set up with described operation system; If described connection example is unoccupied, judged result is to have preserved the unappropriated connection example of selected line server.
5. method according to claim 4, is characterized in that, the each station server in described real-time monitoring server cluster, before obtaining line server information step, also comprises:
Receive the long connection of described operation system input or the link order of short connection, the connection of setting up respective type according to described link order.
6. method according to claim 5, is characterized in that, after the described socket handle of described foundation is set up the Connection Step of described operation system and selected line server, also comprises:
In the time disconnecting with being connected of selected line server, delete the socket handle in described selected connection example, obtain a new connection example.
7. the server jockey based on connection pool, is characterized in that, comprising:
Cluster monitoring module, for each station server of real-time monitoring server cluster, obtains line server information;
Connection management module, the request connecting with server sending for receiving operation system; Policy management module, for the request connecting described in foundation, selects a strategy of selecting server;
Cluster management module, for the described strategy of foundation and line server of described line server Information Selection; Described cluster management module, also for judging whether to have preserved the unappropriated connection example of selected line server; If preserved described connection example, directly select described connection example, wherein, saved each described connection example is to there being socket handle; If do not preserve described connection example, obtain a new connection example, set up and being connected of selected line server by described new connection example, add extremely described new connection example of socket handle corresponding to described connection; The new connection example of described socket handle has been added in selection;
Described connection management module, also for for the described request connecting, socket handle corresponding selected connection example being returned to described operation system by corresponding interface, set up being connected of described operation system and selected line server according to described socket handle.
8. device according to claim 7, is characterized in that, described device also comprises:
Whether health detection module, for after described cluster monitoring module is obtained line server information, can use according to setting each online server of rule detection, deletes the server info that disabled line server is corresponding.
9. according to the device described in claim 7 or 8 any one, it is characterized in that, described server info comprises: central processing unit load, free memory;
Described policy management module according to described in the request that connects, while selecting one to select server tactful: the request connecting described in foundation, select the strategy of the server of a selection central processing unit least-loaded, free memory maximum;
Described cluster management module is according to described strategy during with a line server of described line server Information Selection: according to one of described strategy and the selection of described online server info online and the server of central processing unit least-loaded, free memory maximum.
10. device according to claim 9, is characterized in that,
Described cluster management module, also for the each station server at the real-time monitoring server of described cluster monitoring module, before obtaining line server information, receive the long connection of described operation system input or the link order of short connection, the connection of setting up respective type according to described link order;
Described cluster management module, also for set up being connected of described operation system and described line server in described connection management module after, in the time disconnecting with being connected of described online server, the socket handle of deleting in described selected connection example obtains a new connection example, and the described new connection example obtaining is returned to described connection management module;
Described connection management module, the described new connection example of also giving back for receiving described cluster management module.
CN201410030973.XA 2014-01-22 2014-01-22 Server connection method and device based on connection pool Pending CN103795569A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410030973.XA CN103795569A (en) 2014-01-22 2014-01-22 Server connection method and device based on connection pool

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410030973.XA CN103795569A (en) 2014-01-22 2014-01-22 Server connection method and device based on connection pool

Publications (1)

Publication Number Publication Date
CN103795569A true CN103795569A (en) 2014-05-14

Family

ID=50670894

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410030973.XA Pending CN103795569A (en) 2014-01-22 2014-01-22 Server connection method and device based on connection pool

Country Status (1)

Country Link
CN (1) CN103795569A (en)

Cited By (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104994093A (en) * 2015-07-01 2015-10-21 网宿科技股份有限公司 Method and system for balancing service load
CN105677397A (en) * 2015-12-30 2016-06-15 南京途牛科技有限公司 Method for optimizing PHP remote procedure call through local gateway program
CN105871977A (en) * 2015-11-27 2016-08-17 乐视体育文化产业发展(北京)有限公司 Long connection establishment method and system, and devices
CN105933464A (en) * 2016-04-13 2016-09-07 北京思特奇信息技术股份有限公司 Network communication method and system based on network connection pooling
WO2016177130A1 (en) * 2015-05-07 2016-11-10 中兴通讯股份有限公司 Method and device for selecting communication node
CN106550027A (en) * 2016-10-25 2017-03-29 深圳中兴网信科技有限公司 Equipment method of attachment and equipment connection system
CN106980479A (en) * 2016-01-15 2017-07-25 优视科技(中国)有限公司 Method, device and the server of multi-screen interactive
CN109189595A (en) * 2018-09-17 2019-01-11 深圳怡化电脑股份有限公司 Event-handling method, device, equipment and medium based on server
CN109474456A (en) * 2018-09-26 2019-03-15 中国平安人寿保险股份有限公司 Configuration data processing method, device, computer equipment and storage medium
CN110535940A (en) * 2019-08-29 2019-12-03 北京浪潮数据技术有限公司 A kind of connection management method, system, equipment and the storage medium of BMC
CN110933121A (en) * 2018-09-19 2020-03-27 阿里巴巴集团控股有限公司 Connection establishing method, communication processing method and device and communication equipment
CN112882848A (en) * 2021-02-25 2021-06-01 武汉大学 Basic middleware applied to network and distributed development
CN114679434A (en) * 2022-05-27 2022-06-28 武汉中科通达高新技术股份有限公司 Session message processing system, method, computer device and storage medium

Cited By (21)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016177130A1 (en) * 2015-05-07 2016-11-10 中兴通讯股份有限公司 Method and device for selecting communication node
CN106209943A (en) * 2015-05-07 2016-12-07 中兴通讯股份有限公司 The system of selection of communication node and device
CN104994093B (en) * 2015-07-01 2018-11-02 网宿科技股份有限公司 A kind of service load balancing method and system
CN104994093A (en) * 2015-07-01 2015-10-21 网宿科技股份有限公司 Method and system for balancing service load
CN105871977A (en) * 2015-11-27 2016-08-17 乐视体育文化产业发展(北京)有限公司 Long connection establishment method and system, and devices
CN105677397A (en) * 2015-12-30 2016-06-15 南京途牛科技有限公司 Method for optimizing PHP remote procedure call through local gateway program
CN105677397B (en) * 2015-12-30 2018-09-25 南京途牛科技有限公司 Pass through the method for local gateway program optimization PHP far calls
CN106980479B (en) * 2016-01-15 2020-07-14 阿里巴巴(中国)有限公司 Multi-screen interaction method and device and server
CN106980479A (en) * 2016-01-15 2017-07-25 优视科技(中国)有限公司 Method, device and the server of multi-screen interactive
CN105933464A (en) * 2016-04-13 2016-09-07 北京思特奇信息技术股份有限公司 Network communication method and system based on network connection pooling
CN105933464B (en) * 2016-04-13 2019-05-31 北京思特奇信息技术股份有限公司 A kind of network communication method and system based on network connection pond
CN106550027A (en) * 2016-10-25 2017-03-29 深圳中兴网信科技有限公司 Equipment method of attachment and equipment connection system
CN106550027B (en) * 2016-10-25 2020-02-21 深圳中兴网信科技有限公司 Device connection method and device connection system
CN109189595A (en) * 2018-09-17 2019-01-11 深圳怡化电脑股份有限公司 Event-handling method, device, equipment and medium based on server
CN110933121A (en) * 2018-09-19 2020-03-27 阿里巴巴集团控股有限公司 Connection establishing method, communication processing method and device and communication equipment
CN109474456A (en) * 2018-09-26 2019-03-15 中国平安人寿保险股份有限公司 Configuration data processing method, device, computer equipment and storage medium
CN110535940A (en) * 2019-08-29 2019-12-03 北京浪潮数据技术有限公司 A kind of connection management method, system, equipment and the storage medium of BMC
CN112882848A (en) * 2021-02-25 2021-06-01 武汉大学 Basic middleware applied to network and distributed development
CN112882848B (en) * 2021-02-25 2024-08-23 武汉大学 Basic middleware applied to network and distributed development
CN114679434A (en) * 2022-05-27 2022-06-28 武汉中科通达高新技术股份有限公司 Session message processing system, method, computer device and storage medium
CN114679434B (en) * 2022-05-27 2022-08-26 武汉中科通达高新技术股份有限公司 Session message processing system, method, computer device and storage medium

Similar Documents

Publication Publication Date Title
CN103795569A (en) Server connection method and device based on connection pool
CN105610632B (en) Virtual network equipment and related method
CN115328663B (en) Method, device, equipment and storage medium for scheduling resources based on PaaS platform
CN104811323A (en) Data requesting method, data requesting device, node server and CDN (content delivery network) system
EP2939401B1 (en) Method for guaranteeing service continuity in a telecommunication network and system thereof
CN110995617B (en) MQTT-based data transmission method and device, computer equipment and storage medium
CN107689878A (en) TCP length connection SiteServer LBSs based on name scheduling
CN113127192A (en) Method, system, device and medium for sharing same GPU by multiple services
CN110290009B (en) Data scheduling method and device and computer readable storage medium
CN113517985A (en) File data processing method and device, electronic equipment and computer readable medium
CN105933271B (en) Data processing method and device based on encryption machine
CN112019378A (en) Troubleshooting method and device
CN108667640B (en) Communication method and device, and network access system
CN117032987A (en) Distributed task scheduling method, system, equipment and computer readable medium
CN116389385A (en) System resource processing method, device, storage medium and equipment
EP3174322A1 (en) Method for deleting notification resource, and common service entity
CN111147389A (en) TCP long connection server load balancing system and method
KR101251630B1 (en) System and method for providing push service
CN104869118A (en) Method and system for achieving DDoS defense based on technology of dynamic tunnels
CN114124737B (en) Method and device for controlling user equipment to access network
CN113535402A (en) Load balancing processing method and device based on 5G MEC and electronic equipment
CN114285889A (en) Method, device and equipment for processing configuration information of application service
CN113727138A (en) HLS intranet source returning method
CN104426704A (en) Integration network device and service integration method thereof
CN111641664B (en) Crawler equipment service request method, device and system and storage medium

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20140514