WO2024012101A1 - 分布式服务生成方法、系统、计算设备及存储介质 - Google Patents

分布式服务生成方法、系统、计算设备及存储介质 Download PDF

Info

Publication number
WO2024012101A1
WO2024012101A1 PCT/CN2023/098619 CN2023098619W WO2024012101A1 WO 2024012101 A1 WO2024012101 A1 WO 2024012101A1 CN 2023098619 W CN2023098619 W CN 2023098619W WO 2024012101 A1 WO2024012101 A1 WO 2024012101A1
Authority
WO
WIPO (PCT)
Prior art keywords
client
service
application
distributed service
code
Prior art date
Application number
PCT/CN2023/098619
Other languages
English (en)
French (fr)
Inventor
董克钦
Original Assignee
华为云计算技术有限公司
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 华为云计算技术有限公司 filed Critical 华为云计算技术有限公司
Publication of WO2024012101A1 publication Critical patent/WO2024012101A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment

Definitions

  • This application relates to the field of distributed services, and in particular, to a distributed service generation method, system, computing device and storage medium.
  • This application provides a distributed service generation method, system, computing device and storage medium, which can deploy applications into distributed services.
  • embodiments of the present application provide a distributed service generation method.
  • the method includes: obtaining the program source code of an application, where the program source code of the application includes multiple tags, and the multiple tags include sub-codes used to tag the application. A first tag for the application module and a second tag for tagging interface methods in the sub-application module.
  • the program source code of the application is compiled according to multiple tags to obtain the distributed service corresponding to the sub-application module, where the distributed service includes the sub-service implemented when the interface method in the corresponding sub-application module is executed. It should be understood that after each sub-application module in an application is deployed into a distributed service, the application is also deployed into a corresponding distributed service.
  • the above-mentioned compilation of the program source code of the application based on multiple tags to obtain distributed services corresponding to the sub-application modules includes: compiling the program source code of the application to obtain the services of the application Logic: use at least one code generation tool to obtain the calling code of the distributed service based on multiple tags, wherein the calling code of the distributed service is used to instruct the client of the distributed service to call the sub-service on the server side of the distributed service;
  • the above distributed service is obtained by combining the application business logic, the calling code of the distributed service and the framework code associated with the distributed service.
  • At least one code generation tool is used to obtain the calling code of the distributed service corresponding to the sub-application module according to multiple tags, including: using Remote Procedure Call (RPC) ) Server-side code generation tool obtains the RPC server based on multiple tags.
  • RPC Remote Procedure Call
  • the RPC server is used to provide a service interface for the server of the distributed service, so that the client of the distributed service calls the distributed service through the RPC server. Subservices on the server side.
  • the client of the distributed service includes an RPC client.
  • the above method uses at least one code generation tool to obtain the calling code of the distributed service based on multiple markers, including: using an RPC client code generation tool to obtain the RPC client based on multiple markers, where the RPC client calls the RPC server to Get the subservices on the server side of the distributed service.
  • the server of the distributed service includes multiple replicas
  • the client of the distributed service includes replica clients.
  • the above method of using at least one code generation tool to obtain the calling code of the distributed service based on multiple markers includes: using a replica client code generation tool to obtain a replica client based on multiple tags, where the replica client is used to indicate calling multiple A subservice on one of the replicas.
  • each copy includes an RPC server, and the copy clients include multiple RPC clients.
  • Each RPC client corresponds to an RPC server, which is equivalent to one RPC client corresponding to one RPC server. copy.
  • one RPC client among multiple RPC clients can be called through the replica client, and then the RPC client calls the corresponding RPC server, thereby calling the sub-service on the replica corresponding to the RPC server.
  • the server of the distributed service includes multiple shards
  • the client of the distributed service includes a shard client.
  • the above method of using at least one code generation tool to obtain the calling code of the distributed service based on multiple markers includes: using a shard client code generation tool to obtain the shard client based on multiple markers, where the shard client is used to indicate Call a subservice on at least one shard among multiple shards.
  • each shard can have at least one replica.
  • the shard client includes at least one replica client, and each replica client corresponds to one shard.
  • the shard client calls some or all of the replica clients in at least one replica client, and then some or all of the replica clients call the RPC clients under it, and then the RPC client calls the corresponding RPC server.
  • the service on the replica of the corresponding shard can have at least one replica.
  • the client of the distributed service includes a cluster client.
  • the above method uses at least one code generation tool to obtain the calling code of the distributed service based on multiple markers, including: using a cluster client code generation tool to obtain the cluster client based on multiple markers, wherein the cluster client is used to obtain the distributed service The status information of the server, and create an instance of the client of the distributed service based on the status information. In this way, the effectiveness of clients of distributed services can be guaranteed.
  • the cluster client can call the shard client, replica client or RPC client.
  • the cluster client calls the shard client; in the multi-replica scenario, the cluster client calls the replica client; when the server of the distributed service is not deployed as multiple shards and In the scenario of multiple replicas, that is, the clients of distributed services do not include shard clients and replica clients.
  • the cluster client calls the RPC client.
  • the above method further includes: debugging the distributed service according to the calling code of the distributed service. In this way, it is convenient for users to locate and correct faults in the relevant codes of distributed services.
  • embodiments of the present application provide a distributed service generation system, which includes an acquisition unit and a compilation unit.
  • the acquisition unit is used to obtain the program source code of the application.
  • the program source code of the application includes multiple tags.
  • the multiple tags include a first tag used to tag the sub-application module in the application and a first tag used to tag the interface method in the sub-application module.
  • the second tag; the compilation unit is used to compile the application program source code according to multiple tags to obtain the distributed service corresponding to the sub-application module.
  • the distributed service includes the interface method implemented when the corresponding sub-application module is executed. subservice.
  • the above-mentioned compilation unit is used to compile the program source code of the application to obtain the business logic of the application; use at least one code generation tool to obtain the calling code of the distributed service according to multiple tags , among which, the calling code of the distributed service is used to instruct the client of the distributed service to call the sub-service on the server side of the distributed service; the framework code that associates the application's business logic, the calling code of the distributed service and the distributed service Combine them to get distributed services.
  • the above compilation unit is used to use an RPC server code generation tool to obtain an RPC server based on multiple tags, where the RPC server is used to provide a distributed service server
  • the service interface enables the client of the distributed service to call the sub-services on the server of the distributed service through the RPC server.
  • the client of the distributed service includes an RPC client.
  • the above-mentioned compilation unit is used to use the RPC client code generation tool to obtain the RPC client according to multiple tags, wherein the RPC client obtains the sub-services on the server of the distributed service by calling the RPC server.
  • the server of the distributed service includes multiple replicas
  • the client of the distributed service includes replica clients.
  • the above compilation unit is used to use a replica client code generation tool to obtain a replica client according to multiple tags, where the replica client is used to instruct a subservice on one of the multiple replicas to be called.
  • the server of the distributed service includes multiple shards
  • the client of the distributed service includes a shard client.
  • the above compilation unit is used to use a shard client code generation tool to obtain a shard client based on multiple tags, where the shard client is used to instruct to call a sub-service on at least one shard among the multiple shards.
  • the client of the distributed service includes a cluster client.
  • the above compilation unit is used to use the cluster client code generation tool to obtain the cluster client based on multiple tags.
  • the cluster client is used to obtain the status information of the server of the distributed service and create a client of the distributed service based on the status information. end instance.
  • system further includes a debugging unit, where the debugging unit is used to debug the distributed service according to the calling code of the distributed service.
  • inventions of the present application provide a computing device.
  • the computing device includes a processor and a memory.
  • the processor executes the computer program code in the memory to implement the aforementioned first aspect and any implementation manner of the first aspect. Describe some or all of the methods.
  • embodiments of the present application provide a computer-readable storage medium.
  • the computer storage medium stores computer program code.
  • the computer program code is executed by a computing device, the computing device executes the first aspect and the first aspect. Any implementation of aspects describes some or all of the methods.
  • inventions of the present application provide a computer program product.
  • the computer program product may be a software or program product that contains instructions and can be run on a computing device or stored in any available medium.
  • the computer program product is run on at least one computing device, at least one computing device is caused to execute part or all of the method described in the foregoing first aspect and any implementation of the first aspect.
  • Figure 1 is a schematic diagram of an application scenario of a distributed service generation system provided by an embodiment of the present application
  • Figure 2 is a schematic structural diagram of a distributed service provided by an embodiment of the present application.
  • Figure 3 is a schematic flowchart of a distributed service generation method provided by an embodiment of the present application.
  • Figure 4 is a relationship diagram between service codes of application services in a distributed service provided by an embodiment of the present application
  • Figure 5 is a relationship diagram between service codes of application services in another distributed service provided by the embodiment of the present application.
  • Figure 6 is a relationship diagram between service codes of application services in another distributed service provided by the embodiment of the present application.
  • Figure 7 is a relationship diagram between service codes of application services in another distributed service provided by the embodiment of the present application.
  • Figure 8 is a relationship diagram between service codes of application services in another distributed service provided by the embodiment of the present application.
  • Figure 9 is a schematic structural diagram of a distributed service corresponding to an application Map provided by an embodiment of the present application.
  • Figure 10 is a schematic structural diagram of a distributed service corresponding to another application Map provided by an embodiment of the present application.
  • Figure 11 is a schematic structural diagram of a distributed service corresponding to another application Map provided by an embodiment of the present application.
  • Figure 12 is a schematic structural diagram of a distributed service generation system provided by an embodiment of the present application.
  • Figure 13 is a schematic structural diagram of a computing device provided by an embodiment of the present application.
  • a monolithic application refers to an application that integrates modules with different functions into one process. Although it divides the functions of modules in the logical architecture, it is physically tightly coupled. This results in a single application being developed as a whole and deployed to specific hardware devices. Implement corresponding functions. Monolithic applications have the advantage of being easy to develop and debug. However, as the scale of applications continues to expand, monolithic applications also expose more and more problems, such as: low reliability (that is, a failure of a module may spread to affect The entire application), high maintenance and upgrade costs, and poor scalability.
  • service-oriented transformation includes transforming different modules of a single application into independent application services (such as microservices).
  • Application services can be understood as small services composed of a single application, responsible for an independent business logic and completing the application part of the function.
  • application services can be built and deployed separately, which decouples the various application services included in the application from each other and can be independently replaced, upgraded, and scalable. This not only helps developers update and maintain applications, but also allows developers to update and maintain applications when a single application service appears. In the event of a failure, other application services can still continue to work, improving application reliability.
  • Each application service in the application works together to realize the functions of the application. In other words, there is a need for communication between each application service.
  • the RPC framework is a framework that implements the RPC protocol.
  • the RPC protocol is a protocol that requests services from a remote computer program through the network without knowing the underlying network technology. Therefore, using the RPC framework allows the client to call the remote service interface just like calling a local function.
  • the RPC framework mainly consists of four parts: server, RPC server, RPC client, and client.
  • the server is the service provider;
  • the RPC server is used to provide a service interface for the service on the server so that it can be called by the client;
  • the RPC client is used to call the service on the server through the RPC server, and Return the result to the client so that the client can obtain the service;
  • the client is the caller of the service.
  • the client when the client wants to call the service on the server, the client will first call the RPC client, so that the RPC client initiates a service call request to the RPC server, and the RPC server receives the service from the RPC client.
  • the control server After calling the request, the control server implements the corresponding service and returns the service to the client via the RPC client. In this way, through the RPC client and RPC server, the client and server will not be able to perceive the specific process and communication details when the service is called.
  • serialization refers to serializing the data to be transmitted into a byte array for network transmission
  • deserialization refers to restoring the byte array read from the network into the original object (i.e. the above-mentioned data to be transmitted). ) to facilitate subsequent business logic operations.
  • the gRPC framework is a high-performance, general-purpose open source RPC framework. It is developed based on the ProtoBuf serialization protocol and supports multiple development languages (such as Java and C language).
  • the server i.e., the provider of the above service
  • the client i.e., the above service
  • the caller needs to call the function in the above code to realize the remote call of the service.
  • the gRPC framework can realize communication between various application services, for a complex distributed service, the application service will be deployed in the form of a cluster (that is, the application service itself is also a distributed service).
  • the application service includes Multiple shards and replicas, while the gRPC framework can only solve the communication between RPC client and RPC server, but cannot solve the problem of calling shards and replicas in application services.
  • the Dubbo framework is a high-performance, lightweight open source RPC framework that provides functions such as remote method invocation, fault tolerance and load balancing, automatic service registration, and automatic service discovery.
  • a service registration center such as ZooKeeper
  • the server that is, the provider of the above services
  • the service registration center will also push relevant information of the server to the client to facilitate the client to call remote services.
  • the service interface and service implementation class need to be configured on the server side, and the service interface class that needs to be called is configured on the client side. In this way, the client can get an encapsulated service interface instance and call the remote end like a local call. services.
  • the Dubbo framework proposes corresponding solutions for the invocation of shards and replicas in application services.
  • the application layer protocol used between the client and the server is a private protocol, and the application service
  • HTTP hyper text transfer protocol
  • the framework is based on Java's reflection mechanism to generate clients, this will increase the difficulty of fault location and code debugging of distributed services.
  • the Spring Cloud framework provides a one-stop solution for microservice development.
  • the framework includes various toolkits, such as: configuration management, message bus, service registration and discovery, routing, gateway, security control and circuit breaker, etc.
  • this framework proposes corresponding solutions for the invocation of shards and replicas in application services;
  • this framework uses the HTTP protocol as the application layer protocol between the client and the server; but This framework is also based on Java's reflection mechanism to generate clients, so it is difficult to achieve fault location and code debugging for distributed services developed using this framework.
  • embodiments of the present application provide a distributed service generation system that can deploy applications into distributed services.
  • the system is also based on the RCP framework to implement inter-service calls.
  • it can also generate code for implementing inter-service calls, which is quite It abstracts the complex implementation of distributed services into the system. In other words, using this system can reduce the user's workload of handwritten code and reduce the difficulty and cost of developing distributed services.
  • using the code generated above can also help fault location and debugging of distributed services.
  • the above-mentioned distributed service generation system can be a compilation auxiliary tool or a software development kit.
  • Figure 1 exemplarily shows a schematic diagram of the application scenario of the distributed service generation system.
  • the user divides the application into at least one sub-application module based on the functions that the application to be developed wants to implement, and determines the interface methods in each sub-application module.
  • the sub-application module refers to the functional module in the application, which can be used to implement part of the functions of the application;
  • the interface method refers to the method in the sub-application module that can be called by other sub-application modules. Specifically, it can be one function or multiple Function composition method.
  • the above determined sub-application modules and the interface methods in the sub-application modules are marked in the application program source code, and the above-mentioned marked program source code is compiled using the distributed service generation system provided by the embodiment of the present application.
  • the above-mentioned distributed service generation system will automatically identify the tags in the program source code, and compile each sub-application module in the application into the corresponding distributed service based on the tags, thereby deploying the application into the corresponding distributed service. Serve.
  • sub-application module is a logical concept.
  • users can follow the rules of "high cohesion within sub-application modules and low coupling between sub-application modules” according to functions (i.e. sub-application modules).
  • the internal connections within the module are tight and the degree of coupling between sub-application modules is low), and the application to be developed is divided into at least one sub-application module.
  • an application can be deployed into a distributed service 100 as shown in Figure 2 using the above-mentioned distributed service generation system.
  • the distributed service 100 includes at least one application service 110 ( Figure 2 takes application service A and application service B as an example) and a cluster management node 120.
  • the application service 110 corresponds to the sub-application module in the application, that is, after the application is deployed as a distributed service 100, each sub-application module in the application is deployed as a corresponding application service 110.
  • Each application service 110 in the distributed service 100 may be deployed on different computing nodes, or two or more may be deployed on the same computing node.
  • the computing nodes on which the application services 110 are deployed may include servers, virtual machines, etc. (virtual machine, VM), container (container), etc.
  • each application service 110 in the distributed service 100 also needs to communicate with each other.
  • the above-mentioned at least one application service 110 can be implemented through RPC. Communication (i.e. remote service calls).
  • the application service 110 includes at least one sub-service implemented when the above-mentioned at least one interface method is executed, wherein one interface method corresponds to one sub-service, that is, executing one The interface method implements a subservice.
  • the application service 110 is also a distributed service. As shown in Figure 2, the application service 110 includes a server and a client. The server of the application service 110 and the client of the application service 110 are deployed on different computing nodes. Superior. Among them, the server of the application service 110 is the service provider and is used to provide at least one sub-service included in the application service 110; the client of the application service 110 is the caller of the service and is used to call the service provided by the server of the application service 110. At least one subservice above.
  • application service B wants to call a sub-service on application service A
  • application service B needs to first send a service call request to the client of application service A, and then call it from the client of application service A.
  • the server of application service A provides corresponding sub-services to application service B.
  • the server of the application service 110 includes an RPC server.
  • the RPC server is used to provide at least one service interface for the above-mentioned at least one sub-service, and one sub-service corresponds to one service interface, and the sub-service can be called through the corresponding service interface.
  • Clients of the application service 110 include RPC clients.
  • the RPC client is used to call the RPC server to obtain at least one of the above sub-services.
  • the server of application service A can provide service 1 and service 2
  • the RPC server of application service A will provide the service interface of service 1 (hereinafter referred to as service interface 1) and the service interface of service 2 (hereinafter referred to as service interface 1).
  • the RPC client of application service A includes code for calling service interface 1, and code for calling service interface 2.
  • the client of application service A wants to call service 1
  • the client of application service A calls the service interface 1 provided by the RPC server through the RPC client, so that the server of application service A executes the interface method corresponding to service 1 , in this way, the server of application service A can provide service 1 to the client of application service A.
  • the server side of the application service 110 includes multiple replicas, where each replica is used to provide at least one of the above sub-services.
  • each of the multiple copies This includes an RPC server, and the clients of the application service 110 include replica clients.
  • the replica client includes multiple RPC clients, and each RPC client corresponds to an RPC server, which is equivalent to one RPC client corresponding to one replica.
  • the replica client can be used to indicate which sub-service among the multiple replicas mentioned above is to be called. That is, the replica client calls one RPC client among multiple RPC clients, and then the RPC client calls the corresponding RPC client. RPC server, thereby calling the subservice on the copy corresponding to the RPC server.
  • the server side of the application service 110 may include multiple shards, where each shard is used to provide one or more sub-services among the above-mentioned at least one sub-service.
  • each shard is used to provide one or more sub-services among the above-mentioned at least one sub-service.
  • Serve In a multi-shard scenario, how to determine which shard service needs to be called, and how to implement the call?
  • the embodiment of this application proposes that the client of the application service 110 may also include a shard client, where the shard client is used to indicate which sub-service on which shard or shards among the above-mentioned multiple shards is to be called.
  • each shard may have at least one replica (hereinafter, a shard replica is simply referred to as a shard replica), that is, shard replicas of the same shard provide the same service.
  • a shard replica is simply referred to as a shard replica
  • the embodiment of the present application proposes that the shard client includes multiple replica clients, and each replica client corresponds to a shard, where the shard client is used to indicate which of the above multiple shards or shards to call.
  • Which sub-services on the shards are used by the replica client to indicate which service on which shard replica in a shard is called, that is: the shard client calls at least one replica client among multiple replica clients, and then at least one replica client is called.
  • a replica client calls the RPC client under it respectively, and then the RPC client calls the corresponding RPC server, thereby calling the service on the corresponding shard replica.
  • the client of the application service 110 also includes a cluster client.
  • the cluster client establishes a connection (such as a heartbeat connection) with the cluster management node 120 to obtain the status information of the server of the application service 110 from the cluster management node 120, and creates a client of the application service 110 based on the obtained status information. (including at least one of a shard client, a replica client, and an RPC client), so that the validity of the client of the application service 110 can be guaranteed.
  • the cluster management node 120 will store the sharding configuration information of the server of application service A (that is, the server of application service A includes 2 shards, each shard has 5 replicas), the cluster client of application service A can obtain the above-mentioned sharding configuration information from the cluster management node 120, and create an instance of the sharding client, two replica client instances, and 10 RPC clients based on the sharding configuration information. client instance, thereby creating a shard client, 2 replica clients, and 10 RPC clients.
  • the cluster management node 120 When the number of shards on the server side of application service A increases to 3, the cluster management node 120 will promptly update the locally stored shard configuration information on the server side of application service A (at this time, the server side of application service A includes 3 shards). , each shard has 5 copies).
  • the cluster client will also obtain the updated shard configuration information in time, and re-create the client instance of application service A based on the updated shard configuration information, that is: Instances of the shard client, 3 instances of the replica client, and 15 instances of the RPC client, creating a shard client, 3 replica clients, and 15 RPC clients.
  • the cluster client is also used to receive service invocation requests sent by cluster clients of other application services 110, or send service invocation requests to cluster clients of other application services 110, so as to realize communication between different application services 110.
  • Service call For example: when application service B wants to call the sub-services included in application service A (such as service 1 or service 2), the cluster client of application service B will send a service call request to the cluster client of application service A. The application service After receiving the above service call request, A's cluster client calls the shard client, replica client and RPC client in sequence, and then the RPC client calls the corresponding RPC server, thereby calling the application corresponding to the RPC server. Service on the server side of service A.
  • the cluster management node 120 is used to register services and discover services.
  • the service here includes at least one sub-service included in the application service 110 .
  • “Registration service” refers to the server end of application service 110 in the cluster management
  • the management node 120 registers the services it can provide, such as the service name, service interface, service address, etc. of the registered service.
  • "Discovering services” means that the client of the application service 110 determines the provider of the service it wants to call from the cluster management node 120 .
  • the server of application service A can provide service 1 and service 2
  • the server of application service B can provide service 3.
  • the server of application service A will register the services of service 1 and service 2 with the cluster management node 120. name, service interface, service address and other information.
  • the service of application service B will register the service interface of service 3 with the cluster management node 120.
  • application service B When application service B wants to call service 1, application service B will determine the service interface from the cluster management node 120.
  • the provider of service 1 (that is, the server of application service A) calls service 1 provided by the server of application service A through the service interface of service 1.
  • Application program source code refers to uncompiled text files written in accordance with certain programming language (such as Java, C language) specifications and used to implement specific functions (that is, the functions that users expect the application to implement). It is a series of Human-readable computer language instructions.
  • the program source code of the application includes multiple tags.
  • each tag in the multiple tags can be an annotation for a certain program source code (such as a Java annotation), or a predetermined set of tags adjacent to a certain program source code.
  • the program code of the grammar, the predetermined grammar refers to the grammar that can be recognized by the distributed service generation system.
  • the plurality of tags include a first tag used to tag a sub-application module in the application and a second tag used to tag an interface method in the sub-application module.
  • the definitions of sub-application modules and interface methods can be found in the relevant descriptions in Figure 1.
  • a first mark is used to mark a sub-application module
  • a second mark is used to mark an interface method
  • multiple The number of first markers and the number of second markers in the markers may be one or more.
  • the first mark may be an annotation added at an adjacent position of the program source code corresponding to the sub-application module, for example: adding a corresponding annotation to the previous or next line of the program source code used to define the sub-application module;
  • the first mark may also be a program code using a predetermined syntax added at an adjacent position of the program source code corresponding to the sub-application module, for example: in the previous line or the same line of the program source code used to define the sub-application module.
  • the second mark can be an annotation added at an adjacent position of the program source code corresponding to the interface method, for example: adding a corresponding annotation on the previous or next line of the program source code used to define the interface method; or, the second The tag can also be program code using predetermined syntax that is added adjacent to the program source code corresponding to the interface method. For example, add a paragraph to predetermine the previous line or the end of the same line of the program source code used to define the interface method. Program code written in syntax.
  • the distributed service generation system can obtain the program source code of the application in one or more of the following ways:
  • the distributed service generation system provides a file upload interface (such as application programming interface (API) or user interface (UI)). Users can use the file upload interface to write the program code of the application. Upload to the distributed service generation system, so that the distributed service generation system can obtain the program source code of the application.
  • API application programming interface
  • UI user interface
  • Method 2 The distributed service generation system provides an online programming interface (such as API or UI), through which users can write application program source code on the distributed service generation system.
  • API application program source code
  • the distributed service generation system can also prompt the user to add a first mark to the sub-application module in the application and a second mark to the interface method in the sub-application module when the user writes the program source code of the application.
  • S102 Compile the program source code of the application according to multiple tags to obtain the application service 110 corresponding to each sub-application module in the application, thereby obtaining the distributed service 100 corresponding to the application.
  • the application service 110 is also a distributed service
  • “get the "The application service 110 corresponding to each sub-application module” is equivalent to “obtaining the distributed service corresponding to each sub-application module in the application”.
  • the "distributed service corresponding to the sub-application module” is called “the application service 110 corresponding to the sub-application module”.
  • the distributed service generation system compiles the program source code of the application according to multiple tags to obtain the application service 110 corresponding to each sub-application module in the application, thereby obtaining the distributed service 100 corresponding to the application, including: distribution
  • the service generation system compiles the application program source code and obtains the application's business logic.
  • Use at least one code generation tool to obtain the calling code of at least one application service 110 based on the above-mentioned plurality of marks, wherein the calling code of each application service 110 is used to instruct the client of the application service 110 to call the server of the application service 110
  • the sub-services on the server may specifically include at least one of the RPC server, RPC client, replica client, shard client and cluster client described above.
  • the business logic of the application, the calling code of at least one application service 110 and the framework code associated with at least one application service 110 are combined to obtain the above-mentioned at least one application service 110, thereby obtaining the distributed service 100 corresponding to the application, wherein at least The framework code associated with an application service 110 includes: in addition to the business logic of the application and the calling code of at least one application service 110, code related to implementing the function of at least one application service 110, for example: used to implement the cluster management node 120 Code with functions, code for realizing data synchronization between multiple copies, code for realizing data migration, etc.
  • the framework code associated with at least one of the above application services 110 can be provided in advance by the developer of the distributed service generation system , or it can be provided by the above-mentioned users to the distributed service generation system. In this way, it is equivalent to decoupling the business logic of the application and the complex implementation of the distributed service 100 (including the calling process between each application service 110 in the distributed service 100), and realizing the distributed service 100 by the distributed service generation system. complex implementation, thereby simplifying the user's work (including the user not needing to write the calling code of at least one of the above application services 110), and reducing the difficulty and cost of deploying applications into distributed services 100.
  • the above-mentioned at least one code generation tool is provided by the distributed service generation system and is used to identify multiple tags in the program source code of the application and generate the calling code of at least one application service 110 based on the multiple tags.
  • the multiple tags are Java
  • at least one of the above code generation tools can be a tool that comes with Java (i.e. AbstractProcessor). This tool can intercept annotations in the code. Developers of the distributed service generation system can further develop this tool so that it can also The function of generating at least one calling code of the application service 110 according to the intercepted annotations, thereby obtaining at least one code generation tool in this embodiment.
  • the distributed service generation system uses at least one code generation tool to obtain the calling code of at least one application service 110 based on the above multiple tags, including one or more of the following implementations:
  • At least one code generation tool includes an RPC server code generation tool
  • the plurality of tags include parameters used to indicate generating at least one RPC server.
  • the above steps include: the distributed service generation system uses an RPC server code generation tool to obtain at least one RPC server based on the above multiple tags.
  • each RPC server is used to provide a service interface for the server of the corresponding application service 110, specifically to provide a corresponding service interface for each sub-service in the application service 110, so that the client of the application service 110 can The subservices on the server side of the application service 110 are called through the RPC server side.
  • the distributed service generation system uses the RPC server code generation tool to determine multiple tags from the application program source code, and then generates at least one RPC service based on the instructions in the multiple tags. parameters of the server to obtain the program source code corresponding to at least one RPC server, and then compile the program source code corresponding to at least one RPC server to obtain the above-mentioned at least one RPC server.
  • each RPC server is executable code.
  • the executable code is code obtained by compiling the program source code and can be loaded and executed by a processor (such as a central processing unit (CPU)). .
  • At least one code generation tool includes an RPC client code generation tool, and multiple tags include instructions for Generate at least one RPC client parameter. Then, the above steps include: the distributed service generation system uses an RPC client code generation tool to obtain at least one RPC client based on the multiple tags mentioned above. Each RPC client is used to call the corresponding RPC server to obtain subservices on the server of the application service 110 corresponding to the RPC server.
  • the distributed service generation system uses the RPC client code generation tool to determine multiple tags from the application program source code, and then generates at least one RPC client based on the instructions in the multiple tags. parameters of the client to obtain the program source code corresponding to at least one RPC client, and then compile the program source code corresponding to the at least one RPC client to obtain the above-mentioned at least one RPC client.
  • at least one of the above RPC clients is executable code.
  • At least one code generation tool includes a copy client code generation tool, and the plurality of tags include parameters used to indicate generating at least one copy client. Then, the above steps include: the distributed service generation system uses a replica client code generation tool to obtain at least one replica client based on the multiple tags. Each replica client is used to instruct to call a sub-service on one of the multiple replicas when the server of the corresponding application service 110 includes multiple replicas.
  • the distributed service generation system uses a replica client code generation tool to determine multiple tags from the program source code of the application, and then generates at least one replica client based on the instructions in the multiple tags. parameters of the client to obtain the program source code corresponding to at least one replica client, and then compile the program source code corresponding to the at least one replica client to obtain the above-mentioned at least one replica client.
  • at least one of the above replica clients is executable code.
  • At least one code generation tool includes a shard client code generation tool, and the plurality of tags include parameters used to indicate generating at least one shard client. Then, the above steps include: the distributed service generation system uses a shard client code generation tool to obtain at least one shard client based on the multiple tags mentioned above. Each shard client is used to instruct to call a sub-service on at least one shard among the multiple shards when the server of the corresponding application service 110 includes multiple shards.
  • the distributed service generation system uses the fragment client code generation tool to determine multiple tags from the application program source code, and then generates at least one fragment based on the instructions in the multiple tags. parameters of the shard client to obtain the program source code corresponding to at least one shard client, and then compile the program source code corresponding to the at least one shard client to obtain at least one shard client.
  • at least one of the above-mentioned shard clients is executable code.
  • At least one code generation tool includes a cluster client code generation tool, and the plurality of tags include parameters used to indicate generating at least one cluster client. Then, the above steps include: the distributed service generation system uses a cluster client code generation tool to obtain at least one cluster client based on the above multiple tags. Each cluster client is used to obtain the status information of the server of the corresponding application service 110, and create an instance of the client of the application service 110 based on the above status information.
  • the distributed service generation system uses the cluster client code generation tool to determine multiple tags from the application program source code, and then generates at least one cluster client based on the instructions in the multiple tags. parameters of the client to obtain the program source code corresponding to at least one cluster client, and then compile the program source code corresponding to the at least one cluster client to obtain the above-mentioned at least one cluster client.
  • at least one of the above cluster clients is executable code.
  • the service code of the application service 110 includes an RPC server and an RPC client
  • the relationship between the two service codes is: the RPC client calls the RPC server (specifically, it calls the RPC server provided by the RPC server).
  • Service interface so that the server of the application service 110 executes the interface method corresponding to the called service interface, thereby providing the corresponding sub-service to the client of the application service 110.
  • the service code of application service 110 includes RPC server, RPC client and cluster client
  • the relationship between these three service codes is: the cluster client calls the RPC client, and the RPC client calls
  • the RPC server (specifically, calling the service interface provided by the RPC server) causes the server of the application service 110 to execute the interface method corresponding to the called service interface, thereby providing the corresponding sub-service to the client of the application service 110 .
  • the server of the application service 110 includes M copies (ie, copy 1, copy 2, ..., copy M, where M is an integer greater than 1). Therefore, the application service 110
  • the service code includes a replica client, M RPC clients, and M RPC servers.
  • One replica includes one RPC server, and one RPC server corresponds to one RPC client.
  • the service code of the application service 110 since the application service 110 is deployed in the form of a cluster, the service code of the application service 110 also includes a cluster client.
  • the cluster client calls the replica client
  • the replica client determines the replica to be called (assuming it is replica 2)
  • the replica client calls the RPC client corresponding to replica 2
  • the RPC client calls the corresponding RPC server (that is, the RPC server included in copy 2).
  • copy 2 will provide corresponding sub-services to the client of the application service 110.
  • the server of the application service 110 includes N shards (ie, shard 1, shard 2,..., shard N, where N is an integer greater than 1). Therefore, The service code of the application service 110 includes a fragmented client, N RPC servers, and N RPC clients. One fragment includes one RPC server, and one RPC server corresponds to one RPC client.
  • the service code of the application service 110 since the application service 110 is deployed in the form of a cluster, the service code of the application service 110 also includes a cluster client.
  • the cluster client calls the shard client, the shard client determines the shard to be called (assuming it is shard 1), and then the shard client calls the corresponding shard 1
  • the RPC client finally calls the corresponding RPC server (that is, the RPC server included in shard 1). In this way, shard 1 will provide corresponding sub-services to the client of application service 110. .
  • the server of the application service 110 includes N shards (ie, shard 1, shard 2,..., shard N), and each shard includes M copies (ie, copy 1, copy 2,..., copy M).
  • the server of the application service 110 includes M*N shard copies (ie, shard copy 11 (ie, copy 1 under shard 1), Slice copy 12 (that is, copy 2 under shard 1), ..., shard copy 1M (that is, copy M under shard 1), ..., shard copy NM (that is, copy M under shard N)).
  • the service code of the application service 110 includes a cluster client, a shard client, M replica clients, M*N RPC clients, and M*N RPC servers, where one shard corresponds to one replica client.
  • a shard copy includes an RPC server, and one RPC server corresponds to one RPC client.
  • the cluster client calls the shard client, the shard client determines the shard to be called (assuming it is shard 1), and then the shard client calls the corresponding shard 1
  • the copy client (assumed to be copy client 1) determines the copy to be called under shard 1 (assumed to be copy 2) through copy client 1, and then copy client 1 calls the RPC client corresponding to shard copy 12.
  • the RPC client calls the corresponding RPC server (that is, the RPC server included in the shard copy 12).
  • the shard copy 12 will provide corresponding sub-services to the client of the application service 110.
  • the distributed service 100 includes at least one application service 110, and at least one application service 110 can be connected through at least one The calling code of the application service 110 implements the remote calling of the service.
  • the internal application service 110 that is, the client of the application service 110 and the server of the application service 110
  • the distributed service generation system can also perform the following steps:
  • S103 Debug at least one application service 110 according to the service calling code of at least one application service 110, thereby realizing debugging of the distributed service 100.
  • the distributed service generation system debugs at least one application service 110 based on the business logic of the application, the service calling code of at least one application service 110 and the framework code associated with at least one application service 110, thereby achieving the goal of debugging the distributed service 100. debugging purposes.
  • the distributed service generation system can also return debugging results to the user, where the debugging results indicate codes with errors (such as syntax errors, logic errors, etc.). In this way, users can correct the relevant codes based on the debugging results to ensure that Normal operation of distributed services 100.
  • Java is an object-oriented programming language, so its core is an object (also called an instance).
  • the keyword interface is generally used to declare an interface.
  • An interface is a collection of a series of methods, that is, an interface includes one or more methods. Therefore, when users write the program source code of an application in Java, they can add sub-applications in the application. Modules are defined as interfaces, and interface methods in sub-application modules can be defined as interface methods in the corresponding interface.
  • the interface since the interface only declares methods and cannot implement the methods, the interface can be implemented by the class. When the class implements the interface, it can implement all the interface methods described in the interface.
  • sub-application modules defined as interfaces
  • its specific implementation can be defined as a class.
  • users when users use Java to write the program source code of an application, they can also directly define the sub-application modules in the application as classes, and the interface methods in the sub-application modules are defined as methods in the class. But compared with the former method, the former method can make the writing of program source code more concise and clear.
  • Map in the Java standard library is equivalent to a dictionary, used to store objects with mapping relationships (ie, key-value pairs).
  • the methods provided by Map include: put(), get() and size(), among which put() is used to add key-value pairs; get() is used to return the value corresponding to the specified key; size() is used to query the current The number of stored key-value pairs.
  • This embodiment uses the above Map as an application and introduces in detail the process of deploying the Map into a distributed service 100:
  • the application will not be further divided here.
  • the application only includes one sub-application module, and the sub-application module is the application itself.
  • the "application Map” will be referred to as the "sub-application module Map” below. Therefore, when users use Java language to write the program source code of the application, they can define the sub-application module Map as the interface IMap, and define the class used to implement the interface IMap as the class MapImpl. The specific definition method of the interface IMap can be found below. Describe Example 1-Example 3.
  • ClusterService in the above program source code is a predefined interface of the distributed service generation system. Sub-application modules that need to generate the calling code of application service 110 need to implement this interface. Therefore, in the above program source code, the interface IMap is declared to inherit the interface ClusterService. Indicates that the sub-application module Map is a sub-application module that needs to generate the calling code of the application service 110.
  • the above program source code includes two types of tags: @Cluster and @ClusterMethod.
  • the mark @Cluster belongs to the first mark, which is used here to mark the sub-application module Map (ie, the interface IMap); the mark @Cluster Method belongs to the second mark.
  • the interface methods put(), get() and size() in the sub-application module Map.
  • the program source code of the sub-application module Map also includes other parts.
  • the program source code of the sub-application module Map also includes the server side of the sub-application module Map (i.e., the service of the application service 110 in Figure 2 client (hereinafter referred to as MapServer), the client of the sub-application module Map (that is, the client of the application service 110 in Figure 2, hereinafter referred to as MapClient), and the relevant program source code of the class MapImpl that implements the interface IMap.
  • MapServer the server side of the sub-application module Map
  • MapClient the client of the sub-application module Map
  • MapClient the client of the sub-application module Map that implements the interface IMap.
  • the program source code of the sub-application module Map also includes a cluster configuration file, where the cluster configuration file is the code used to implement the functions of the cluster management node 120 in S102.
  • the default parameters of the first tag in the above program source code include parameters used to instruct the generation of an RPC server, parameters used to indicate the generation of an RPC client, parameters used to indicate not to generate a replica client, and parameters used to indicate not to generate a shard client. , and parameters used to indicate the generation of cluster clients. Therefore, during the compilation process of the program source code of the sub-application module Map, multiple code generation tools provided by the distributed service generation system can obtain the RPC server, RPC Clients and cluster clients will not get replica clients and shard clients.
  • the specific process is as follows:
  • the RPC server code generation tool first identifies the mark @Cluster in the source code of the above program, thereby determining that the RPC server needs to be generated for the sub-application module IMap indicated by the mark; then it sequentially identifies the three marks @ClusterMethod in the source code of the above program. , thereby obtaining the RPC server, in which the RPC server is used to provide the service interface of the interface method put() (hereinafter referred to as the put interface), the service interface of the interface method get() (hereinafter referred to as the get interface), and the interface method The service interface of size() (hereinafter referred to as the size interface).
  • the RPC client code generation tool first identifies the mark @Cluster in the source code of the above program, thereby determining that the RPC client needs to be generated for the sub-application module Map indicated by the mark; then it sequentially identifies the three marks @ClusterMethod in the source code of the above program. , thereby obtaining the RPC client, in which the RPC client is used to call the RPC server, which may specifically include: used to call the put interface, get interface and size interface provided by the RPC server, thereby implementing the interface method put(), interface method get(), and calls to the interface method size().
  • the cluster client code generation tool first identifies the mark @Cluster in the above program source code, thereby determining that the cluster client needs to be generated for the sub-application module IMap indicated by the mark; then it identifies three of the above program source codes in sequence Mark @ClusterMethod to get the cluster client.
  • the cluster client is used to call the RPC client so that the RPC client calls an interface provided by the RPC server.
  • the cluster client is also used to read the cluster configuration file and Establish a connection with the cluster management node 120 configured in the cluster configuration file. After the connection is established, obtain the status information of the MapServer from the cluster management node 120, and create an instance of the RPC client based on the status information of the MapServer.
  • the above-mentioned RPC server, RPC client and cluster client are the calling codes of the application service 110 in the above-mentioned S102. Therefore, as shown in Figure 9, the above-mentioned RPC server, RPC client and cluster are obtained in the distributed service generation system After the client, by combining the business logic of the sub-application module Map, the above-mentioned RPC server, RPC client and cluster client, as well as related framework code (including code for realizing the functions of the cluster management node 120), Then the application service 110 corresponding to the sub-application module Map can be obtained, that is, the distributed service 100 corresponding to the application Map.
  • the difference from the program source code given in Example 1 is: 1
  • the sub-application module Map generates a copy client.
  • the interface method put() on the (leader) node and after the leader node executes the interface method put() (that is, the key-value pair is written to the leader node), the follower nodes in multiple copies are notified for data synchronization ( That is, the above key-value is written to the following node).
  • the RPC server code generation tool first identifies the first mark in the above program source code, thereby determining that the RPC server needs to be generated for the sub-application module IMap indicated by the mark; then, it identifies three second marks in the above program source code. , thereby obtaining the RPC server.
  • the RPC server code generation tool is used to generate the put() interface. In addition, it is also used to enable the replica synchronization function in MapServer. Afterwards, the distributed service generation system deploys the RPC server for each replica.
  • the copy client includes code for implementing the following functions: When MapClient needs to call the interface method put(), it will first call the leader node.
  • the interface method put() (specifically, the RPC client corresponding to the leader node is called, and then the RPC client calls the RPC server included in the leader node, thereby realizing the call to the interface method put() on the leader node), the leader After the node executes the interface method put(), it records the key-value pairs into the local write-ahead log, and then notifies the following node to perform data synchronization to write the above key-value pairs to the following node.
  • MapClient When MapClient needs to call the interface method get() or the interface method size, MapClient selects one copy from the above multiple copies according to the load balancing algorithm, and calls the interface method get() or the interface method size on it (specifically, according to The load balancing algorithm calls the RPC client corresponding to a certain copy, and then the RPC client calls the RPC server included in the copy, thereby realizing the call to the interface method get() or size() on the copy).
  • the above-mentioned RPC server, RPC client, replica client and cluster client are the calling codes of the application service 110 in the above-mentioned S102. Therefore, as shown in Figure 10, the above-mentioned RPC server, RPC After the client, replica client and cluster client, by mapping the business logic of the sub-application module, the above-mentioned RPC server, RPC client, replica client and cluster client, as well as related framework code (including those used to implement the cluster), the application service 110 corresponding to the sub-application module Map can be obtained, that is, the distributed service 100 corresponding to the application Map.
  • the difference from the program source code given in Example 2 is: 1
  • the sharding strategy is a consistent hashing strategy, which means that a sharding client needs to be generated for the sub-application module Map.
  • the second mark used to mark the interface method size() in Example 3 also includes the parameter "TRAVERSE", which is used to indicate that when MapClient needs to call the interface method size(), it will call the copies of all shards of MapServer at the same time.
  • MapServer includes 2 shards (shard 1 and 2), and each shard includes 2 copies (copy 1 and copy 2), then the parameter "TRAVERSE" is used to indicate that the interface method size needs to be called in MapClient (), the interface method size() on copy 1 under shard 1 (or copy 2 under shard 1) and copy 1 under shard 2 (or copy 2 under shard 2) will be called at the same time; After copy 1 under shard 1 (or copy 2 under shard 1) executes the interface method size(), the number of key-value pairs stored in the shard copy is obtained.
  • multiple code generation tools provided by the distributed service generation system can obtain the RPC server, RPC client, Replica clients, shard clients, and cluster clients. Among them, the process of obtaining RPC client, RPC server, replica client and cluster client by the distributed service generation system is similar to the above example 2, so it will not be described here. Only the points obtained by the distributed service generation system are given below.
  • the process of slice client is described:
  • the sharded client includes code for implementing the following functions: MapClient needs to call the interface method size() When, the interface method size() on the copies of all shards of MapServer will be called at the same time (specifically, the copy client corresponding to each shard will be called at the same time, and then each copy client will call any RPC client under it. , and then call the RPC server included in each shard copy to implement the call to the interface method size() on the shard copy), and after all the above shard copies execute the interface method size(), execute The results are summarized and the summary results are returned to MapClient.
  • MapClient When MapClient needs to call the interface method put() or get(), it determines a shard from multiple shards based on the consistent hash algorithm and key identification (i.e. "@Id"), and calls the next shard under the shard.
  • the interface method put() or get() on a replica (specifically, the replica client corresponding to the shard is called, and then the replica client calls an RPC client under it, and then calls the corresponding RPC service end, thereby implementing the call to the interface methods put() and get() on a copy under the shard).
  • the above RPC server, RPC client, replica client, shard client and cluster client are the calling codes of the application service 110 in the above S102. Therefore, as shown in Figure 11, the above is obtained in the distributed service generation system After the RPC server, RPC client, replica client, shard client and cluster client, by mapping the business logic of the sub-application module, the above-mentioned RPC server, RPC client, replica client, shard client and By combining the cluster client and related framework code (including code for realizing the functions of the cluster management node 120, code for realizing data synchronization between multiple copies, and code for realizing data migration), the sub-system can be obtained.
  • the application service 110 corresponding to the application module Map is the distributed service 100 corresponding to the application Map.
  • Figure 12 exemplarily shows a schematic structural diagram of the above distributed service generation system.
  • the distributed service generation system 200 includes an acquisition unit 210 and a compilation unit 220.
  • the system also includes a debugging unit 230.
  • the acquisition unit 210, the compilation unit 220 and the debugging unit 230 work together to implement the steps performed by the distributed service generation system in the above method embodiment.
  • the acquisition unit 210 is used to execute the above S101;
  • the compilation unit 220 is used to execute the above S102;
  • the debugging unit 230 is used to execute the above S103.
  • the acquisition unit 210, the compilation unit 220 and the debugging unit 230 can all be implemented by software, or can be implemented by hardware. Illustratively, the following takes the acquisition unit 210 as an example to introduce the implementation of the acquisition unit 210 . Similarly, the implementation of the compilation unit 220 and the debugging unit 230 may refer to the implementation of the acquisition unit 210 .
  • the acquisition unit 210 may include code running on a computing instance.
  • the computing instance may include at least one of a physical host (computing device), a virtual machine, and a container.
  • the above computing instance may be one or more.
  • the acquisition unit 210 may include code running on multiple hosts/virtual machines/containers. It should be noted that multiple hosts/virtual machines/containers used to run the code can be distributed in the same region (region) or in different regions. Further, multiple hosts/virtual machines/containers used to run the code can be distributed in the same availability zone (AZ) or in different AZs. Each AZ includes one data center or multiple AZs. geographically close data centers. Among them, usually a region can include multiple AZs.
  • VPC virtual private cloud
  • multiple hosts/virtual machines/containers used to run the code can be distributed in the same virtual private cloud (VPC) or across multiple VPCs.
  • VPC virtual private cloud
  • Cross-region communication between two VPCs in the same region and between VPCs in different regions requires a communication gateway in each VPC, and the interconnection between VPCs is realized through the communication gateway. .
  • the acquisition unit 210 may include at least one computing device, such as a server.
  • the acquisition unit 210 may also be a device implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD).
  • ASIC application-specific integrated circuit
  • PLD programmable logic device
  • the above-mentioned PLD can be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a general array logic (generic array logic, GAL), or any combination thereof.
  • CPLD complex programmable logical device
  • FPGA field-programmable gate array
  • GAL general array logic
  • Multiple computing devices included in the acquisition unit 210 may be distributed in the same region or in different regions.
  • the multiple computing devices included in the acquisition unit 210 may be distributed in the same AZ or in different AZs.
  • multiple computing devices included in the acquisition unit 210 may be distributed in the same VPC or in multiple VPCs.
  • the plurality of computing devices may be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, and GALs.
  • the acquisition unit 210 can be used to perform any of the steps in S101-S103
  • the compilation unit 220 can be used to perform any of the steps in S101-S103
  • the debugging unit 230 can be used to perform
  • the steps that the acquisition unit 210, the compilation unit 220, and the debugging unit 230 are responsible for implementing can be specified as needed.
  • the above-mentioned distributed service generation method is implemented through the acquisition unit 210, the compilation unit 220, and the debugging unit 230 respectively. (Including the above-mentioned S101-S103) different steps to realize all functions of the distributed service generation system.
  • computing device 300 includes bus 310 , processor 320 , memory 330 , and communication interface 340 .
  • the processor 320, the memory 330 and the communication interface 340 communicate through the bus 310.
  • Computing device 300 may be a server or a terminal device. It should be understood that the embodiments of the present application do not limit the number of processors and memories in the computing device 300.
  • the bus 310 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc.
  • the bus can be divided into address bus, data bus, control bus, etc. For ease of presentation, only one line is used in Figure 13, but it does not mean that there is only one bus or one type of bus.
  • Bus 310 may include a path that carries information between various components of computing device 300 (eg, memory 330, processor 320, communication interface 340).
  • the processor 320 may include any one or more of a CPU, a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP). .
  • the memory 330 may include volatile memory, such as random access memory (RAM).
  • RAM random access memory
  • the processor 320 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD) or solid state drive (solid state drive). drive, SSD).
  • ROM read-only memory
  • HDD hard disk drive
  • SSD solid state drive
  • the memory 330 stores executable program code, and the processor 320 executes the executable program code to realize the functions of the aforementioned acquisition unit 210, the compilation unit 220, and the debugging unit 230 respectively, thereby realizing the distributed service generation method described above. (Including S101-S103 above). That is, the memory 330 stores instructions for executing the distributed service generation method described above.
  • the communication interface 340 uses transceiver modules such as, but not limited to, network interface cards and transceivers to implement communication between the computing device 300 and other devices or communication networks.
  • An embodiment of the present application also provides a computer program product containing instructions.
  • the computer program product may be a software or program product containing instructions capable of running on a computing device or stored in any available medium.
  • the computer program product is run on at least one computing device, at least one computing device is caused to execute the distributed service generation method described above.
  • An embodiment of the present application also provides a computer-readable storage medium.
  • the computer-readable storage medium may be any available media that a computing device can store or a data storage device such as a data center that contains one or more available media, where the available media may be magnetic media (eg, floppy disks, hard disks, tapes) , optical media (such as DVD), or semiconductor media (such as solid-state hard drive), etc.
  • the computer-readable storage medium includes instructions, wherein the instructions instruct the computing device to perform the distributed service generation method described above, or instruct the computing device to perform the distributed service generation method described above.

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)
  • Multi Processors (AREA)

