CN111262907B - Service instance access method and device and electronic equipment - Google Patents
Service instance access method and device and electronic equipment Download PDFInfo
- Publication number
- CN111262907B CN111262907B CN202010020522.3A CN202010020522A CN111262907B CN 111262907 B CN111262907 B CN 111262907B CN 202010020522 A CN202010020522 A CN 202010020522A CN 111262907 B CN111262907 B CN 111262907B
- Authority
- CN
- China
- Prior art keywords
- fragment
- service instance
- service
- fragments
- target
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
- H04L67/1097—Protocols in which an application is distributed across nodes in the network for distributed storage of data in networks, e.g. transport arrangements for network file system [NFS], storage area networks [SAN] or network attached storage [NAS]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L61/00—Network arrangements, protocols or services for addressing or naming
- H04L61/50—Address allocation
- H04L61/5053—Lease time; Renewal aspects
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/50—Network services
- H04L67/60—Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Information Transfer Between Computers (AREA)
Abstract
The embodiment of the disclosure discloses a service instance access method, a service instance access device and electronic equipment. One embodiment of the method comprises: determining a fragment to which each service instance in a service instance set obtained in advance belongs from a preset number of fragments; determining a target fragment from a preset number of fragments in response to receiving a query request sent by a client; and feeding back the service address of the target service instance selected from the target fragment to the client, wherein the service address is used for the client to access the target service instance under the service address. The implementation method realizes the access of the client to the service instance on the premise of reducing the workload of the server.
Description
Technical Field
The present disclosure relates to the field of internet technologies, and in particular, to a method and an apparatus for accessing a service instance, and an electronic device.
Background
In a distributed system, multiple service instances (service instances) may be deployed for one service. On the one hand, the access of a large number of clients to the same service can be distributed to a plurality of service instances, and further the pressure of the service is relieved. On the other hand, when part of the service instances have faults, the access of the client is distributed to the service instances which have no faults, and the normal operation of the service is further ensured.
In practical applications, a client needs to determine a service address of a service instance before accessing the service instance. It is understood that the service address of a service instance is the address at which the service instance is deployed and provides services in the distributed system.
Disclosure of Invention
This disclosure is provided to introduce concepts in a simplified form that are further described below in the detailed description. This disclosure is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.
The embodiment of the disclosure provides a service instance access method, a service instance access device and electronic equipment, which are used for realizing the access of a client to a service instance on the premise of reducing the workload of a server.
In a first aspect, an embodiment of the present disclosure provides a service instance access method, where the method includes: determining a fragment to which each service instance in a service instance set obtained in advance belongs from a preset number of fragments; determining a target fragment from a preset number of fragments in response to receiving a query request sent by a client; and feeding back the service address of the target service instance selected from the target fragment to the client, wherein the service address is used for the client to access the target service instance under the service address.
In a second aspect, an embodiment of the present disclosure provides a service instance access apparatus, including: the first determining unit is used for determining the fragments to which each service instance in the service instance set obtained in advance belongs from the fragments with the preset number; the second determining unit is used for determining the target fragments from the fragments with the preset number in response to receiving the query request sent by the client; and the feedback unit is used for feeding back the service address of the target service instance selected from the target fragment to the client, wherein the service address is used for the client to access the target service instance under the service address.
In a third aspect, an embodiment of the present disclosure provides an electronic device, including: one or more processors; storage means for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to implement the service instance access method as described in the first aspect.
In a fourth aspect, the disclosed embodiments provide a computer readable medium, on which a computer program is stored, which when executed by a processor, implements the steps of the service instance access method according to the first aspect.
The service instance access method, the service instance access device and the electronic device provided by the embodiment of the disclosure can determine the segment to which each service instance in the service instance set acquired in advance belongs from the preset number of segments, can determine the target segment from the preset number of segments if receiving the query request sent by the client, and further can feed back the service address of the target service instance selected from the target segment to the client. After receiving the service address, the client may access the target service instance at the service address. In order to ensure the smooth proceeding of the process of accessing the service instance by the client, the service end only needs to update the service address of the service instance contained in the partial fragment and only needs to notify the client currently accessing the service instance in the partial fragment. Therefore, the client side can access the service instance on the premise of reducing the workload of the server side.
Drawings
The above and other features, advantages and aspects of various embodiments of the present disclosure will become more apparent by referring to the following detailed description when taken in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numbers refer to the same or similar elements. It should be understood that the drawings are schematic and that elements and features are not necessarily drawn to scale.
FIG. 1 is a flow diagram for one embodiment of a service instance access method according to the present disclosure;
FIG. 2 is a schematic diagram of one application scenario of a service instance access method according to the present disclosure;
FIG. 3 is a flow diagram of yet another embodiment of a service instance access method according to the present disclosure;
FIG. 4 is a schematic diagram of one application scenario for determining a shard to which a service instance belongs according to the present disclosure;
FIG. 5 is a schematic diagram illustrating one embodiment of a service instance access device, according to the present disclosure;
FIG. 6 is an exemplary system architecture to which the service instance access method of one embodiment of the present disclosure may be applied;
fig. 7 is a schematic diagram of a basic structure of an electronic device provided according to an embodiment of the present disclosure.
Detailed Description
Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure are shown in the drawings, it is to be understood that the present disclosure may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but rather are provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the disclosure are for illustration purposes only and are not intended to limit the scope of the disclosure.
It should be understood that the various steps recited in the method embodiments of the present disclosure may be performed in a different order, and/or performed in parallel. Moreover, method embodiments may include additional steps and/or omit performing the illustrated steps. The scope of the present disclosure is not limited in this respect.
The term "include" and variations thereof as used herein are open-ended, i.e., "including but not limited to". The term "based on" is "based, at least in part, on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions for other terms will be given in the following description.
It should be noted that the terms "first", "second", and the like in the present disclosure are only used for distinguishing different devices, modules or units, and are not used for limiting the order or interdependence relationship of the functions performed by the devices, modules or units.
It is noted that references to "a", "an", and "the" modifications in this disclosure are intended to be illustrative rather than limiting, and that those skilled in the art will recognize that "one or more" may be used unless the context clearly dictates otherwise.
The names of messages or information exchanged between devices in the embodiments of the present disclosure are for illustrative purposes only, and are not intended to limit the scope of the messages or information.
Referring to FIG. 1, a flow diagram of one embodiment of a service instance access method according to the present disclosure is shown. The service instance access method shown in fig. 1 includes the following steps:
In this embodiment, the electronic device executing the service instance access method may obtain the service instance set from a local or communicatively connected database server.
In this embodiment, after obtaining the service instance set, the electronic device executing the service instance access method may determine, from a preset number of pieces, a piece to which each service instance in the service instance set belongs.
Specifically, the electronic device executing the service instance access method may divide the plurality of service instances in the service instance set into different segments on the premise of ensuring that the number of service instances in each segment is as consistent as possible, thereby determining the segment to which each service instance belongs.
In some optional implementations, the preset number is rounded down by a ratio of the number of service instances in the service instance set to the number of service instances each segment is expected to contain. For example, if the number of service instances in the service instance set is x and the number of service instances expected to be included in each slice is y, the preset number may beAnd carrying out downward rounding to obtain an integer.
In this embodiment, after determining the segment to which each service instance belongs, if receiving a query request sent by a client, the electronic device executing the service instance access method may determine the target segment from the preset number of segments.
The query request may be a request that the client initiates when querying the service address of the service instance.
The target shard may be a shard from which a service instance to be distributed to the client is selected.
Specifically, the electronic device executing the service instance access method may select one segment with a smaller number of currently accessed clients from the preset number of segments as the target segment.
And 103, feeding back the service address of the target service instance selected from the target fragment to the client.
In this embodiment, after determining the target fragment, the electronic device executing the service instance access method may select the target service instance from the target fragment.
The target service instance may be a service instance to be distributed to the client for the client to access.
Specifically, the electronic device executing the service instance access method may select one service instance with a smaller number of currently accessed clients from the service instances included in the target fragment as the target service instance.
In this embodiment, after selecting the target service instance, the electronic device executing the service instance access method may obtain the service address of the target service instance from a local or communicatively connected database server, and feed back the service address of the target service instance to the client.
The service address is used for the client to access the target service instance under the service address. That is, after receiving the service address of the target service instance, the client may send an access request to the service address, so as to access the target service instance.
Referring to fig. 2, an application scenario of a service instance access method according to an embodiment of the present disclosure is shown. As shown in fig. 2, the server 201 may determine, from the shard 202 and the shard 203, a shard to which each service instance in the service instance set 204 belongs. Other service instances, such as service instance 2041, service instance 2042, and service instance 2043, may be included in the service instance collection 204. As shown, the server 201 can determine that the service instance 2041 belongs to the shard 203 and that the service instance 2042 and the service instance 2043 belong to the shard 202. In response to receiving a query request sent by the client 205, the server 201 may determine the shard 202 as a target shard. Further, the service 201 may select the service instance 2042 from the shards 202 as a target service instance, and feed back the service address 206 of the service instance 2042 to the client 205. Upon receiving the service address 206, the client 205 may access the service instance 2042 under the service address 206.
Currently, in terms of accessing a service instance by a client, the service instance is offline or online, which causes the service address of each service instance to change. In the related art, in order to ensure that the process of accessing the service instance by the client is performed smoothly, the service end needs to update the service address of each service instance at intervals (for example, 5 seconds), and notify the client accessing the service instance currently about the service address change. In this embodiment, before the client accesses the service instance, the segment to which each service instance belongs is determined, and as the service instance goes offline or comes online, only the service address of the service instance included in part of the segments is changed. In order to ensure the smooth proceeding of the process of accessing the service instance by the client, the service end only needs to update the service address of the service instance contained in the partial fragment and only needs to notify the client currently accessing the service instance in the partial fragment. Therefore, the client side can access the service instance on the premise of reducing the workload of the server side.
Continuing to refer to FIG. 3, a flow diagram of yet another embodiment of a service instance access method according to the present disclosure is shown. As shown in fig. 3, the service instance access method includes the following steps:
In this embodiment, for each of the preset number of fragments, the electronic device executing the service instance access method may map the fragment and each target virtual fragment of the fragment to the first hash ring.
The target virtual shard may be a partition provided for shards for mapping to the first hash ring.
Here, the mapping may be a process of matching the uniquely identified hash value with the hash value corresponding to the node on the first hash ring.
Specifically, the electronic device executing the service instance access method may map the fragment to the first hash ring by matching a hash value of the unique identifier of the fragment with a hash value corresponding to a node on the first hash ring. Similarly, the target virtual fragment may be mapped to the first hash ring by matching the hash value of the unique identifier of the target virtual fragment with the hash value corresponding to the node on the first hash ring.
For example, a large number of nodes, such as node M1, node M2, etc., are distributed on the first hash ring. If the hash value of the unique identifier of a certain fragment is the same as the hash value corresponding to the node M1, the fragment may be matched to the position of the node M1 in the first hash ring. If the hash value of a certain target virtual partition is the same as the hash value corresponding to the node M2, the target virtual partition may be matched to the position of the node M2 in the first hash ring.
In this embodiment, the electronic device executing the service instance access method may further map each service instance in the service instance set to the first hash ring.
In practice, the service instance may be mapped to the first hash ring by matching the uniquely identified hash value of the service instance to the hash value corresponding to the node on the first hash ring. The process of mapping the service instance to the first hash ring is similar to the process of mapping the fragment to the first hash ring, and is not described here again.
It will be appreciated that mapping each segment, each target virtual segment of each segment, and each service instance to the first hash ring means matching each segment, each target virtual segment of each segment, and each service instance to the location of the corresponding node on the first hash ring.
In this embodiment, after mapping each segment, each target virtual segment of each segment, and each service instance to the first hash ring, the electronic device executing the service instance access method may determine, from a preset number of segments, a segment to which each service instance belongs, according to a position at which each segment, each target virtual segment of each segment, and each service instance are respectively mapped to the first hash ring.
Specifically, for each service instance, the electronic device executing the service instance access method may move clockwise along the first hash ring with a position of the service instance mapped to the first hash ring as a starting point, determine a first moved fragment or a target virtual fragment from the first hash ring, and further take the first moved fragment as a fragment to which the service instance belongs, or take a fragment corresponding to the first moved target virtual fragment as a fragment to which the service instance belongs.
Taking fig. 4 as an example, in the first hash ring, the service instance a is mapped to the location of the node 402, the service instance B is mapped to the location of the node 404, the partition N1 is mapped to the location of the node 401, the partition N2 is mapped to the location of the node 405, the target virtual partition N11 of the partition N1 is mapped to the location of the node 403, and the target virtual partition N2 and the target virtual partition N21 are mapped to the location of the node 406. For the service instance a, the electronic device executing the service instance access method may move clockwise with the position of the node 402 as a starting point, and move to the target virtual partition N11 for the first time, so that the electronic device executing the service instance access method may use the partition N1 corresponding to the target virtual partition N11 as the partition to which the service instance a belongs. For service instance B, the electronic device executing the service instance access method may move clockwise from the location of the node 404 as a starting point and move to the slice N2 for the first time, and therefore, the electronic device executing the service instance access method may use the slice N2 as the slice to which the service instance B belongs.
And 305, feeding back the service address of the target service instance selected from the target fragment to the client.
Step 304 and step 305 may be performed in a similar manner as step 102 and step 103 in the embodiment shown in fig. 1, and the above description for step 102 and step 103 also applies to step 304 and step 305, which is not described herein again.
In some optional implementations, before performing step 301, the electronic device executing the service instance access method may determine the number of target virtual shards for each of the preset number of shards.
In some application scenarios, an electronic device executing the service instance access method may use a preset number for each slice as the number of target virtual slices of the slice.
In these optional implementation manners, the number of the target virtual fragments of each fragment is determined, and then each target virtual fragment of each fragment is mapped to the first hash ring, so that the target virtual fragments of a corresponding number are mapped to the first hash ring according to actual requirements. In some alternative implementations, the electronic device executing the service instance access method may determine the number of target virtual shards of each of the preset number of shards in the manners shown in steps S1 to S4.
Step S1, for each shard, mapping the shard and a plurality of initial virtual shards of the shard to a second hash ring.
The initial virtual shard may be a partition provided for shards for mapping to the second hash ring. In practice, the number of initial virtual shards of different shards may be the same or a smaller difference.
In step S2, each service instance in the set of service instances is mapped to a second hash ring.
Step S3, for each fragment, determining a service instance belonging to the fragment in the second hash ring according to the position where the fragment, each initial virtual fragment of the fragment, and each service instance are respectively mapped to the second hash ring.
In practice, the electronic device executing the service instance access method may execute step S1, step S2, and step S3 in a manner similar to that described in step 301, step 302, and step 303, and will not be described herein again.
Step S4, for each fragment, determining the number of target virtual fragments of the fragment according to the number of initial virtual fragments of the fragment and the number of service instances belonging to the fragment in the second hash ring.
For each fragment, after determining each service instance belonging to the fragment in the second hash ring, the electronic device executing the service instance access method may determine the number of target virtual fragments of the fragment according to the number of initial virtual fragments of the fragment and the number of service instances belonging to the fragment in the second hash ring.
Specifically, a correspondence table for determining the number of the target virtual shards may be obtained in advance according to historical data statistics, and the number of the initial virtual shards and the number of the service instances in the correspondence table correspond to the number of one target virtual shard. In practice, the correspondence table is stored in a database server local to or communicatively connected to the electronic device executing the service instance access method. Therefore, for each fragment, the electronic device executing the service instance access method may query the correspondence table by using the number of the initial virtual fragments of the fragment and the number of the service instances belonging to the fragment in the second hash ring, and further determine the number of the target virtual fragments of the fragment.
In these optional implementations, by determining the number of target virtual shards of a shard by combining the number of initial virtual shards of the shard and the number of service instances belonging to the shard in the second hash ring, the number of target virtual shards of each shard is accurately determined.
In some optional implementations, for each shard, the electronic device executing the service instance access method may round down a square root of a product of the number of initial virtual shards of the shard and the number of service instances belonging to the shard in the second hash ring to obtain a target number of virtual shards of the shard. For example, if the number of initial virtual shards of a certain shard is m, and the number of service instances belonging to the shard in the second hash ring is n, then the number of target virtual shards of the shard is mAnd carrying out downward rounding to obtain an integer.
In some alternative implementations, the electronic device performing the service instance access method may perform step 304 as shown in steps L1 through L2.
Step L1, maps the client to the first hash ring.
Specifically, the electronic device executing the service instance access method may map the client to the first hash ring by matching a hash value of the unique identifier of the client with a hash value corresponding to a node on the first hash ring. The process of mapping the client to the first hash ring is similar to the process of mapping the fragments to the first hash ring, and is not described herein again.
Step L2, determining the target shard from the preset number of shards according to the client, each shard, and the position of each target virtual shard of each shard mapped to the first hash ring.
Specifically, after the client is mapped to the first hash ring, the electronic device executing the service instance access method may move clockwise along the first hash ring with a position where the client is mapped to the first hash ring as a starting point, determine a first moved segment or a target virtual segment from the first hash ring, and further determine the first moved segment as the target segment, or determine a segment corresponding to the first moved target virtual segment as the target segment.
In these optional implementation manners, the target segment is determined by mapping the client to the first hash ring, and compared with selecting a segment with a smaller number of currently accessed clients from the preset number of segments as the target segment, the number of currently accessed clients in each segment can be prevented from being acquired in real time, so that the process of determining the target segment is simplified.
In this embodiment, in the process of determining the segment to which each service instance belongs, by combining each segment, each target virtual segment of each segment, and the position of each service instance mapped to the first hash ring, the segment to which each service instance belongs is accurately determined.
With further reference to fig. 5, as an implementation of the methods shown in the above-mentioned figures, the present disclosure provides an embodiment of a service instance access apparatus, which corresponds to the method embodiment shown in fig. 1, and which is specifically applicable to various electronic devices.
As shown in fig. 5, the service instance access apparatus of the present embodiment includes: a first determination unit 501, a second determination unit 502 and a feedback unit 503. The first determining unit 501 is configured to: the method comprises the steps of determining a fragment to which each service instance in a service instance set obtained in advance belongs from a preset number of fragments; the second determining unit 502 is configured to: determining a target fragment from a preset number of fragments in response to receiving a query request sent by a client; the feedback unit 503 is configured to: and feeding back the service address of the target service instance selected from the target fragment to the client, wherein the service address can be used for the client to access the target service instance under the service address.
In this embodiment, specific processing of the first determining unit 501, the second determining unit 502, and the feedback unit 503 of the service instance access apparatus and technical effects thereof may refer to related descriptions of step 101, step 102, and step 103 in the corresponding embodiment of fig. 1, which are not described herein again.
In some optional implementations, the first determining unit 501 may include: a first mapping subunit (not shown), a second mapping subunit (not shown), and a first determining subunit (not shown). Wherein the first mapping subunit may be configured to: for each shard, the shard and respective target virtual shards of the shard are mapped to a first hash ring. The second mapping subunit may be to: each service instance in the set of service instances is mapped to a first hash ring. The first determining subunit may be to: and determining the fragment to which each service instance belongs from the preset number of fragments according to the position of each fragment, each target virtual fragment of each fragment and each service instance mapped to the first hash ring.
In some optional implementations, the first determining unit 501 may further include a second determining subunit (not shown in the figure). Wherein the second determining subunit is operable to: determining the number of target virtual shards of each shard in the preset number of shards.
In some optional implementations, the second determining subunit may include: a first mapping module (not shown), a second mapping module (not shown), a first determining module (not shown), and a second determining module (not shown). Wherein the first mapping module may be configured to: for each fragment, mapping the fragment and a plurality of initial virtual fragments of the fragment to a second hash ring; the second mapping module may be to: each service instance in the set of service instances is mapped to a second hash ring. The first determining module may be to: and for each fragment, determining the service instance belonging to the fragment in the second hash ring according to the fragment, each initial virtual fragment of the fragment and the position of each service instance mapped to the second hash ring. The second determination module may be to: and for each fragment, determining the number of target virtual fragments of the fragment according to the number of initial virtual fragments of the fragment and the number of service instances belonging to the fragment in the second hash ring.
In some optional implementations, the second determining module may be further configured to: and rounding down the square root of the product of the number of the initial virtual fragments of the fragment and the number of the service instances belonging to the fragment in the second hash ring to obtain the number of the target virtual fragments of the fragment.
In some alternative implementations, the preset number is rounded down by a ratio of the number of service instances in the service instance set to the number of service instances each segment is expected to contain.
In some optional implementations, the second determining unit 502 may be further configured to: mapping the client to a first hash ring; and determining the target fragments from the preset number of fragments according to the positions of the client, each fragment and each target virtual fragment of each fragment mapped to the first hash ring.
With further reference to fig. 6, fig. 6 illustrates an exemplary system architecture to which the service instance access method of one embodiment of the present disclosure may be applied.
As shown in fig. 6, the system architecture may include terminals 601, 602, a network 603, and a server 604. The network 603 serves to provide a medium for communication links between the terminals 601, 602 and the server 604. Network 603 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The terminals 601, 602 may interact with the server 604 via the network 603 to receive or send messages or the like. The terminals 601, 602 may have various client applications installed thereon, such as a web browser application, a search-type application, and a news-information-type application. In some application scenarios, a client application in the terminal 601, 602 may send a query request to the server 604 through the network 603, and receive a service address of a target service instance fed back by the server 604, so as to access the target service instance under the service address.
The terminals 601 and 602 may be hardware or software. When the terminals 601, 602 are hardware, they may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, laptop portable computers, desktop computers, and the like. When the terminals 601 and 602 are software, they can be installed in the electronic devices listed above. It may be implemented as multiple pieces of software or software modules (e.g., software or software modules used to provide distributed services) or as a single piece of software or software module. And is not particularly limited herein.
The server 604 may be a server that provides various services. In some application scenarios, the service end 604 may determine the target segment and feed back the service address of the target service instance selected from the target segment to the terminals 601, 602.
The server 604 may be hardware or software. When the server 604 is hardware, it may be implemented as a distributed server cluster composed of multiple servers, or may be implemented as a single server. When the server 604 is software, it can be implemented as multiple pieces of software or software modules (e.g., multiple pieces of software or software modules used to provide distributed services), or as a single piece of software or software module. And is not particularly limited herein.
It should be noted that the service instance access method provided by the embodiment of the present disclosure may be executed by the server 604, and accordingly, the service instance access device may be disposed in the server 604.
It should be understood that the number of terminals, networks, and servers in fig. 6 is merely illustrative. There may be any number of terminals, networks, and servers, as desired for an implementation.
Referring now to FIG. 7, shown is a schematic diagram of an electronic device (e.g., the server of FIG. 7) suitable for use in implementing embodiments of the present disclosure. The terminal device in the embodiments of the present disclosure may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle terminal (e.g., a car navigation terminal), and the like, and a stationary terminal such as a digital TV, a desktop computer, and the like. The electronic device shown in fig. 7 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 7, the electronic device may include a processing device (e.g., central processing unit, graphics processor, etc.) 701, which may perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)702 or a program loaded from a storage device 708 into a Random Access Memory (RAM) 703. In the RAM703, various programs and data necessary for the operation of the electronic apparatus 700 are also stored. The processing device 701, the ROM 702, and the RAM703 are connected to each other by a bus 704. An input/output (I/O) interface 705 is also connected to bus 704.
Generally, the following devices may be connected to the I/O interface 705: input devices 706 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; an output device 707 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 708 including, for example, magnetic tape, hard disk, etc.; and a communication device 709. The communication device 709 may allow the electronic device to communicate wirelessly or by wire with other devices to exchange data. While fig. 7 illustrates an electronic device having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a non-transitory computer readable medium, the computer program containing program code for performing the method illustrated by the flow chart. In such embodiments, the computer program may be downloaded and installed from a network via the communication means 709, or may be installed from the storage means 708, or may be installed from the ROM 702. The computer program, when executed by the processing device 701, performs the above-described functions defined in the methods of the embodiments of the present disclosure.
It should be noted that the computer readable medium in the present disclosure can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
In some embodiments, the clients, servers may communicate using any currently known or future developed network Protocol, such as HTTP (HyperText Transfer Protocol), and may interconnect with any form or medium of digital data communication (e.g., a communications network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), the Internet (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed network.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.
The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: determining a fragment to which each service instance in a service instance set obtained in advance belongs from a preset number of fragments; determining a target fragment from a preset number of fragments in response to receiving a query request sent by a client; and feeding back a service address of the target service instance selected from the target fragment to the client, wherein the service address is used for the client to access the target service instance under the service address.
Computer program code for carrying out operations for the present disclosure may be written in any combination of one or more programming languages, including but not limited to an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present disclosure may be implemented by software or hardware. For example, the first determining unit may be further described as "a unit that determines, from a preset number of pieces, a piece to which each service instance in the service instance set obtained in advance belongs, from the preset number of pieces".
The functions described herein above may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), systems on a chip (SOCs), Complex Programmable Logic Devices (CPLDs), and the like.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the disclosure herein is not limited to the particular combination of features described above, but also encompasses other embodiments in which any combination of the features described above or their equivalents does not depart from the spirit of the disclosure. For example, the above features and (but not limited to) the features disclosed in this disclosure having similar functions are replaced with each other to form the technical solution.
Further, while operations are depicted in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limitations on the scope of the disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims.
Claims (14)
1. A method for accessing a service instance, comprising:
determining a fragment to which each service instance in a service instance set obtained in advance belongs from a preset number of fragments;
determining a target fragment from the preset number of fragments in response to receiving a query request sent by a client;
feeding back a service address of a target service instance selected from the target fragment to the client, wherein the service address is used for the client to access the target service instance under the service address;
the determining the fragments to which each service instance in the service instance set obtained in advance belongs from the fragments with the preset number comprises: for each fragment in the preset number of fragments, mapping the fragment and each target virtual fragment of the fragment to a first hash ring; mapping each service instance in the set of service instances to the first hash ring; and determining the fragment to which each service instance belongs from the preset number of fragments according to the position of each fragment, each target virtual fragment of each fragment and each service instance mapped to the first hash ring.
2. The method according to claim 1, wherein before mapping, for each of the preset number of fragments, the fragment to which each service instance in the service instance set obtained in advance belongs and each target virtual fragment of the fragment to the first hash ring, the method further includes:
and determining the number of the target virtual fragments of each fragment in the preset number of fragments.
3. The method of claim 2, wherein the determining the number of target virtual shards for each shard of the preset number of shards comprises:
for each fragment, mapping the fragment and a plurality of initial virtual fragments of the fragment to a second hash ring;
mapping each service instance in the set of service instances to the second hash ring;
for each fragment, determining the service instance belonging to the fragment in the second hash ring according to the fragment, each initial virtual fragment of the fragment and the position of each service instance mapped to the second hash ring;
and for each fragment, determining the number of target virtual fragments of the fragment according to the number of initial virtual fragments of the fragment and the number of service instances belonging to the fragment in the second hash ring.
4. The method of claim 3, wherein determining the number of target virtual shards for the shard according to the number of initial virtual shards for the shard and the number of service instances belonging to the shard in the second hash ring comprises:
and rounding down the square root of the product of the number of the initial virtual fragments of the fragment and the number of the service instances belonging to the fragment in the second hash ring to obtain the number of the target virtual fragments of the fragment.
5. The method of claim 1, wherein the preset number is rounded down by a ratio of a number of service instances in the service instance set to a number of service instances each segment is expected to contain.
6. The method according to any of claims 1-5, wherein the determining a target slice from the preset number of slices comprises:
mapping the client to the first hash ring;
and determining the target fragments from the preset number of fragments according to the positions of the client, each fragment and each target virtual fragment of each fragment mapped to the first hash ring.
7. A service instance access apparatus, comprising:
the first determining unit is used for determining the fragments to which each service instance in the service instance set obtained in advance belongs from the fragments with the preset number;
a second determining unit, configured to determine, in response to receiving a query request sent by a client, a target segment from the preset number of segments;
a feedback unit, configured to feed back a service address of a target service instance selected from the target segment to the client, where the service address is used for the client to access the target service instance under the service address;
the first determination unit includes: a first mapping subunit, configured to map, for each of the preset number of fragments, the fragment and each target virtual fragment of the fragment to a first hash ring; a second mapping subunit configured to map each service instance in the set of service instances to the first hash ring; and the first determining subunit is configured to determine, according to each fragment, each target virtual fragment of each fragment, and a position where each service instance is mapped to the first hash ring, a fragment to which each service instance belongs from the preset number of fragments.
8. The apparatus according to claim 7, wherein the first determining unit comprises:
a second determining subunit, configured to determine the number of target virtual slices of each slice in the preset number of slices.
9. The apparatus of claim 8, wherein the second determining subunit comprises:
a first mapping module, configured to map, for each segment, the segment and a plurality of initial virtual segments of the segment to a second hash ring;
a second mapping module to map each service instance in the set of service instances to the second hash ring;
a first determining module, configured to determine, for each segment, a service instance belonging to the segment in the second hash ring according to the segment, each initial virtual segment of the segment, and a position at which each service instance is mapped to the second hash ring;
and the second determining module is used for determining the number of the target virtual shards of each shard according to the number of the initial virtual shards of the shard and the number of the service instances belonging to the shard in the second hash ring.
10. The apparatus of claim 9, wherein the second determining module is further configured to:
and rounding down the square root of the product of the number of the initial virtual fragments of the fragment and the number of the service instances belonging to the fragment in the second hash ring to obtain the number of the target virtual fragments of the fragment.
11. The apparatus of claim 7, wherein the preset number is rounded down by a ratio of a number of service instances in the service instance set to a number of service instances each slice is expected to contain.
12. The apparatus according to any of claims 7-11, wherein the second determining unit is further configured to:
mapping the client to the first hash ring;
and determining the target fragments from the preset number of fragments according to the positions of the client, each fragment and each target virtual fragment of each fragment mapped to the first hash ring.
13. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-6.
14. A computer-readable medium, on which a computer program is stored which, when being executed by a processor, carries out the method according to any one of claims 1-6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010020522.3A CN111262907B (en) | 2020-01-08 | 2020-01-08 | Service instance access method and device and electronic equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010020522.3A CN111262907B (en) | 2020-01-08 | 2020-01-08 | Service instance access method and device and electronic equipment |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111262907A CN111262907A (en) | 2020-06-09 |
CN111262907B true CN111262907B (en) | 2021-07-02 |
Family
ID=70952730
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010020522.3A Active CN111262907B (en) | 2020-01-08 | 2020-01-08 | Service instance access method and device and electronic equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111262907B (en) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113051456A (en) * | 2021-05-11 | 2021-06-29 | 北京字节跳动网络技术有限公司 | Request processing method and device, electronic equipment and computer readable medium |
CN114666338B (en) * | 2022-05-19 | 2022-08-26 | 杭州指令集智能科技有限公司 | Message-based multi-instance load balancing method and system |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108093094A (en) * | 2017-12-08 | 2018-05-29 | 腾讯科技(深圳)有限公司 | Database instance access method, device, system, storage medium and equipment |
WO2019144321A1 (en) * | 2018-01-24 | 2019-08-01 | Telefonaktiebolaget Lm Ericsson (Publ) | Method and apparatus for improving service discovery |
Family Cites Families (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US10200311B2 (en) * | 2016-09-08 | 2019-02-05 | Cisco Technology, Inc. | Computer network control for application instantiation |
US20190081924A1 (en) * | 2017-09-11 | 2019-03-14 | Linkedin Corporation | Discovering address mobility events using dynamic domain name services |
-
2020
- 2020-01-08 CN CN202010020522.3A patent/CN111262907B/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108093094A (en) * | 2017-12-08 | 2018-05-29 | 腾讯科技(深圳)有限公司 | Database instance access method, device, system, storage medium and equipment |
WO2019144321A1 (en) * | 2018-01-24 | 2019-08-01 | Telefonaktiebolaget Lm Ericsson (Publ) | Method and apparatus for improving service discovery |
Also Published As
Publication number | Publication date |
---|---|
CN111262907A (en) | 2020-06-09 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110781373B (en) | List updating method and device, readable medium and electronic equipment | |
CN110489621B (en) | Method, device, medium and electronic equipment for dynamically adjusting route | |
CN111596991A (en) | Interactive operation execution method and device and electronic equipment | |
CN111262907B (en) | Service instance access method and device and electronic equipment | |
CN111309304A (en) | Method, device, medium and electronic equipment for generating IDL file | |
CN112099982A (en) | Collapse information positioning method, device, medium and electronic equipment | |
CN111309254A (en) | Data processing method and device, readable medium and electronic equipment | |
CN111241137A (en) | Data processing method and device, electronic equipment and storage medium | |
CN110852720A (en) | Document processing method, device, equipment and storage medium | |
CN114428925A (en) | Page rendering method and device, electronic equipment and computer readable medium | |
CN111596992B (en) | Navigation bar display method and device and electronic equipment | |
CN111597439A (en) | Information processing method and device and electronic equipment | |
CN111338827A (en) | Method and device for pasting table data and electronic equipment | |
CN112507676B (en) | Method and device for generating energy report, electronic equipment and computer readable medium | |
CN113240108B (en) | Model training method and device and electronic equipment | |
CN111212296B (en) | Live broadcast room gift list configuration method, device, medium and electronic equipment | |
CN113971195A (en) | Data synchronization method, device, electronic equipment and medium | |
CN111399730A (en) | Image processing method, image processing device, electronic equipment and computer readable storage medium | |
CN111625707B (en) | Recommendation response method, device, medium and equipment | |
CN111680754A (en) | Image classification method and device, electronic equipment and computer-readable storage medium | |
CN111580890A (en) | Method, apparatus, electronic device, and computer-readable medium for processing features | |
CN112100205A (en) | Data processing method, device, equipment and computer readable medium | |
CN112115154A (en) | Data processing and data query method, device, equipment and computer readable medium | |
CN110633121A (en) | Interface rendering method and device, terminal equipment and medium | |
CN111241443A (en) | Method and device for pushing information and electronic equipment |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |