Method and device for synchronizing service data
Technical Field
The present invention relates to the field of internet communications, and in particular, to a method and an apparatus for synchronizing service data.
Background
Currently, to relieve the pressure on the service server caused by the huge access amount, a plurality of service servers are generally used to provide services for one service. When service data is generated on one service server, the service server needs to synchronize the generated service data to other service servers, so as to ensure that the other service servers can provide services for the service according to the service data.
Currently, the prior art provides a method for synchronizing service data, which includes: a data server is set in advance, and the data server is used for storing service data of a service. The service corresponds to a plurality of service servers, and when service data is generated on any one of the plurality of service servers, the service server transmits the generated service data to the data server, and the data server stores the service data. When a service server receives a service request for reading the service data, the service server sends a request for acquiring the service data to a data server, acquires the service data from the data server to realize the synchronization of the service data to the service server, and then sends the acquired service data to a user.
In the process of implementing the invention, the inventor finds that the prior art has at least the following problems:
each time of generating service data, the generated service data is sent to the data server, and when the service data needs to be read, the service data is obtained from the data server, so that a large amount of bandwidth resources are occupied, and when the capacity of the generated service data is large, the time spent on sending the service data is long, and the efficiency of synchronizing the service data is low.
Disclosure of Invention
In order to save bandwidth resources and improve the efficiency of synchronizing service data, the invention provides a method and a device for synchronizing service data. The technical scheme is as follows:
a method of synchronizing traffic data, the method comprising:
when monitoring that a program code of an operation service generates first service data, a first service server acquires a class and a function used for generating the first service data in the program code;
acquiring first synchronization information corresponding to the first service data according to the class and the function, wherein the first synchronization information comprises a class identifier of the class, a function identifier of the function, and a parameter type and a parameter value of a parameter included in the function;
and sending the first synchronization information to each other service server except the first service server in the service server group corresponding to the service, so that each other service server executes the class and the function according to the first synchronization information to generate the first service data, thereby realizing synchronization of the first service data.
An apparatus for synchronizing traffic data, the apparatus comprising:
the system comprises a first acquisition module, a first service server and a second acquisition module, wherein the first acquisition module is used for acquiring a class and a function used for generating first service data in a program code when the first service server monitors that the program code of an operation service generates the first service data;
a second obtaining module, configured to obtain, according to the class and the function, first synchronization information corresponding to the first service data, where the first synchronization information includes a class identifier of the class, a function identifier of the function, and a parameter type and a parameter value of a parameter included in the function;
a sending module, configured to send the first synchronization information to each service server in a service server group corresponding to the service, except for the first service server, so that each service server executes the class and the function according to the first synchronization information to generate the first service data, thereby synchronizing the first service data.
In the embodiment of the invention, when monitoring that a program code of an operation service generates first service data, a first service server acquires a class and a function for generating the first service data in the program code; according to the class and the function, first synchronization information corresponding to the first service data is obtained, wherein the first synchronization information comprises class identification of the class, function identification of the function, and parameter types and parameter values of parameters included in the function; and sending first synchronization information to each other service server except the first service server in the service server group corresponding to the service, so that each other service server generates first service data according to the execution class and the function of the first synchronization information respectively, thereby realizing the synchronization of the first service data. Because the capacity of the first synchronization information is very small, the bandwidth occupied by sending the first synchronization information is very small, the speed of sending the first synchronization information is very high, and after each other service server receives the first synchronization information, the first service data is quickly generated according to the first synchronization information, so that the network bandwidth is saved, and the efficiency of synchronizing the service data is improved.
Drawings
Fig. 1 is a flowchart of a method for synchronizing service data according to embodiment 1 of the present invention;
fig. 2 is a flowchart of a method for synchronizing service data according to embodiment 2 of the present invention;
fig. 3 is a schematic structural diagram of an apparatus for synchronizing service data according to embodiment 3 of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention will be described in detail with reference to the accompanying drawings.
Example 1
Referring to fig. 1, an embodiment of the present invention provides a method for synchronizing service data, including:
step 101: when monitoring that a program code of an operation service generates first service data, a first service server acquires a class and a function for generating the first service data in the program code;
step 102: according to the class and the function, first synchronization information corresponding to the first service data is obtained, wherein the first synchronization information comprises class identification of the class, function identification of the function, and parameter types and parameter values of parameters included in the function;
step 103: and sending first synchronization information to each other service server except the first service server in the service server group corresponding to the service, so that each other service server generates first service data according to the execution class and the function of the first synchronization information respectively, thereby realizing the synchronization of the first service data.
Preferably, the obtaining of the first synchronization information corresponding to the first service data according to the class and the function includes:
acquiring a class identifier of the class and a function identifier of the function;
acquiring each parameter included in the function, respectively acquiring a parameter value of each parameter, and acquiring a parameter type of each parameter value;
and the acquired class identifier, function identifier, parameter type and parameter value form first synchronization information corresponding to the first service data.
Preferably, the sending the first synchronization information to each service server except the first service server in the service server group corresponding to the service includes:
the method comprises the steps that the address of each service server except a first service server in a service server group corresponding to a service is obtained from a control server, and first synchronization information is sent to each other service server according to the address of each other service server; or,
and sending the first synchronization information, the service identifier of the service and the identifier of the first service server to the control server, so that the control server respectively sends the first synchronization information to each other service server according to the address of each other service server except the first service server in the service server group corresponding to the service.
Further, the method further comprises:
receiving second synchronous information sent by a second service server, wherein the second synchronous information comprises a class identifier, a function identifier, a parameter type and a parameter value;
and executing the class corresponding to the class identifier and the function corresponding to the function identifier according to the second synchronization information to generate second service data.
Preferably, executing the class corresponding to the class identifier and the function corresponding to the function identifier according to the second synchronization information to generate the second service data includes:
acquiring a class corresponding to the class identifier from the program code according to the class identifier included in the second synchronization information;
acquiring a function corresponding to the function identifier from the program code according to the function identifier included in the second synchronization information;
and executing the acquired class and the acquired function according to the parameter type and the parameter value included in the second synchronization information to generate second service data.
In the embodiment of the invention, when monitoring that a program code of an operation service generates first service data, a first service server acquires a class and a function for generating the first service data in the program code; according to the class and the function, first synchronization information corresponding to the first service data is obtained, wherein the first synchronization information comprises class identification of the class, function identification of the function, and parameter types and parameter values of parameters included in the function; and sending first synchronization information to each other service server except the first service server in the service server group corresponding to the service, so that each other service server generates first service data according to the execution class and the function of the first synchronization information respectively, thereby realizing the synchronization of the first service data. Because the capacity of the first synchronization information is very small, the bandwidth occupied by sending the first synchronization information is very small, the speed of sending the first synchronization information is very high, and after each other service server receives the first synchronization information, the first service data is quickly generated according to the first synchronization information, so that the network bandwidth is saved, and the efficiency of synchronizing the service data is improved.
Example 2
The embodiment of the invention provides a method for synchronizing service data.
At present, in order to relieve the pressure on the service server caused by huge access volume, a plurality of service servers are generally used for providing service for one service, so that one service corresponds to one service server group. When one service server in the service server group generates service data, the service server can synchronize the generated service data to each service server in the service server group except the service server by using the method provided by the embodiment of the invention.
The service also corresponds to a load balancing server, and is used for balancing the load pressure of each service server in the service server group corresponding to the service. When the load balancing server receives a service request of the service, the load balancing server determines a service server with the minimum load pressure according to the load condition of each service server in the service server group, and forwards the service request to the determined service server.
Referring to fig. 2, the method specifically includes:
step 201: when monitoring that a program code of an operation service generates first service data, a first service server acquires a class and a function for generating the first service data in the program code;
when writing a program code of a service, a technician labels classes and functions capable of generating service data in the program code, and then stores the program code of the service in each service server included in a service server group corresponding to the service.
Wherein a class is a type of data in object-oriented programming that describes a class of things having common characteristics. The interior of the class encapsulates functions, and the class needs to be instantiated at runtime as an object having the characteristics of the class description through which the function is called. For example, a "teacher" is a class that describes the common features of all teachers. The class "teacher" may encapsulate the "prepare lesson" function and the "view lesson preparation" function. Instantiating the class "teacher" may result in an object "plum teacher". At run-time, the function "prepare lesson" or "view lesson book" is called by the object "li teacher". The 'li teacher' calls the function 'to prepare lessons' to generate service data, and the 'li teacher' calls the function 'to check lessons' to generate service data.
The instantiation of the class as the object is to open up a storage space in the memory for storing the data information of the object. For example, the class "teacher" is instantiated as an object "li teacher", which is to create a storage space in the memory to store the data information of "li teacher", and the data information of "li teacher" may include the name of the class and the name of the course taught by "li teacher".
The method specifically includes that when a first service server receives a service request forwarded by a load balancing server, a program code of the service is operated to process the service request, at the moment, the first service server monitors the program code of the service, when it is monitored that a certain labeled class in the program code calls a certain labeled function, the class and the function are judged to be executed and first service data are generated, and at the moment, the class and the function are obtained from the program code.
The first service server is any one service server in the service server group corresponding to the service.
For example, when a first service server receives a service request forwarded by a load balancing server, the first service server runs a program code of the service 1 to process the service request, and monitors the program code of the service 1, and when it is monitored that a certain labeled class in the program code calls a certain labeled function, it is determined that the class and the function are executed and first service data is generated. The labeled class is assumed to be the class "teacher" and the labeled function is the function "prepare lesson". At this point the class "teacher" and the function "prepare lesson" are obtained from the program code.
Step 202: acquiring first synchronization information corresponding to the first service data according to the acquired class and function, wherein the first synchronization information comprises class identification of the class, function identification of the function, and parameter type and parameter value of parameters included in the function;
the class identifier of the class may be a class name of the class, and the function identifier of the function may be a function name of the function. The function comprises at least one parameter, and when the function is operated, the parameter comprised in the function is endowed with a parameter value, the parameter value has a corresponding parameter type, and the parameter type can be integer type or character type.
Specifically, the step is to acquire the class name of the class from the class as the class identifier of the class. And acquiring the function name of the function from the function as the function identification of the function. Obtaining each parameter included in the function, respectively obtaining a parameter value of each parameter, and obtaining a parameter type of each parameter value. And the acquired class identifier, function identifier, parameter type and parameter value form first synchronization information corresponding to the first service data.
For example, the class name "teacher" of the class is acquired from the class "teacher" as the class identification of the class. And acquiring the function name 'lesson preparation' of the function from the function 'lesson preparation' as the function identification of the function. Each parameter included in the function "lesson preparation" is obtained, the function "lesson preparation" is assumed to include parameters "teacher", "course" and "page number", the parameter value "li teacher" of the parameter "teacher", the parameter value "language" of the parameter "course" and the parameter value "5 pages" of the parameter "page number" are obtained, and the parameter types of the parameter values "li teacher", "language" and the parameter value "5 pages" are all integer types. And the acquired class identifier 'teacher', the function identifier 'lesson preparation', the parameter value 'li teacher' and the parameter type integer thereof, the parameter value 'language' and the parameter type integer thereof, and the parameter value '5 pages' and the parameter type integer thereof form first synchronization information S1 corresponding to the first service data.
After the first synchronization information corresponding to the first service data is obtained through the operations in steps 201 and 202, the first service data may be synchronized to each service server, except the first service server, included in the service server group corresponding to the service through the following operation in step 203.
Step 203: sending first synchronization information to each service server except the first service server in the service server group corresponding to the service, so that each other service server executes the type and the function according to the first synchronization information to generate first service data, thereby realizing synchronization of the first service data;
the network can also be provided with a control server, and the control server stores the corresponding relation between the identification and the address of each service server included in the service server group corresponding to the service. The control server and the load balancing server may be the same server or different servers.
The step can be realized by the following first and second modes, specifically:
first, a first service server sends a service identifier of the service and an identifier of the first service server to a control server. The control server obtains the service server group corresponding to the service from the corresponding relation between the service identifier and the service server group according to the service identifier of the service, obtains the identifier of each service server except the first service server from the service server group according to the identifier of the first service server, then obtains the address of each service server except the first service server from the corresponding relation between the identifier of the service server and the address according to the identifier of each service server, and returns the address of each service server to the first service server. And the first service server respectively sends first synchronization information to each other service server according to the address of each other service server. After receiving the first synchronization information, each of the other service servers executes the class and the function according to the first synchronization information to generate first service data, so as to synchronize the first service data.
For example, assume that the service server group includes service servers 1, 2, and 3, where service server 1 is the first service server. The first service server 1 sends the service identity B1 of the service 1 and the identity F1 of the first service server to the control server. The control server obtains the service server group (F1, F2, F3) corresponding to the service 1 from the correspondence between the service identifier and the service server group shown in table 1 according to the service identifier B1 of the service 1, obtains the identifiers of the service servers 2 and 3 other than the first service server from the service server group (F1, F2, F3) according to the identifier F1 of the first service server as F2 and F3 respectively, then obtains the addresses of the service servers 2 and 3 other than the first service server 1 in the service server group (F1, F2, F3) as URL2 and URL3 respectively from the correspondence between the identifiers and the addresses of the service servers as shown in table 2 according to the identifiers F2 and F3 of the service servers 2 and 3, and returns the addresses 2 and URL3 of the service servers 2 and 3 to the first service server 1. The first service server 1 transmits the first synchronization information S1 to the service servers 2 and 3 according to the address URLs 2 and 3 of the service servers 2 and 3, respectively. After the service servers 2 and 3 receive the first synchronization information S1, the class "teacher" and the function "prepare lessons" are executed according to the first synchronization information S1, respectively, to generate first service data, so as to implement synchronization of the first service data.
TABLE 1
Service identification |
Business server group |
B1 |
(F1、F2、F3) |
…… |
…… |
TABLE 2
Identification of a service server |
Address of service server |
F1 |
URL1 |
F2 |
URL2 |
F3 |
URL3 |
Secondly, the first service server sends the first synchronization information, the service identifier of the service and the identifier of the first service server to the control server. The control server obtains the corresponding service server group from the corresponding relation between the service identifier and the service server group according to the service identifier of the service, obtains the identifier of each service server except the first service server from the obtained service server group according to the identifier of the first service server, and then obtains the address of each service server from the corresponding relation between the identifier of the service server and the address according to the identifier of each service server. And the control server respectively sends the first synchronization information to each other service server according to the address of each other service server. After receiving the first synchronization information, each of the other service servers executes the class and the function according to the first synchronization information to generate first service data, so as to synchronize the first service data.
For example, the first service server 1 transmits the first synchronization information S1, the service identity B1 of the service 1, and the identity F1 of the first service server to the control server. The control server obtains the corresponding service server group (F1, F2, F3) from the corresponding relationship between the service identifier and the service server group shown in table 1 according to the service identifier B1 of the service 1, obtains the identifiers of the service servers 2 and 3 except the first service server 1 as F2 and F3 from the obtained service server group (F1, F2, F3) according to the identifier F1 of the first service server, and then obtains the addresses of the service servers 2 and 3 as URLs 2 and 3 from the corresponding relationship between the identifiers and the addresses of the service servers shown in table 2 according to the identifiers F2 and F3 of the service servers 2 and 3. The control server transmits the first synchronization information S1 to the service servers 2 and 3 according to the address URLs 2 and 3 of the service servers 2 and 3, respectively. After the service servers 2 and 3 receive the first synchronization information S1, the class "teacher" and the function "prepare lessons" are executed according to the first synchronization information S1, respectively, to generate first service data, so as to implement synchronization of the first service data.
When the service data is generated for each service server except the first service server included in the service server group corresponding to the service, the generated service data may be synchronized with the first service server according to the operations of step 201 and step 203.
The first service server may obtain the first synchronization information when generating the first service data, and send the first synchronization information to each of the service servers included in the service server group except the first service server. It is also possible to receive the second synchronization information sent by the other service server and generate the second service data according to the second synchronization information by the following operations of steps 204 and 205.
Step 204: the first service server receives second synchronous information sent by a second service server, wherein the second synchronous information comprises a class identifier, a function identifier, a parameter type and a parameter value;
the second service server is any service server except the first service server in the service server group corresponding to the service.
For example, the first service server 1 receives the second synchronization information S2 sent by the second service server 2, and the second synchronization information S2 includes a class identifier "teacher", a function identifier "lesson preparation", a parameter value "teacher" and its corresponding parameter type integer, "math" and its corresponding parameter type integer, and a parameter value "10 pages" and its corresponding parameter type integer.
Step 205: and executing the class corresponding to the class identifier and the function corresponding to the function identifier according to the second synchronization information to generate second service data.
Specifically, according to the class identifier included in the second synchronization information, a class corresponding to the class identifier is obtained from the program code of the service. And acquiring a function corresponding to the function identifier from the program code of the service according to the function identifier included in the second synchronization information. And executing the acquired class and function according to the parameter type and the parameter value included in the second synchronous information to generate second service data.
The obtained class and function may be executed in the following manner:
and instantiating the acquired class according to the parameter type and the parameter value included in the second synchronous information to obtain an object. And substituting the parameter type and the parameter value included in the second synchronization information into the acquired function, and calling the function through the object to generate second service data.
For example, based on the class identification "teacher" included in the second synchronization information S2, the class "teacher" corresponding to the class identification is acquired from the program code of the service 1. According to the function identifier "lesson preparation" included in the second synchronization information S2, the function "lesson preparation" corresponding to the function identifier is obtained from the program code of service 1. The acquired class "teacher" is instantiated as the object "teacher" according to the parameter value "teacher" and its data type integer included in the second synchronization information S2. The parameter value "math" and its parameter type integer, and the parameter value "10 pages" and its parameter type integer included in the second synchronization information S2 are substituted into the function "lesson preparation", and the function "lesson preparation" is called by the object "teacher" so that "teacher prepares lessons on math to obtain 10 pages of lesson preparation records", thereby generating the second service data.
When each of the other service servers included in the service server group corresponding to the service receives the synchronization information, the service server group and the first service server may generate service data according to the synchronization information according to the operations of the above steps 204 and 205, so as to complete synchronization of the service data.
In the embodiment of the invention, when monitoring that a program code of an operation service generates first service data, a first service server acquires a class and a function for generating the first service data in the program code; according to the class and the function, first synchronization information corresponding to the first service data is obtained, wherein the first synchronization information comprises class identification of the class, function identification of the function, and parameter types and parameter values of parameters included in the function; and sending first synchronization information to each other service server except the first service server in the service server group corresponding to the service, so that each other service server generates first service data according to the execution class and the function of the first synchronization information respectively, thereby realizing the synchronization of the first service data. Because the capacity of the first synchronization information is very small, the bandwidth occupied by sending the first synchronization information is very small, the speed of sending the first synchronization information is very high, and after each other service server receives the first synchronization information, the first service data is quickly generated according to the first synchronization information, so that the network bandwidth is saved, and the efficiency of synchronizing the service data is improved.
Example 3
Referring to fig. 3, an embodiment of the present invention provides an apparatus for synchronizing service data, including:
a first obtaining module 301, configured to, when it is monitored that a program code of an operating service generates first service data, obtain a class and a function used for generating the first service data in the program code;
a second obtaining module 302, configured to obtain first synchronization information corresponding to the first service data according to the class and the function, where the first synchronization information includes a class identifier of the class, a function identifier of the function, and a parameter type and a parameter value of a parameter included in the function;
the sending module 303 is configured to send first synchronization information to each other service server in the service server group corresponding to the service, except for the first service server, so that each other service server generates first service data according to the first synchronization information execution class and the function, respectively, to implement synchronization of the first service data.
Wherein, the second obtaining module 302 includes:
the first obtaining unit is used for obtaining the class identifier of the class and the function identifier of the function;
the second obtaining unit is used for obtaining each parameter included in the function, respectively obtaining the parameter value of each parameter, and obtaining the parameter type of each parameter value;
and the composition unit is used for composing the acquired class identifier, function identifier, parameter type and parameter value into first synchronization information corresponding to the first service data.
Wherein, the sending module 303 includes:
a first sending unit, configured to obtain, from the control server, an address of each of the other service servers in the service server group corresponding to the service, except the first service server, and send first synchronization information to each of the other service servers according to the addresses of each of the other service servers; or,
and the second sending unit is used for sending the first synchronization information, the service identifier of the service and the identifier of the first service server to the control server, so that the control server respectively sends the first synchronization information to other service servers according to the addresses of other service servers except the first service server in the service server group corresponding to the service.
Further, the apparatus further comprises:
the receiving module is used for receiving second synchronous information sent by a second service server, wherein the second synchronous information comprises a class identifier, a function identifier, a parameter type and a parameter value;
and the execution module is used for executing the class corresponding to the class identifier and the function corresponding to the function identifier according to the second synchronous information so as to generate second service data.
Wherein, the execution module includes:
a third obtaining unit, configured to obtain, according to the class identifier included in the second synchronization information, a class corresponding to the class identifier from the program code;
a fourth obtaining unit, configured to obtain, according to the function identifier included in the second synchronization information, a function corresponding to the function identifier from the program code;
and the execution unit is used for executing the acquired class and the acquired function according to the parameter type and the parameter value included in the second synchronous information so as to generate second service data.
In the embodiment of the invention, when monitoring that a program code of an operation service generates first service data, a first service server acquires a class and a function for generating the first service data in the program code; according to the class and the function, first synchronization information corresponding to the first service data is obtained, wherein the first synchronization information comprises class identification of the class, function identification of the function, and parameter types and parameter values of parameters included in the function; and sending first synchronization information to each other service server except the first service server in the service server group corresponding to the service, so that each other service server generates first service data according to the execution class and the function of the first synchronization information respectively, thereby realizing the synchronization of the first service data. Because the capacity of the first synchronization information is very small, the bandwidth occupied by sending the first synchronization information is very small, the speed of sending the first synchronization information is very high, and after each other service server receives the first synchronization information, the first service data is quickly generated according to the first synchronization information, so that the network bandwidth is saved, and the efficiency of synchronizing the service data is improved.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, where the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like that fall within the spirit and principle of the present invention are intended to be included therein.