Abstract

本申请提供了一种分布式服务生成方法、系统、计算设备及存储介质,其中,该分布式服务生成方法包括以下步骤:获取应用的程序源码,应用的程序源码包括多个标记,多个标记包括用于标记应用中的子应用模块的第一标记和用于标记子应用模块中的接口方法的第二标记。然后,根据上述多个标记对应用的程序源码进行编译,得到应用中的各个子应用模块对应的分布式服务。如此,可以将应用部署成分布式服务。

Description

分布式服务生成方法、系统、计算设备及存储介质
本申请要求于2022年7月13日提交中国专利局、申请号为202210820850.0、申请名称为“分布式服务生成方法、系统、计算设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及分布式服务领域,尤其涉及一种分布式服务生成方法、系统、计算设备及存储介质。
背景技术
随着应用规模的不断增长,一个应用往往需要部署成相应的分布式服务。目前,通常使用gRPC、Dubbo、Spring Cloud等框架将应用部署成分布式服务,但gRPC框架的功能较为欠缺,无法满足分布式服务对于多分片或多副本的需求,而Dubbo框架和Spring Cloud框架存在增加分布式服务的调试难度等问题。因此,如何将应用部署成分布式服务仍然是一个急需解决的问题。
发明内容
本申请提供了一种分布式服务生成方法、系统、计算设备及存储介质,能够将应用部署成分布式服务。
第一方面,本申请实施例提供了一种分布式服务生成方法,该方法包括:获取应用的程序源码,其中,应用的程序源码包括多个标记,多个标记包括用于标记应用中的子应用模块的第一标记和用于标记子应用模块中的接口方法的第二标记。然后,根据多个标记对应用的程序源码进行编译,得到子应用模块对应的分布式服务,其中,该分布式服务包括与其对应的子应用模块中的接口方法被执行时所实现的子服务。应理解,将应用中的各个子应用模块部署成分布式服务后,该应用也就部署成了相应的分布式服务。
在第一方面的一种可能的实现方式中,上述根据多个标记对应用的程序源码进行编译,得到子应用模块对应的分布式服务,包括:对应用的程序源码进行编译,获得应用的业务逻辑;使用至少一个代码生成工具,根据多个标记得到分布式服务的调用代码,其中,分布式服务的调用代码用于指示分布式服务的客户端调用分布式服务的服务端上的子服务;将应用的业务逻辑、分布式服务的调用代码和分布式服务关联的框架代码进行组合,得到上述分布式服务。通过上述实现方式,无需用户编写分布式服务的调用代码,从而减少用户的工作量,相较于现有技术中,用户不仅需要编写与应用的业务逻辑相关的程序源码,还需要编写分布式服务的通信代码,本申请实施例提供的方法能降低分布式服务的开发难度和成本。
在第一方面的一种可能的实现方式中,上述使用至少一个代码生成工具,根据多个标记得到子应用模块对应的分布式服务的调用代码,包括:使用远程过程调用(Remote Procedure Call,RPC)服务端代码生成工具,根据多个标记得到RPC服务端,其中,RPC服务端用于为分布式服务的服务端提供服务接口,使得分布式服务的客户端通过RPC服务端调用分布式服务的服务端上的子服务。
在第一方面的一种可能的实现方式中,分布式服务的客户端包括RPC客户端。上述使用至少一个代码生成工具,根据多个标记得到分布式服务的调用代码,包括:使用RPC客户端代码生成工具,根据多个标记得到RPC客户端,其中,RPC客户端通过调用RPC服务端以获得分布式服务的服务端上的子服务。
在第一方面的一种可能的实现方式中,分布式服务的服务端包括多个副本,分布式服务的客户端包括副本客户端。上述使用至少一个代码生成工具,根据多个标记得到分布式服务的调用代码,包括:使用副本客户端代码生成工具,根据多个标记得到副本客户端,其中,副本客户端用于指示调用多个副本中的一个副本上的子服务。通过上述实现方式中,应用中的子应用模块可以部署成包括多个副本的分布式服务,从而提高该分布式服务的可靠性,并通过副本客户端实现服务的远程调用。
进一步地,在多副本的场景下,每个副本包括一个RPC服务端,副本客户端包括多个RPC客户端,每个RPC客户端对应一个RPC服务端,这就相当于一个RPC客户端对应一个副本。如此,便可以通过副本客户端调用多个RPC客户端中的一个RPC客户端,再由该RPC客户端调用对应的RPC服务端,从而调用该RPC服务端对应的副本上的子服务。
在第一方面的一种可能的实现方式中,分布式服务的服务端包括多个分片,分布式服务的客户端包括分片客户端。上述使用至少一个代码生成工具,根据多个标记得到分布式服务的调用代码,包括:使用分片客户端代码生成工具,根据多个标记得到分片客户端,其中,分片客户端用于指示调用多个分片中的至少一个分片上的子服务。通过上述实现方式,应用中的子应用模块可以部署成包括多个分片的分布式服务,从而提供该分布式服务的容量和吞吐量,并通过分片客户端实现服务的远程调用。
进一步地,在多分片的场景下,每个分片可具有至少一个副本,此时,分片客户端包括至少一个副本客户端,且每个副本客户端对应一个分片,如此,便可以通过分片客户端调用至少一个副本客户端中的部分或全部副本客户端,再由上述部分或全部副本客户端分别调用其下的RPC客户端,之后再由RPC客户端调用对应的RPC服务端,从而调用对应分片的副本上的服务。
在第一方面的一种可能的实现方式中,分布式服务的客户端包括集群客户端。上述使用至少一个代码生成工具,根据多个标记得到分布式服务的调用代码,包括:使用集群客户端代码生成工具,根据多个标记得到集群客户端,其中,集群客户端用于获取分布式服务的服务端的状态信息,并根据该状态信息创建分布式服务的客户端的实例。如此,可保证分布式服务的客户端的有效性。
进一步地,集群客户端可调用分片客户端、副本客户端或RPC客户端。具体地,在多分片的场景下,集群客户端调用分片客户端;在多副本的场景下,集群客户端调用副本客户端;在分布式服务的服务端未被部署为多个分片和多个副本的场景下,即分布式服务的客户端不包括分片客户端和副本客户端,此时集群客户端调用RPC客户端。
在第一方面的一种可能的实现方式中,上述方法还包括:根据分布式服务的调用代码对分布式服务进行调试。如此,方便用户对分布式服务的相关代码进行故障定位和故障修正。
第二方面,本申请实施例提供了一种分布式服务生成系统,该系统包括获取单元和编译单元。其中,获取单元用于获取应用的程序源码,应用的程序源码包括多个标记,多个标记包括用于标记应用中的子应用模块的第一标记和用于标记子应用模块中的接口方法的第二标记;编译单元用于根据多个标记对应用的程序源码进行编译,得到子应用模块对应的分布式服务,分布式服务包括与其对应的子应用模块中的接口方法被执行时所实现的子服务。
在第二方面的一种可能的实现方式中,上述编译单元用于对应用的程序源码进行编译,获得应用的业务逻辑;使用至少一个代码生成工具,根据多个标记得到分布式服务的调用代码,其中,分布式服务的调用代码用于指示分布式服务的客户端调用分布式服务的服务端上的子服务;将应用的业务逻辑、分布式服务的调用代码和分布式服务关联的框架代码进行组合,得到分布式服务。
在第二方面的一种可能的实现方式中,上述编译单元用于使用RPC服务端代码生成工具,根据多个标记得到RPC服务端,其中,RPC服务端用于为分布式服务的服务端提供服务接口,使得分布式服务的客户端通过RPC服务端调用分布式服务的服务端上的子服务。
在第二方面的一种可能的实现方式中,分布式服务的客户端包括RPC客户端。上述编译单元用于使用RPC客户端代码生成工具,根据多个标记得到RPC客户端,其中,RPC客户端通过调用RPC服务端以获得分布式服务的服务端上的子服务。
在第二方面的一种可能的实现方式中,分布式服务的服务端包括多个副本,分布式服务的客户端包括副本客户端。上述编译单元用于使用副本客户端代码生成工具,根据多个标记得到副本客户端,其中,副本客户端用于指示调用多个副本中的一个副本上的子服务。
在第二方面的一种可能的实现方式中,分布式服务的服务端包括多个分片,分布式服务的客户端包括分片客户端。上述编译单元用于使用分片客户端代码生成工具,根据多个标记得到分片客户端,其中,分片客户端用于指示调用多个分片中的至少一个分片上的子服务。
在第二方面的一种可能的实现方式中,分布式服务的客户端包括集群客户端。上述编译单元用于使用集群客户端代码生成工具,根据多个标记得到集群客户端,其中,集群客户端用于获取分布式服务的服务端的状态信息,并根据该状态信息创建分布式服务的客户端的实例。
在第二方面的一种可能的实现方式中,该系统还包括调试单元,其中,调试单元用于根据分布式服务的调用代码对分布式服务进行调试。
第三方面,本申请实施例提供了一种计算设备,该计算设备包括处理器和存储器,处理器执行存储器中的计算机程序代码以实现前述第一方面及第一方面的任一种实现方式所描述部分或全部方法。
第四方面,本申请实施例提供了一种计算机可读存储介质,该计算机存储介质存储有计算机程序代码,当该计算机程序代码被计算设备执行时,该计算设备执行前述第一方面及第一方面的任一种实现方式所描述部分或全部方法。
第五方面,本申请实施例提供了一种计算机程序产品,该计算机程序产品可以是包含指令的、能够运行在计算设备上或被储存在任何可用介质中的软件或程序产品。当该计算机程序产品在至少一个计算设备上运行时,使得至少一个计算设备执行前述第一方面及第一方面的任一种实现方式所描述部分或全部方法。
附图说明
图1是本申请实施例提供的一种分布式服务生成系统的应用场景示意图;
图2是本申请实施例提供的一种分布式服务的结构示意图;
图3是本申请实施例提供的一种分布式服务生成方法的流程示意图;
图4是本申请实施例提供的一种分布式服务中应用服务的服务代码之间的关系图;
图5是本申请实施例提供的另一种分布式服务中应用服务的服务代码之间的关系图;
图6是本申请实施例提供的另一种分布式服务中应用服务的服务代码之间的关系图;
图7是本申请实施例提供的另一种分布式服务中应用服务的服务代码之间的关系图;
图8是本申请实施例提供的另一种分布式服务中应用服务的服务代码之间的关系图;
图9是本申请实施例提供的一种应用Map对应的分布式服务的结构示意图;
图10是本申请实施例提供的另一种应用Map对应的分布式服务的结构示意图;
图11是本申请实施例提供的另一种应用Map对应的分布式服务的结构示意图;
图12是本申请实施例提供的一种分布式服务生成系统的结构示意图;
图13是本申请实施例提供的一种计算设备的结构示意图。
具体实施方式
为了使本申请提供的技术方案更清晰,首先对本申请涉及到的相关术语进行解释。
单体应用是指将具有不同功能的模块集成在一个进程中的应用。它虽然在逻辑架构上进行了模块的功能划分,但在物理上却是紧耦合的实现,这就导致单体应用是被当作一个整体进行开发,并被部署到特定的硬件设备上,以实现相应的功能。单体应用具有易于开发和调试等优点,但随着应用规模的不断扩大,单体应用也暴露出越来越多的问题,例如:可靠性低(即某个模块出现故障可能会扩散影响到整个应用)、维护和升级的成本高、扩展性差。
基于此,对单体应用进行服务化改造,使其成为一个分布式服务,成为了一种必然的发展趋势。其中,服务化改造包括将单体应用的不同模块改造成独立的应用服务(如微服务),应用服务可以理解为由单一应用程序构成的小服务,用于负责一个独立的业务逻辑,完成应用的一部分功能。而且,应用服务可以单独构建和部署,这就使得应用包括的各个应用服务之间相互解耦,可独立替换、升级以及伸缩,不仅有助于开发者更新和维护应用,而且在单个应用服务出现故障时,其他应用服务仍可继续工作,提高了应用的可靠性。
应用中的各个应用服务相互协同工作,才能实现应用所具备的功能,换言之,各个应用服务之间存在通信的需求。为了解决各个应用服务之间的通信问题,人们开发了RPC框架。
RPC框架是一种可实现RPC协议的框架。其中,RPC协议是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议,因此使用RPC框架可以使得客户端像调用本地函数一样调用远程的服务接口。
RPC框架主要由四部分组成:服务端、RPC服务端、RPC客户端、客户端。其中,服务端是服务的提供方;RPC服务端用于给服务端上的服务提供服务接口,使其能够被客户端调用;RPC客户端用于通过RPC服务端调用服务端上的服务,并将结果返回给客户端,使得客户端获得服务;客户端是服务的调用方。在具体实现中,当客户端想要调用服务端上的服务时,客户端首先会调用RPC客户端,使得RPC客户端向RPC服务端发起服务调用请求,RPC服务端接收到来自RPC客户端的服务调用请求后,控制服务端实现相应的服务,并将该服务经由RPC客户端返回给客户端。这样,通过RPC客户端和RPC服务端,客户端和服务端将无法感知到服务调用时的具体过程和通信细节。
需要说明的是,RPC客户端和RPC服务端在通信时(例如:RPC客户端向RPC服务端发送服务调用请求,以及RPC服务端向RPC客户端返回执行结果)需要对待传输的数据进行序列化(serialization)和反序列化(deserialization)的处理。其中,序列化是指将待传输的数据序列化为字节数组,以用于网络传输;反序列化是指把从网络读取到的字节数组还原成原始对象(即上述待传输的数据),以方便后续的业务逻辑操作。
目前,经常使用分布式服务框架将应用拆分成多个应用服务,下面介绍几个使用RPC框架实现应用服务间通信的分布式服务框架:
(1)gRPC框架
gRPC框架是一个高性能、通用的开源RPC框架,它基于ProtoBuf序列化协议开发,支持多种开发语言(如Java、C语言)。在使用gRPC框架开发分布式服务时,用户需要编写一个proto文件,然后调用相关命令生成对应的代码,服务端(即上述服务的提供方)需要实现上述代码中的接口,客户端(即上述服务的调用方)需要调用上述代码中的函数来实现服务的远程调用。
虽然gRPC框架可实现各个应用服务之间的通信,但对于一个复杂的分布式服务来说,应用服务会以集群的形式进行部署(即应用服务本身也是一个分布式服务),例如:应用服务包括多个分片和副本,而gRPC框架只能解决RPC客户端和RPC服务端之间的通信,并不能解决应用服务中分片和副本的调用问题。
(2)Dubbo框架
Dubbo框架是一个高性能、轻量级的开源RPC框架,它提供了远程方法调用、容错和负载均衡、服务自动注册以及服务自动发现等功能。在使用Dubbo框架开发分布式服务时,用户需要提供一个服务注册中心(如ZooKeeper),服务端(即上述服务的提供方)会将其信息(如服务接口和服务地址)发布到服务注册中心,相应地,服务注册中心也会向客户端推送服务端的相关信息,以方便客户端调用远程服务。另外,在服务端还需要配置服务接口和服务实现类,在客户端配置需要调用的服务接口类,这样,客户端就可以得到一个封装好的服务接口的实例,从而像本地调用一样调用远端的服务。
相较于gRPC框架,Dubbo框架针对应用服务中分片和副本的调用提出了相应的解决方案,但在该框架中,客户端和服务端之间使用的应用层协议是私有协议,而应用服务之间常使用的是超文本传输协议(hyper text transfer protocol,HTTP)协议,这使得该框架与应用服务之间的配合比较困难。除此之外,该框架是基于Java的反射机制(reflection)来生成客户端时,这会增加分布式服务的故障定位和代码调试的难度。
(3)Spring Cloud框架
Spring Cloud框架提供了微服务开发的一站式解决方案,该框架包括各种工具包,例如:配置管理、消息总线、服务注册和发现、路由、网关、安全控制和熔断等。相较于gRPC框架,该框架针对应用服务中分片和副本的调用提出了相应的解决方案;相较于Dubbo框架,该框架使用HTTP协议作为客户端和服务端之间的应用层协议;但该框架也是基于Java的反射机制来生成客户端,因此使用该框架开发的分布式服务较难实现故障定位和代码调试。
针对上述问题,本申请实施例提供了一种分布式服务生成系统,能够将应用部署成分布式服务。在具体实现中,该系统也是基于RCP框架实现服务间调用的,但相较于现有技术来说,在生成分布式服务的过程中,还能生成用于实现服务间调用的代码,这相当于将分布式服务的复杂实现抽象到系统内部,换句话说,利用该系统能够减少用户手写代码的工作量,降低分布式服务的开发难度和成本。另外,利用上述生成的代码,还有助于对分布式服务进行故障定位和调试。
上述分布式服务生成系统可以是一种编译辅助工具,或一个软件开发包。图1示例性地展示了该分布式服务生成系统的应用场景示意图。如图1所示,用户基于待开发应用想要实现的功能,将该应用划分为至少一个子应用模块,并确定各个子应用模块中的接口方法,其 中,子应用模块是指应用中的功能模块,可用于实现该应用的一部分功能;接口方法是指子应用模块中、可供其他子应用模块调用的方法,具体可以是一个函数或由多个函数组成的方法。然后,在应用的程序源码中对上述确定好的子应用模块以及子应用模块中的接口方法进行标记,并使用本申请实施例提供的分布式服务生成系统对上述标记后的程序源码进行编译。在编译过程中,上述分布式服务生成系统会自动识别出程序源码中的标记,并根据标记将应用中的各个子应用模块编译成相应的分布式服务,从而将该应用部署成相应的分布式服务。
需要说明的是,上述子应用模块是一个逻辑性的概念,在实际应用中,用户可以按照功能、并遵循“子应用模块内高内聚、子应用模块间低耦合”的规则(即子应用模块内部联系紧密、子应用模块之间耦合程度低),将待开发的应用划分成至少一个子应用模块。
示例性的,利用上述分布式服务生成系统可以将一个应用部署成如图2所示的分布式服务100。其中,分布式服务100包括至少一个应用服务110(图2以应用服务A和应用服务B为例)和集群管理节点120。
应用服务110对应于应用中的子应用模块,即应用被部署为分布式服务100后,应用中的每个子应用模块都被部署为相应的应用服务110。分布式服务100中的各个应用服务110可以部署在不同的计算节点上,也可以两个或多个部署在同一个计算节点上,其中,部署有应用服务110的计算节点可包括服务器、虚拟机(virtual machine,VM)、容器(container)等。
由于应用的各个子应用模块之间存在通信的需求,因此分布式服务100中的各个应用服务110之间也需要相互通信,本申请实施例中,上述至少一个应用服务110之间可通过RPC实现通信(即远程服务调用)。除此之外,考虑到子应用模块包括至少一个接口方法,因此应用服务110包括上述至少一个接口方法被执行时所实现的至少一个子服务,其中,一个接口方法对应一个子服务,即执行一个接口方法会实现一个子服务。
在一些实施例中,应用服务110也是一个分布式服务,如图2所示,应用服务110包括服务端和客户端,应用服务110的服务端和应用服务110的客户端部署在不同的计算节点上。其中,应用服务110的服务端是服务的提供方,用于提供应用服务110包括的至少一个子服务;应用服务110的客户端是服务的调用方,用于调用应用服务110的服务端提供的上述至少一个子服务。需要说明的一点是,以应用服务B想要调用应用服务A上的一个子服务为例,应用服务B需要先向应用服务A的客户端发送服务调用请求,再由应用服务A的客户端调用应用服务A的服务端以向应用服务B提供相应的子服务。
应用服务110的服务端包括RPC服务端。其中,RPC服务端用于给上述至少一个子服务提供至少一个服务接口,且一个子服务对应一个服务接口,子服务可通过对应的服务接口被调用。应用服务110的客户端包括RPC客户端。其中,RPC客户端用于调用RPC服务端以获得上述至少一个子服务。比如说:应用服务A的服务端可提供服务1和服务2,则应用服务A的RPC服务端会提供服务1的服务接口(以下简称为服务接口1)和服务2的服务接口(以下简称为服务接口2),应用服务A的RPC客户端包括用于调用服务接口1的代码,以及用于调用服务接口2的代码。当应用服务A的客户端想要调用服务1时,应用服务A的客户端通过RPC客户端来调用RPC服务端所提供的服务接口1,使得应用服务A的服务端执行服务1对应的接口方法,这样,应用服务A的服务端便可以向应用服务A的客户端提供服务1。
可选的,为了提高应用服务110的可靠性,应用服务110的服务端包括多个副本(replica),其中,每个副本均用于提供上述至少一个子服务。在多副本的场景下,如何确定需要调用哪个副本上的子服务,以及如何实现调用呢?为此,本申请实施例提出:多个副本中的每个副 本包括一个RPC服务端,且应用服务110的客户端包括副本客户端。其中,副本客户端包括多个RPC客户端,每个RPC客户端对应一个RPC服务端,这就相当于一个RPC客户端对应一个副本。这样,便可以通过副本客户端指示调用上述多个副本中的哪个副本上的子服务,即:副本客户端调用多个RPC客户端中的一个RPC客户端,再由该RPC客户端调用对应的RPC服务端,从而调用该RPC服务端对应的副本上的子服务。
进一步地,为了提高应用服务110的容量和吞吐量,应用服务110的服务端可包括多个分片(shards),其中,每个分片用于提供上述至少一个子服务中的一个或多个子服务。在多分片的场景下,如何确定需要调用哪个分片上的服务,以及如何实现调用呢?为此,本申请实施例提出:应用服务110的客户端还可以包括分片客户端,其中,分片客户端用于指示调用上述多个分片中的哪个或哪些分片上的子服务。
在一些实施例中,每个分片可具有至少一个副本(以下将分片的副本简称为分片副本),即同一个分片的分片副本提供相同的服务。在多分片和多副本的场景下,如何确定需要调用哪个分片副本上的服务,以及如何实现调用呢?为此,本申请实施例提出:分片客户端包括多个副本客户端,且每个副本客户端对应一个分片,其中,分片客户端用于指示调用上述多个分片中的哪个或哪些分片上的子服务,副本客户端用于指示调用一个分片中的哪个分片副本上的服务,即:分片客户端调用多个副本客户端中的至少一个副本客户端,再由至少一个副本客户端分别调用其下的RPC客户端,之后再由RPC客户端调用对应的RPC服务端,从而调用对应分片副本上的服务。
可选的,应用服务110的客户端还包括集群客户端。其中,集群客户端与集群管理节点120建立有连接(如心跳连接),以从集群管理节点120中获取应用服务110的服务端的状态信息,并根据获取到的状态信息创建应用服务110的客户端(包括分片客户端、副本客户端和RPC客户端中的至少一种)的实例,如此可以保证应用服务110的客户端的有效性。比如说:在多分片和多副本的场景下,集群管理节点120会存储有应用服务A的服务端的分片配置信息(即应用服务A的服务端包括2个分片,每个分片具有5个副本),应用服务A的集群客户端可以从集群管理节点120中获取上述分片配置信息,并根据分片配置信息创建分片客户端的实例、2个副本客户端的实例、以及10个RPC客户端的实例,从而创建出分片客户端、2个副本客户端和10个RPC客户端。当应用服务A的服务端的分片数量增加到3时,集群管理节点120会及时更新本地存储的应用服务A的服务端的分片配置信息(此时为应用服务A的服务端包括3个分片,每个分片具有5个副本),相应的,集群客户端也会及时获取更新后的分片配置信息,并根据更新后的分片配置信息重新创建应用服务A的客户端的实例,即:分片客户端的实例,3个副本客户端的实例和15个RPC客户端的实例,从而创建出分片客户端、3个副本客户端和15个RPC客户端。
除此之外,集群客户端还用于接收其他应用服务110的集群客户端发送的服务调用请求,或者向其他应用服务110的集群客户端发送服务调用请求,以实现不同应用服务110之间的服务调用。比如说:当应用服务B想要调用应用服务A包括的子服务(如服务1或服务2)时,应用服务B的集群客户端会向应用服务A的集群客户端发送服务调用请求,应用服务A的集群客户端接收到上述服务调用请求后,依次调用分片客户端、副本客户端和RPC客户端,再由RPC客户端调用相应的RPC服务端,从而调用与该RPC服务端对应的应用服务A的服务端上的服务。
集群管理节点120用于注册(register)服务和发现(discover)服务。其中,此处的服务包括应用服务110包括的至少一个子服务。“注册服务”是指应用服务110的服务端在集群管 理节点120注册其可提供的服务,例如:注册服务的服务名、服务接口、服务地址等。“发现服务”是指应用服务110的客户端从集群管理节点120确定想要调用的服务的提供方。比如说:应用服务A的服务端可提供服务1和服务2,应用服务B的服务端可提供服务3,那么,应用服务A的服务端会向集群管理节点120注册服务1和服务2的服务名、服务接口、服务地址等信息,应用服务B的服务会向集群管理节点120注册服务3的服务接口,当应用服务B想要调用服务1时,应用服务B会从集群管理节点120中确定服务1的提供方(即应用服务A的服务端),从而通过服务1的服务接口调用应用服务A的服务端提供的服务1。
下面结合图3示出的分布式服务生成方法,对上述分布式服务生成系统将应用部署成分布式服务100的具体过程展开描述。其中,该方法由上述分布式服务生成系统执行。
S101:获取应用的程序源码。
应用的程序源码是指未经编译的、按照一定的程序设计语言(如Java、C语言)规范书写的、用于实现特定功能(即用户期望应用能够实现的功能)的文本文件,是一系列人类可读的计算机语言指令。
应用的程序源码包括多个标记,可选的,多个标记中的每个标记可以是对某段程序源码的注解(如Java注解),或是与某段程序源码相邻的、设置有预定语法的程序代码,该预定语法是指可以被分布式服务生成系统识别的语法。
多个标记包括用于标记应用中的子应用模块的第一标记和用于标记子应用模块中的接口方法的第二标记。其中,子应用模块和接口方法的定义可参见图1中的相关描述,本实施例中,一个第一标记用于标记一个子应用模块,一个第二标记用于标记一个接口方法,且多个标记中第一标记的数量和第二标记的数量均可以是一个或多个。在具体实现中,第一标记可以是添加在子应用模块对应的程序源码的相邻位置处的注解,例如:在用于定义子应用模块的程序源码的上一行或下一行添加相应的注解;或者,第一标记也可以是添加在子应用模块对应的程序源码的相邻位置处的、使用预定语法的程序代码,例如:在用于定义子应用模块的程序源码的上一行或同一行的末尾,添加一段以预定语法编写的程序代码。同样的,第二标记可以是添加在接口方法对应的程序源码的相邻位置处的注解,例如:在用于定义接口方法的程序源码的上一行或下一行添加相应的注解;或者,第二标记也可以是添加在接口方法对应的程序源码的相邻位置处的、使用预定语法的程序代码,例如:在用于定义接口方法的程序源码的上一行或同一行的末尾,添加一段以预定语法编写的程序代码。
在一些实施例中,分布式服务生成系统可采用以下一种或多种方式获取应用的程序源码:
方式1、分布式服务生成系统提供文件上传接口(如应用程序编程接口(application programming interface,API)或用户界面(user interface,UI)),用户可通过该文件上传接口将编写好应用的程序代码上传至分布式服务生成系统,如此,分布式服务生成系统便可以获取应用的程序源码。
方式2、分布式服务生成系统提供在线编程接口(如API或UI),用户可通过该在线编程接口在分布式服务生成系统上编写应用的程序源码。
进一步地,分布式服务生成系统还可在用户编写应用的程序源码时,提示用户为应用中的子应用模块添加第一标记,为子应用模块中的接口方法添加第二标记。
S102:根据多个标记对应用的程序源码进行编译,得到应用中的各个子应用模块对应的应用服务110,从而得到应用对应的分布式服务100。
需要说明的是,由于应用服务110也是一个分布式服务,因此本步骤中“得到应用中的 各个子应用模块对应的应用服务110”相当于“得到应用中的各个子应用模块对应的分布式服务”。但为了清楚地区分“应用对应的分布式服务”和“子应用模块对应的分布式服务”,此处将“子应用模块对应的分布式服务”称为“子应用模块对应的应用服务110”。
在一些实施例中,分布式服务生成系统根据多个标记对应用的程序源码进行编译,得到应用中的各个子应用模块对应的应用服务110,从而得到应用对应的分布式服务100,包括:分布式服务生成系统对应用的程序源码进行编译,获得应用的业务逻辑。使用至少一个代码生成工具,根据上述多个标记得到至少一个应用服务110的调用代码,其中,每个应用服务110的调用代码用于指示该应用服务110的客户端调用该应用服务110的服务端上的子服务,具体可包括前文所描述的RPC服务端、RPC客户端、副本客户端、分片客户端以及集群客户端中的至少一种。然后,将应用的业务逻辑、至少一个应用服务110的调用代码和至少一个应用服务110关联的框架代码进行组合,得到上述至少一个应用服务110,从而得到应用对应的分布式服务100,其中,至少一个应用服务110关联的框架代码包括:除应用的业务逻辑和至少一个应用服务110的调用代码之外的、与实现至少一个应用服务110的功能相关的代码,例如:用于实现集群管理节点120具有的功能的代码、用于实现多副本间数据同步的代码、用于实现数据迁移的代码等,另外,上述至少一个应用服务110关联的框架代码可以是分布式服务生成系统的开发者预先提供的,也可以是上述用户提供给分布式服务生成系统的。如此,相当于把应用的业务逻辑和分布式服务100的复杂实现(包括分布式服务100中各个应用服务110间的调用过程)进行解耦,并由分布式服务生成系统来实现分布式服务100的复杂实现,从而简化了用户的工作(包括用户无需编写上述至少一个应用服务110的调用代码),降低了将应用部署成分布式服务100的难度和成本。
上述至少一个代码生成工具由分布式服务生成系统提供,用于识别应用的程序源码中的多个标记,并根据多个标记生成至少一个应用服务110的调用代码,例如:当多个标记是Java注解时,上述至少一个代码生成工具可以是Java自带的工具(即AbstractProcessor),该工具能够拦截代码中的注解,分布式服务生成系统的开发者通过对该工具进行进一步开发,使其还具备根据拦截下的注解生成至少一个应用服务110的调用代码的功能,从而得到本实施例中的至少一个代码生成工具。
在一些实施例中,分布式服务生成系统使用至少一个代码生成工具,根据上述多个标记得到至少一个应用服务110的调用代码,包括以下一种或多种实现方式:
方式1、至少一个代码生成工具包括RPC服务端代码生成工具,多个标记包括用于指示生成至少一个RPC服务端的参数。那么,上述步骤包括:分布式服务生成系统使用RPC服务端代码生成工具,根据上述多个标记得到至少一个RPC服务端。其中,每个RPC服务端用于为对应的应用服务110的服务端提供服务接口,具体是为该应用服务110中的每个子服务提供相应的服务接口,以使得该应用服务110的客户端可通过RPC服务端来调用该应用服务110的服务端上的子服务。
更具体地,分布式服务生成系统在获得应用的程序源码后,使用RPC服务端代码生成工具,从应用的程序源码中确定多个标记,然后根据多个标记中用于指示生成至少一个RPC服务端的参数,得到至少一个RPC服务端对应的程序源码,之后对至少一个RPC服务端对应的程序源代码进行编译,得到上述至少一个RPC服务端。需要说明的是,每个RPC服务端都是可执行代码,可执行代码是对程序源码进行编译后得到的、处理器(如中央处理器(central processing unit,CPU))可以加载并执行的代码。
方式2、至少一个代码生成工具包括RPC客户端代码生成工具,多个标记包括用于指示 生成至少一个RPC客户端的参数。那么,上述步骤包括:分布式服务生成系统使用RPC客户端代码生成工具,根据上述多个标记得到至少一个RPC客户端。其中,每个RPC客户端用于调用对应的RPC服务端,以获得与该RPC服务端对应的应用服务110的服务端上的子服务。
更具体地,分布式服务生成系统在获得应用的程序源码后,使用RPC客户端代码生成工具,从应用的程序源码中确定多个标记,然后根据多个标记中用于指示生成至少一个RPC客户端的参数,得到至少一个RPC客户端对应的程序源码,之后对至少一个RPC客户端对应的程序源码进行编译,得到上述至少一个RPC客户端。其中,上述至少一个RPC客户端是可执行代码。
方式3、至少一个代码生成工具包括副本客户端代码生成工具,多个标记包括用于指示生成至少一个副本客户端的参数。那么,上述步骤包括:分布式服务生成系统使用副本客户端代码生成工具,根据上述多个标记得到至少一个副本客户端。其中,每个副本客户端用于在对应的应用服务110的服务端包括多个副本的情况下,指示调用多个副本中的一个副本上的子服务。
更具体地,分布式服务生成系统在获得应用的程序源码后,使用副本客户端代码生成工具,从应用的程序源码中确定多个标记,然后根据多个标记中用于指示生成至少一个副本客户端的参数,得到至少一个副本客户端对应的程序源码,之后对至少一个副本客户端对应的程序源码进行编译,得到上述至少一个副本客户端。其中,上述至少一个副本客户端是可执行代码。
方式4、至少一个代码生成工具包括分片客户端代码生成工具,多个标记包括用于指示生成至少一个分片客户端的参数。那么,上述步骤包括:分布式服务生成系统使用分片客户端代码生成工具,根据上述多个标记得到至少一个分片客户端。其中,每个分片客户端用于在对应的应用服务110的服务端包括多个分片的情况下,指示调用多个分片中的至少一个分片上的子服务。
更具体地,分布式服务生成系统在获得应用的程序源码后,使用分片客户端代码生成工具,从应用的程序源码中确定多个标记,然后根据多个标记中用于指示生成至少一个分片客户端的参数,得到至少一个分片客户端对应的程序源码,之后对至少一个分片客户端对应的程序源码进行编译,得到上述至少一个分片客户端。其中,上述至少一个分片客户端是可执行代码。
方式5、至少一个代码生成工具包括集群客户端代码生成工具,多个标记包括用于指示生成至少一个集群客户端的参数。那么,上述步骤包括:分布式服务生成系统使用集群客户端代码生成工具,根据上述多个标记得到至少一个集群客户端。其中,每个集群客户端用于获取对应的应用服务110的服务端的状态信息,并根据上述状态信息创建该应用服务110的客户端的实例。
更具体地,分布式服务生成系统在获得应用的程序源码后,使用集群客户端代码生成工具,从应用的程序源码中确定多个标记,然后根据多个标记中用于指示生成至少一个集群客户端的参数,得到至少一个集群客户端对应的程序源码,之后对至少一个集群客户端对应的程序源码进行编译,得到上述至少一个集群客户端。其中,上述至少一个集群客户端是可执行代码。
需要说明的是,上述RPC服务端、RPC客户端、副本客户端、分片客户端和集群客户端的详细内容可参见图2及其相关描述,此处不再对其展开描述。但为了更清晰地了解这几种 服务代码的功能,此处以一个应用服务110为例,结合图4-图8对这几种服务代码之间的关系进行描述。
如图4所示,当应用服务110的服务代码包括RPC服务端和RPC客户端时,这两种服务代码之间的关系是:RPC客户端调用RPC服务端(具体是调用RPC服务端提供的服务接口),使得应用服务110的服务端执行被调用的服务接口对应的接口方法,从而将相应的子服务提供给应用服务110的客户端。
如图5所示,当应用服务110的服务代码包括RPC服务端、RPC客户端和集群客户端时,这三种服务代码之间的关系是:集群客户端调用RPC客户端,RPC客户端调用RPC服务端(具体是调用RPC服务端提供的服务接口),使得应用服务110的服务端执行被调用的服务接口对应的接口方法,从而将相应的子服务提供给应用服务110的客户端。
如图6所示,在多副本的场景下,应用服务110的服务端包括M个副本(即副本1、副本2、…、副本M,M是大于1的整数),因此,应用服务110的服务代码包括副本客户端、M个RPC客户端和M个RPC服务端,其中,一个副本包括一个RPC服务端,一个RPC服务端对应一个RPC客户端。另外,在多副本的场景下,由于应用服务110以集群的形式部署,因此应用服务110的服务代码还包括集群客户端。这几种服务代码之间的关系是:集群客户端调用副本客户端,通过副本客户端确定待调用的副本(假设是副本2),再由副本客户端调用副本2对应的RPC客户端,最后由该RPC客户端调用与之对应的RPC服务端(即副本2包括的RPC服务端),如此,副本2便会向应用服务110的客户端提供相应的子服务。
如图7所示,在多分片的场景下,应用服务110的服务端包括N个分片(即分片1、分片2、…、分片N,N是大于1的整数),因此,应用服务110的服务代码包括分片客户端、N个RPC服务端和N个RPC客户端,其中,一个分片包括一个RPC服务端,一个RPC服务端对应一个RPC客户端。另外,在多分片的场景下,由于应用服务110以集群的形式部署,因此应用服务110的服务代码还包括集群客户端。这几种服务代码之间的关系是:集群客户端调用分片客户端,通过分片客户端确定待调用的分片(假设是分片1),再由分片客户端调用分片1对应的RPC客户端,最后由该RPC客户端调用与之对应的RPC服务端(即分片1包括的RPC服务端),如此,分片1便会向应用服务110的客户端提供相应的子服务。
如图8所示,在多分片和多副本的场景下,应用服务110的服务端包括N个分片(即分片1、分片2、…、分片N),每个分片包括M个副本(即副本1、副本2、…、副本M),换言之,应用服务110的服务端包括M*N个分片副本(即分片副本11(即分片1下的副本1)、分片副本12(即分片1下的副本2)、…、分片副本1M(即分片1下的副本M)、…、分片副本NM(即分片N下的副本M))。因此,应用服务110的服务代码包括集群客户端、分片客户端、M个副本客户端、M*N个RPC客户端和M*N个RPC服务端,其中,一个分片对应一个副本客户端,一个分片副本包括一个RPC服务端,一个RPC服务端对应一个RPC客户端。这几种服务代码之间的关系是:集群客户端调用分片客户端,通过分片客户端确定待调用的分片(假设是分片1),再由分片客户端调用分片1对应的副本客户端(假设是副本客户端1),通过副本客户端1确定分片1下待调用的副本(假设是副本2),之后由副本客户端1调用分片副本12对应的RPC客户端,最后由该RPC客户端调用对应的RPC服务端(即分片副本12包括的RPC服务端),如此,分片副本12便会向应用服务110的客户端提供相应的子服务。
应理解,分布式服务生成系统执行上述S101-S102后,可以将应用部署成分布式服务100。分布式服务100包括至少一个应用服务110,至少一个应用服务110之间可以通过至少一个 应用服务110的调用代码实现服务的远程调用。另外,由于应用服务110本身也是一个分布式服务,因此应用服务110内部(即应用服务110的客户端和应用服务110的服务端)也可以通过该应用服务110的调用代码实现服务的远程调用。
除此之外,考虑到在分布式服务100开发完成之后,一般还需对其进行调试,因此,可选的,分布式服务生成系统还可以执行以下步骤:
S103:根据至少一个应用服务110的服务调用代码对至少一个应用服务110进行调试,从而实现对分布式服务100的调试。
具体地,分布式服务生成系统根据应用的业务逻辑、至少一个应用服务110的服务调用代码和至少一个应用服务110关联的框架代码,对至少一个应用服务110进行调试,从而达到对分布式服务100调试的目的。
进一步地,分布式服务生成系统还可以将调试结果返回给用户,其中,调试结果指示出现错误(如语法错误、逻辑错误等)的代码,如此,用户便可以根据调试结果修正相关代码,以保证分布式服务100的正常运行。
下文以Java为例对上述分布式服务生成方法进行更一步地描述。
在描述之前,首先对涉及到的、与Java相关的知识进行简要介绍:Java是一种面向对象的编程语言,因此其核心是对象(也称为实例)。在Java中,一般使用关键字interface来声明接口,接口是一系列方法的集合,即接口包括一个或多个方法,因此,用户在使用Java编写应用的程序源码时,可以将应用中的子应用模块定义为接口,子应用模块中的接口方法可以被定义为相应接口中的接口方法。另外,由于接口中只是声明了方法,并不能实现方法,但接口可以被类实现,类实现接口时可以实现该接口内描述的所有接口方法,因此,对于被定义为接口的子应用模块来说,其具体实现可以被定义为一个类。除此之外,用户在使用Java编写应用的程序源码时,还可以直接将应用中的子应用模块定义为类,子应用模块中的接口方法被定义为类中的方法。但相较于前一种方式,前一种方式可以使得程序源码的编写更加简洁明了。
Java标准库中的Map相当于一个字典,用于存放具有映射关系的对象(即键(key)-值(value)对)。Map提供的方法包括:put()、get()以及size(),其中,put()用于添加key-value对;get()用于返回指定key对应的value;size()用于查询当前已存放的key-value对的个数。
本实施例将上述Map作为一个应用,详细介绍将Map部署成分布式服务100的过程:
首先,考虑到Map的功能较为单一,那么此处不再对该应用进行进一步划分,换言之,该应用仅包括一个子应用模块,该子应用模块即为应用本身。为了方便与上述分布式服务生成方法对应,下文将“应用Map”称为“子应用模块Map”。因此,用户在使用Java语言编写该应用的程序源码时,可以将子应用模块Map定义为接口IMap,将用于实现接口IMap的类定义为类MapImpl,其中,接口IMap的具体定义方式可参见下述示例1-示例3。
示例1:

上述程序源码中“ClusterService”是分布式服务生成系统预先定义的接口,需要生成应用服务110的调用代码的子应用模块都需要实现这个接口,因此在上述程序源码中通过声明接口IMap继承接口ClusterService来表示子应用模块Map是一个需要生成应用服务110的调用代码的子应用模块。
上述程序源码包括2种标记,分别是:@Cluster、@ClusterMethod。其中,标记@Cluster属于第一标记,在此处用于标记子应用模块Map(即接口IMap);标记@Cluster Method属于第二标记,在上述程序源码中有3个这种标记,分别用于标记子应用模块Map中接口方法put()、get()和size()。
除上述接口IMap的定义之外,子应用模块Map的程序源码还包括其他部分,例如:子应用模块Map的程序源码还包括子应用模块Map的服务端(即图2中的应用服务110的服务端,以下简称为MapServer)、子应用模块Map的客户端(即图2中的应用服务110的客户端,以下简称为MapClient)、以及类MapImpl实现接口IMap的相关程序源码。而且,为了使得MapServer能够提供服务,用户会在MapServer的主程序源码中创建类MapImpl的实例,并将类MapImpl的实例注册到RPC服务端中。同样的,为了使得MapClient能够调用MapServer上的服务,用户还会在MapClient的主程序源码中创建RPC客户端的实例,并在该实例的参数中指定MapServer的IP地址和端口号。
可选的,子应用模块Map的程序源码还包括集群配置文件,其中,集群配置文件是上述S102中的用于实现集群管理节点120具有的功能的代码。
上述程序源码中的第一标记的默认参数包括用于指示生成RPC服务端的参数、用于指示生成RPC客户端的参数、用于指示不生成副本客户端的参数、用于指示不生成分片客户端的参数、以及用于指示生成集群客户端的参数,因此,在子应用模块Map的程序源码的编译过程中,分布式服务生成系统提供的多个代码生成工具根据上述多个标记可以得到RPC服务端、RPC客户端以及集群客户端,不会得到副本客户端和分片客户端。具体过程如下:
(1)RPC服务端
RPC服务端代码生成工具首先识别出上述程序源码中的标记@Cluster,从而确定需要为该标记指示的子应用模块IMap生成RPC服务端;然后再依次识别出上述程序源码中的3个标记@ClusterMethod,从而得到RPC服务端,其中,RPC服务端用于提供接口方法put()的服务接口(以下简称为put接口)、接口方法get()的服务接口(以下简称为get接口)、以及接口方法size()的服务接口(以下简称为size接口)。
(2)RPC客户端
RPC客户端代码生成工具首先识别出上述程序源码中的标记@Cluster,从而确定需要为该标记指示的子应用模块Map生成RPC客户端;然后再依次识别出上述程序源码中的3个标记@ClusterMethod,从而得到RPC客户端,其中,RPC客户端用于调用RPC服务端,具体可包括:用于调用RPC服务端提供的put接口、get接口和size接口,从而实现接口方法put()、接口方法get()、以及接口方法size()的调用。
(3)集群客户端
集群客户端代码生成工具首先识别出上述程序源码中的标记@Cluster,从而确定需要为该标记指示的子应用模块IMap生成集群客户端;然后再依次识别出上述程序源码中的3个 标记@ClusterMethod,从而得到集群客户端,其中,集群客户端用于调用RPC客户端,以使得RPC客户端调用RPC服务端提供的某个接口,集群客户端还用于读取集群配置文件,并与集群配置文件中配置的集群管理节点120建立连接,在连接建立后,从集群管理节点120获取MapServer的状态信息,并根据MapServer的状态信息创建RPC客户端的实例。
上述RPC服务端、RPC客户端和集群客户端即为上述S102中的应用服务110的调用代码,因此,如图9所示,在分布式服务生成系统得到上述RPC服务端、RPC客户端和集群客户端后,通过将子应用模块Map的业务逻辑,上述RPC服务端、RPC客户端和集群客户端,以及相关的框架代码(包括用于实现集群管理节点120具有的功能的代码)进行组合,便可得到子应用模块Map对应的应用服务110,即应用Map对应的分布式服务100。
示例2:
与示例1给出的程序源码不同的是:①示例2中的第一标记还包括参数“replica=true”,该参数用于表示MapServer需要以多副本的形式进行部署,也就是说,需要为子应用模块Map生成副本客户端。②示例2中用于标记接口方法put()的第二标记还包括参数“value=WRITABLE”,该参数用于表示在调用MapServer上的接口方法put()时,优先调用多个副本中的领导(leader)节点上的接口方法put(),并在领导节点执行接口方法put()后(即将键-值对写入领导节点),通知多个副本中的跟随(follower)节点进行数据同步(即将上述键-值写入跟随节点)。
上述程序源码中第一标记的默认参数包括用于指示生成RPC服务端的参数、用于指示生成RPC客户端的参数、用于指示不生成分片客户端的参数以及用于指示生成集群客户端的参数,再结合第一标记中的参数“replica=true”,在子应用模块Map的程序源码的编译过程中,分布式服务生成系统提供的多个代码生成工具根据上述多个标记可以得到RPC服务端、RPC客户端、副本客户端以及集群客户端,不会得到分片客户端。其中,分布式服务生成系统得到RPC客户端和集群客户端的过程与上述示例1的类似,因此这里不再对其展开描述,下面仅对分布式服务生成系统得到RPC服务端和副本客户端的过程进行描述。
(1)RPC服务端
RPC服务端代码生成工具首先识别出上述程序源码中的第一标记,从而确定需要为该标记指示的子应用模块IMap生成RPC服务端;然后,再识别出上述程序源码中的3个第二标记,从而得到RPC服务端,其中,当识别出用于标记接口方法put()的第二标记(即@ClusterMethod(value=WRITABLE))时,RPC服务端代码生成工具除了用于生成put()接口外,还用于在MapServer开启副本同步功能。之后,分布式服务生成系统为每个副本都部署该RPC服务端。
(2)副本客户端
副本客户端代码生成工具首先识别出上述程序源码中的第一标记(即@Cluster(replica=true)),从而确定需要为该标记指示的子应用模块Map生成相应的副本客户端;然后再依次识别出上述程序源码中的3个第二标记,从而得到副本客户端,其中,副本客户端包括用于实现以下功能的代码:MapClient在需要调用接口方法put()时,会优先调用领导节点上的接口方法put()(具体是调用领导节点对应的RPC客户端,再由该RPC客户端调用领导节点包括的RPC服务端,从而实现对领导节点上的接口方法put()的调用),领导节点执行接口方法put()后,将键-值对记录到本地的预写日志中,然后通知跟随节点进行数据同步,以将上述键-值对写入跟随节点。MapClient在需要调用接口方法get()或接口方法size时,MapClient根据负载均衡算法从上述多个副本中选择一个副本,并对其上的接口方法get()或接口方法size进行调用(具体是根据负载均衡算法调用某个副本对应的RPC客户端,再由该RPC客户端调用该副本包括的RPC服务端,从而实现对该副本上的接口方法get()或size()的调用)。
上述RPC服务端、RPC客户端、副本客户端和集群客户端即为上述S102中的应用服务110的调用代码,因此,如图10所示,在分布式服务生成系统得到上述RPC服务端、RPC客户端、副本客户端和集群客户端后,通过将子应用模块Map的业务逻辑,上述RPC服务端、RPC客户端、副本客户端和集群客户端,以及相关的框架代码(包括用于实现集群管理节点120具有的功能的代码和用于实现多副本间数据同步的代码)进行组合,便可得到子应用模块Map对应的应用服务110,即应用Map对应的分布式服务100。
示例3:
与示例2给出的程序源码不同的是:①示例3中的第一标记还包括参数“shards=ShardsStrategy.CONSISTENT_HASH”,该参数用于表示MapServer需要以多分片的形式进行部署,且遵循的分片策略是一致性哈希(consistent hashing)策略,也就是说,需要为子应用模块Map生成分片客户端。②示例3中用于标记接口方法size()的第二标记还包括参数“TRAVERSE”,该参数用于表示在MapClient需要调用接口方法size()时,会同时调用MapServer的所有分片的副本上的接口方法size(),并在上述所有分片的副本执行接口方法size()后,对执行结果进行汇总,并将汇总结果返回给MapClient。比如说:MapServer包括2个分片(分片1和分片2),每个分片包括2个副本(副本1和副本2),则参数“TRAVERSE”用于表示在MapClient需要调用接口方法size()时,会同时调用分片1下的副本1(或分片1下的副本2)和分片2下的副本1(或分片2下的副本2)上的接口方法size();在分片1下的副本1(或分片1下的副本2)执行接口方法size()后,得到该分片副本中存储的键-值对数量,在分片2下的副本1(或分片2下的副本2)执行接口方法size()后,得到该分片副本中 存储的键-值对数量;然后,计算上述2个分片副本中存储的键-值对数量的和,并将和值返回给MapClient。③示例3中“@Id”是键(即程序源码中的“String key”)的标识,在键前添加“@Id”,以用于表示该键是唯一的,在具体实现中,分片客户端通过对“@Id”进行一致性哈希计算来从多个分片中确定待调用的分片。
上述程序源码中第一标记的默认参数包括用于指示生成RPC服务端的参数、用于指示生成RPC客户端的参数以及用于指示生成集群客户端的参数,再结合第一标记中的参数“replica=true”和“shards=ShardsStrategy.CONSISTENT_HASH”,在子应用模块Map的程序源码的编译过程中,分布式服务生成系统提供的多个代码生成工具根据上述多个标记可以得到RPC服务端、RPC客户端、副本客户端、分片客户端以及集群客户端。其中,分布式服务生成系统得到RPC客户端、RPC服务端、副本客户端以及集群客户端的过程与上述示例2的类似,因此这里不再对其展开描述,下面仅对分布式服务生成系统得到分片客户端的过程进行描述:
分片客户端代码生成工具首先识别出上述程序源码中的第一标记(即@Cluster(shards=ShardsStrategy.CONSISTENT_HASH,replica=true)),从而确定需要为该标记指示的子应用模块Map生成分片客户端;然后再依次识别出上述程序源码中的3个第二标记,从而得到分片客户端,其中,分片客户端包括用于实现以下功能的代码:MapClient在需要调用接口方法size()时,会同时调用MapServer的所有分片的副本上的接口方法size()(具体是同时调用每个分片对应的副本客户端,再由每个副本客户端调用其下的任一个RPC客户端,进而调用每个分片副本包括的RPC服务端,从而实现对该分片副本上的接口方法size()的调用),并在上述所有分片的副本执行接口方法size()后,对执行结果进行汇总,并将汇总结果返回给MapClient。MapClient在需要调用接口方法put()或get()时,根据一致性哈希算法和键的标识(即“@Id”),从多个分片中确定一个分片,并调用该分片下的某个副本上的接口方法put()或get()(具体是调用该分片对应的副本客户端,再由该副本客户端调用其下的某个RPC客户端,进而调用相应的RPC服务端,从而实现对该分片下的某个副本上的接口方法put()和get()的调用)。
上述RPC服务端、RPC客户端、副本客户端、分片客户端和集群客户端即为上述S102中的应用服务110的调用代码,因此,如图11所示,在分布式服务生成系统得到上述RPC服务端、RPC客户端、副本客户端、分片客户端和集群客户端后,通过将子应用模块Map的业务逻辑,上述RPC服务端、RPC客户端、副本客户端、分片客户端和集群客户端,以及相关的框架代码(包括用于实现集群管理节点120具有的功能的代码、用于实现多副本间数据同步的代码、用于实现数据迁移的代码)进行组合,便可得到子应用模块Map对应的应用服务110,即应用Map对应的分布式服务100。
前文结合图2-图11,详细描述了本申请实施例提供的分布式服务生成系统的功能,下面结合图12,从该系统的结构方面对其展开详细描述。
图12示例性地展示了上述分布式服务生成系统的结构示意图。如图12所示,分布式服务生成系统200包括获取单元210和编译单元220,可选的,该系统还包括调试单元230。其中,获取单元210、编译单元220和调试单元230协同工作以实现上述方法实施例中分布式服务生成系统所执行的步骤。具体地,获取单元210用于执行上述S101;编译单元220用于执行上述S102;调试单元230用于执行上述S103。
本申请实施例中,获取单元210、编译单元220和调试单元230均可以通过软件实现,或者可以通过硬件实现。示例性的,接下来以获取单元210为例,介绍获取单元210的实现方式。类似的,编译单元220和调试单元230的实现方式可以参考获取单元210的实现方式。
作为软件功能单元的一种举例,获取单元210可以包括运行在计算实例上的代码。其中,计算实例可以包括物理主机(计算设备)、虚拟机、容器中的至少一种。进一步地,上述计算实例可以是一台或者多台。例如,获取单元210可以包括运行在多个主机/虚拟机/容器上的代码。需要说明的是,用于运行该代码的多个主机/虚拟机/容器可以分布在相同的区域(region)中,也可以分布在不同的region中。进一步地,用于运行该代码的多个主机/虚拟机/容器可以分布在相同的可用区(availability zone,AZ)中,也可以分布在不同的AZ中,每个AZ包括一个数据中心或多个地理位置相近的数据中心。其中,通常一个region可以包括多个AZ。
同样,用于运行该代码的多个主机/虚拟机/容器可以分布在同一个虚拟私有云(virtual private cloud,VPC)中,也可以分布在多个VPC中。其中,通常一个VPC设置在一个region内,同一region内两个VPC之间,以及不同region的VPC之间跨区通信需在每个VPC内设置通信网关,经通信网关实现VPC之间的互连。
作为硬件功能单元的一种举例,获取单元210可以包括至少一个计算设备,如服务器等。或者,获取单元210也可以是利用专用集成电路(application-specific integrated circuit,ASIC)实现、或可编程逻辑器件(programmable logic device,PLD)实现的设备等。其中,上述PLD可以是复杂程序逻辑器件(complex programmable logical device,CPLD)、现场可编程门阵列(field-programmable gate array,FPGA)、通用阵列逻辑(generic array logic,GAL)或其任意组合实现。
获取单元210包括的多个计算设备可以分布在相同的region中,也可以分布在不同的region中。获取单元210包括的多个计算设备可以分布在相同的AZ中,也可以分布在不同的AZ中。同样,获取单元210包括的多个计算设备可以分布在同一个VPC中,也可以分布在多个VPC中。其中,所述多个计算设备可以是服务器、ASIC、PLD、CPLD、FPGA和GAL等计算设备的任意组合。
需要说明的是,在其他实施例中,获取单元210可以用于执行上述S101-S103中的任意步骤,编译单元220可以用于执行上述S101-S103中的任意步骤,调试单元230可以用于执行上述S101-S103中的任意步骤,获取单元210、编译单元220和调试单元230负责实现的步骤可根据需要进行指定,通过获取单元210、编译单元220和调试单元230分别实现上述分布式服务生成方法(包括上述S101-S103)中不同的步骤来实现分布式服务生成系统的全部功能。
本申请实施例还提供一种计算设备。如图13所示,计算设备300包括总线310、处理器320、存储器330以及通信接口340。处理器320、存储器330和通信接口340之间通过总线310通信。计算设备300可以是服务器或终端设备。应理解,本申请实施例不限定计算设备300中的处理器、存储器的个数。
总线310可以是外设部件互连标准(peripheral component interconnect,PCI)总线或扩展工业标准结构(extended industry standard architecture,EISA)总线等。总线可以分为地址总线、数据总线、控制总线等。为便于表示,图13中仅用一条线表示,但并不表示仅有一根总线或一种类型的总线。总线310可包括在计算设备300各个部件(例如:存储器330、处理器320、通信接口340)之间传送信息的通路。
处理器320可以包括CPU、图形处理器(graphics processing unit,GPU)、微处理器(micro processor,MP)或者数字信号处理器(digital signal processor,DSP)等处理器中的任意一种或多种。
存储器330可以包括易失性存储器(volatile memory),例如随机存取存储器(random access memory,RAM)。处理器320还可以包括非易失性存储器(non-volatile memory),例如只读存储器(read-only memory,ROM),快闪存储器,机械硬盘(hard disk drive,HDD)或固态硬盘(solid state drive,SSD)。
存储器330中存储有可执行的程序代码,处理器320执行该可执行的程序代码以分别实现前述获取单元210、编译单元220和调试单元230的功能,从而实现前文所描述的分布式服务生成方法(包括上述S101-S103)。也即,存储器330上存有用于执行前文所描述的分布式服务生成方法的指令。
通信接口340使用例如但不限于网络接口卡、收发器一类的收发模块,来实现计算设备300与其他设备或通信网络之间的通信。
本申请实施例还提供了一种包含指令的计算机程序产品。该计算机程序产品可以是包含指令的、能够运行在计算设备上或被储存在任何可用介质中的软件或程序产品。当该计算机程序产品在至少一个计算设备上运行时,使得至少一个计算设备执行前文所描述的分布式服务生成方法。
本申请实施例还提供了一种计算机可读存储介质。该计算机可读存储介质可以是计算设备能够存储的任何可用介质或者是包含一个或多个可用介质的数据中心等数据存储设备,其中,可用介质可以是磁性介质(例如:软盘、硬盘、磁带)、光介质(例如:DVD)、或者半导体介质(例如:固态硬盘)等。该计算机可读存储介质包括指令,其中,指令指示计算设备执行前文所描述的分布式服务生成方法,或指示计算设备执行前文所描述的分布式服务生成方法。
最后应说明的是:以上实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的保护范围。

Claims (18)

  1. 一种分布式服务生成方法,其特征在于,包括:
    获取应用的程序源码,其中,所述应用的程序源码包括多个标记,所述多个标记包括用于标记所述应用中的子应用模块的第一标记和用于标记所述子应用模块中的接口方法的第二标记;
    根据所述多个标记对所述应用的程序源码进行编译,得到所述子应用模块对应的分布式服务,其中,所述分布式服务包括所述接口方法被执行时所实现的子服务。
  2. 根据权利要求1所述的方法,其特征在于,所述根据多个标记对所述应用的程序源码进行编译,得到所述子应用模块对应的分布式服务,包括:
    对所述应用的程序源码进行编译,获得所述应用的业务逻辑;
    使用至少一个代码生成工具,根据所述多个标记得到所述分布式服务的调用代码,其中,所述分布式服务的调用代码用于指示所述分布式服务的客户端调用所述分布式服务的服务端上的子服务;
    将所述应用的业务逻辑、所述分布式服务的调用代码和所述分布式服务关联的框架代码进行组合,得到所述分布式服务。
  3. 根据权利要求2所述的方法,其特征在于,所述使用至少一个代码生成工具,根据所述多个标记得到所述分布式服务的调用代码,包括:
    使用远程过程调用RPC服务端代码生成工具,根据所述多个标记得到RPC服务端,其中,所述RPC服务端用于为所述分布式服务的服务端提供服务接口,使得所述分布式服务的客户端通过所述RPC服务端调用所述分布式服务的服务端上的子服务。
  4. 根据权利要求3所述的方法,其特征在于,所述分布式服务的客户端包括RPC客户端;
    所述使用至少一个代码生成工具,根据所述多个标记得到所述分布式服务的调用代码,包括:
    使用RPC客户端代码生成工具,根据所述多个标记得到所述RPC客户端,其中,所述RPC客户端通过调用所述RPC服务端以获得所述分布式服务的服务端上的子服务。
  5. 根据权利要求3所述的方法,其特征在于,所述分布式服务的服务端包括多个副本,所述分布式服务的客户端包括副本客户端;
    所述使用至少一个代码生成工具,根据所述多个标记得到所述分布式服务的调用代码,包括:
    使用副本客户端代码生成工具,根据所述多个标记得到所述副本客户端,其中,所述副本客户端用于指示调用所述多个副本中的一个副本上的子服务。
  6. 根据权利要求3所述的方法,其特征在于,所述分布式服务的服务端包括多个分片,所述分布式服务的客户端包括分片客户端;
    所述使用至少一个代码生成工具,根据所述多个标记得到所述分布式服务的调用代码,包括:
    使用分片客户端代码生成工具,根据所述多个标记得到所述分片客户端,其中,所述分片客户端用于指示调用所述多个分片中的至少一个分片上的子服务。
  7. 根据权利要求3所述的方法,其特征在于,所述分布式服务的客户端包括集群客户端;
    所述使用至少一个代码生成工具,根据所述多个标记得到所述分布式服务的调用代码,包括:
    使用集群客户端代码生成工具,根据所述多个标记得到所述集群客户端,其中,所述集群客户端用于获取所述分布式服务的服务端的状态信息,并根据所述状态信息创建所述分布式服务的客户端的实例。
  8. 根据权利要求2-7任一项所述的方法,其特征在于,所述方法还包括:
    根据所述分布式服务的调用代码对所述分布式服务进行调试。
  9. 一种分布式服务生成系统,其特征在于,包括:
    获取单元,用于获取应用的程序源码,其中,所述应用的程序源码包括多个标记,所述多个标记包括用于标记所述应用中的子应用模块的第一标记和用于标记所述子应用模块中的接口方法的第二标记;
    编译单元,用于根据所述多个标记对所述应用的程序源码进行编译,得到所述子应用模块对应的分布式服务,其中,所述分布式服务包括所述接口方法被执行时所实现的子服务。
  10. 根据权利要求9所述的系统,其特征在于,
    所述编译单元,用于对所述应用的程序源码进行编译,获得所述应用的业务逻辑;使用至少一个代码生成工具,根据所述多个标记得到所述分布式服务的调用代码,其中,所述分布式服务的调用代码用于指示所述分布式服务的客户端调用所述分布式服务的服务端上的子服务;将所述应用的业务逻辑、所述分布式服务的调用代码和所述分布式服务关联的框架代码进行组合,得到所述分布式服务。
  11. 根据权利要求10所述的系统,其特征在于,
    所述编译单元,用于使用远程过程调用协议RPC服务端代码生成工具,根据所述多个标记得到RPC服务端,其中,所述RPC服务端用于为所述分布式服务的服务端提供服务接口,使得所述分布式服务的客户端通过所述RPC服务端调用所述分布式服务的服务端上的子服务。
  12. 根据权利要求11所述的系统,其特征在于,所述分布式服务的客户端包括RPC客户端;
    所述编译单元,用于使用RPC客户端代码生成工具,根据所述多个标记得到所述RPC客户端,其中,所述RPC客户端通过调用所述RPC服务端以获得所述分布式服务的服务端上的子服务。
  13. 根据权利要求11所述的系统,其特征在于,所述分布式服务的服务端包括多个副本,所述分布式服务的客户端包括副本客户端;
    所述编译单元,用于使用副本客户端代码生成工具,根据所述多个标记得到所述副本客户端,其中,所述副本客户端用于指示调用所述多个副本中的一个副本上的子服务。
  14. 根据权利要求11所述的系统,其特征在于,所述分布式服务的服务端包括多个分片,所述分布式服务的客户端包括分片客户端;
    所述编译单元,用于使用分片客户端代码生成工具,根据所述多个标记得到所述分片客户端,其中,所述分片客户端用于指示调用所述多个分片中的至少一个分片上的子服务。
  15. 根据权利要求11所述的系统,其特征在于,所述分布式服务的客户端包括集群客户端;
    所述编译单元,用于使用集群客户端代码生成工具,根据所述多个标记得到所述集群客户端,其中,所述集群客户端用于获取所述分布式服务的服务端的状态信息,并根据所述状态信息创建所述分布式服务的客户端的实例。
  16. 根据权利要求10-15任一项所述的系统,其特征在于,还包括:
    调试单元,用于根据所述分布式服务的调用代码对所述分布式服务进行调试。
  17. 一种计算设备,其特征在于,包括处理器和存储器,所述处理器执行所述存储器中的计算机程序代码以实现前述权利要求1-8所述的任一项方法。
  18. 一种计算机可读存储介质,其特征在于,存储有计算机程序代码,当所述计算机程序代码被计算设备执行时,所述计算设备执行前述权利要求1-8任一项所述的方法。
PCT/CN2023/098619 2022-07-13 2023-06-06 分布式服务生成方法、系统、计算设备及存储介质 WO2024012101A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210820850.0A CN117435201A (zh) 2022-07-13 2022-07-13 分布式服务生成方法、系统、计算设备及存储介质
CN202210820850.0 2022-07-13

Publications (1)

Publication Number Publication Date
WO2024012101A1 true WO2024012101A1 (zh) 2024-01-18

Family

ID=89535462

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/098619 WO2024012101A1 (zh) 2022-07-13 2023-06-06 分布式服务生成方法、系统、计算设备及存储介质

Country Status (2)

Country Link
CN (1) CN117435201A (zh)
WO (1) WO2024012101A1 (zh)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100242017A1 (en) * 2009-03-20 2010-09-23 Microsoft Corporation Inferring missing type information for reflection
CN108292349A (zh) * 2015-10-26 2018-07-17 亚马逊科技有限公司 在分布式计算环境中提供虚拟机实例的细粒度访问远程命令执行
CN112416338A (zh) * 2020-11-26 2021-02-26 上海睿成软件有限公司 一种基于标签的代码仓库系统
CN113722204A (zh) * 2020-05-26 2021-11-30 华为技术有限公司 一种应用调试方法、系统、设备及介质
CN114327742A (zh) * 2020-09-30 2022-04-12 华为云计算技术有限公司 云平台及基于云平台的程序代码处理方法

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100242017A1 (en) * 2009-03-20 2010-09-23 Microsoft Corporation Inferring missing type information for reflection
CN108292349A (zh) * 2015-10-26 2018-07-17 亚马逊科技有限公司 在分布式计算环境中提供虚拟机实例的细粒度访问远程命令执行
CN113722204A (zh) * 2020-05-26 2021-11-30 华为技术有限公司 一种应用调试方法、系统、设备及介质
CN114327742A (zh) * 2020-09-30 2022-04-12 华为云计算技术有限公司 云平台及基于云平台的程序代码处理方法
CN112416338A (zh) * 2020-11-26 2021-02-26 上海睿成软件有限公司 一种基于标签的代码仓库系统

Also Published As

Publication number Publication date
CN117435201A (zh) 2024-01-23

Similar Documents

Publication Publication Date Title
US20210048998A1 (en) Container-based server environments
US20200067802A1 (en) Communication between independent containers
US20210048995A1 (en) Conversion and restoration of computer environments to container-based implementations
US8819672B2 (en) Multi-image migration system and method
US8788569B2 (en) Server computer system running versions of an application simultaneously
JP5259924B2 (ja) レガシーコンポーネントのための動的サービスの生成
JP7360395B2 (ja) 入力および出力スキーママッピング
US20090172636A1 (en) Interactive development tool and debugger for web services
US20090320045A1 (en) Server computer component
US9442822B2 (en) Providing a visual representation of a sub-set of a visual program
US10140121B2 (en) Sending a command with client information to allow any remote server to communicate directly with client
US11595299B2 (en) System and method of suppressing inbound payload to an integration flow of an orchestration based application integration
US10872007B2 (en) Methods and systems to compound alerts in a distributed computing system
US11537367B1 (en) Source code conversion from application program interface to policy document
US20220092038A1 (en) System and method for customized graphql data-handling scripts
US11531526B1 (en) Creating portable serverless applications
CN114448895A (zh) 一种应用访问方法、装置、设备及介质
US8997116B2 (en) Event logging application programming interface (API)
US11494184B1 (en) Creation of transportability container files for serverless applications
CN108496157B (zh) 使用扩展接口提供运行时跟踪的系统和方法
US10713014B2 (en) Multi-platform interface framework
WO2024012101A1 (zh) 分布式服务生成方法、系统、计算设备及存储介质
JP2021505989A (ja) エラー・ハンドリングのための方法、コンピュータ・プログラム、データ処理システム、およびエラー・ハンドリング・コンポーネント
WO2022226205A1 (en) System and method for packaging standalone application modules into re-usable application and infrastructure resources
CN114610381A (zh) 一种方法服务的调用方法、装置、设备及存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 23838595

Country of ref document: EP

Kind code of ref document: A1