Grayscale switch instance hot update method and device, electronic equipment and storage medium
By generating and utilizing references to target packaging class objects, the problem in the prior art that grayscale switch instances cannot be hot updated is solved, and efficient dynamic updating of grayscale switch instances is achieved.
Patent Information
- Application Number
- CN202410625725.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-20
- Publication Date
- 2024-08-23
AI Technical Summary
The existing technology cannot realize the hot update of the grayscale switch instance in the local memory of the server, resulting in low efficiency and the inability to dynamically update the grayscale switch instance obtained from the local memory.
By obtaining the key and value in the grayscale request, the target wrapper class object is generated based on multiple preconfigured grayscale switch instances, and when the grayscale switch update corresponding to the key is detected, the reference of the wrapper class object is used to directly obtain the updated The grayscale switch instance realizes the hot update of the grayscale switch instance.
There is no need to obtain the updated grayscale switch instance from the local memory again, and it is directly updated based on the reference, which improves the dynamic update efficiency of the grayscale switch instance and realizes the hot update of the grayscale switch instance obtained from the local memory.
Smart Images

Figure CN118535191A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a grayscale switch instance hot update method, device, electronic device and storage medium. Background Art
[0002] In the field of grayscale expansion, the configuration center can pre-configure multiple grayscale switches, and then the server synchronizes and instantiates the multiple grayscale switches pre-configured by the configuration center to obtain multiple corresponding grayscale switch instances, and stores the multiple grayscale switch instances in the local memory of the server; when the server receives a grayscale request from the client, the server obtains the corresponding target grayscale switch instance from the local memory based on the parameters carried by the grayscale request; then the server makes a grayscale hit result judgment based on the obtained target grayscale switch instance. However, when the configuration center updates the configuration of the grayscale switch corresponding to the target grayscale switch instance, the server cannot update the target grayscale switch instance obtained from the local memory, that is, it cannot implement hot update of the grayscale switch instance obtained from the local memory. Summary of the invention
[0003] The present application provides a grayscale switch instance hot update method, device, electronic device and storage medium, which realize the hot update of the grayscale switch instance.
[0004] In a first aspect, the present application provides a grayscale switch instance hot update method, the method comprising:
[0005] Obtaining a grayscale request, wherein the grayscale request includes a first key and a first value corresponding to the first key;
[0006] Based on a first key, a first value, and a plurality of preconfigured grayscale switch instances, obtaining a target packaging class object corresponding to the first key, wherein the plurality of grayscale switch instances are obtained by instantiating the plurality of preconfigured grayscale switches, and the target packaging class object includes a reference to the grayscale switch instance matching the first key;
[0007] When it is detected that the grayscale switch corresponding to the first key is updated, the updated grayscale switch instance is obtained based on the reference of the grayscale switch instance matching the first key in the target packaging class object.
[0008] In a second aspect, the present application provides a grayscale switch instance hot update device, the device comprising a request calling module and an acquisition module;
[0009] A request calling module, used to obtain a grayscale request, wherein the grayscale request includes a first key and a first value corresponding to the first key;
[0010] an acquisition module, configured to acquire a target packaging class object corresponding to the first key based on the first key, the first value, and a plurality of pre-configured grayscale switch instances, wherein the plurality of grayscale switch instances are obtained by instantiating the plurality of pre-configured grayscale switches, and the target packaging class object includes a reference to the grayscale switch instance matching the first key;
[0011] The request calling module is also used to obtain the updated grayscale switch instance based on the reference of the grayscale switch instance matching the first key in the target packaging class object when it is detected that the grayscale switch corresponding to the first key is updated.
[0012] In a third aspect, the present application provides an electronic device, comprising: a processor and a memory, the processor being connected to the memory, the memory being used to store a computer program, and the processor being used to execute the computer program stored in the memory, so that the electronic device performs the method of the first aspect.
[0013] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program enables a computer to execute the method of the first aspect.
[0014] In a fifth aspect, the present application provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and is computer-operable to cause the computer to execute the method of the first aspect.
[0015] Implementing this application has the following beneficial effects:
[0016] First, the grayscale switch instance hot update device obtains a grayscale request, wherein the grayscale request includes parameters such as a first key and a first value corresponding to the first key; then the grayscale switch instance hot update device obtains a target package class object corresponding to the first key based on the first key, the first value, and a plurality of pre-configured grayscale switch instances, wherein the plurality of grayscale switch instances are obtained by instantiating a plurality of pre-configured grayscale switches, that is, the plurality of grayscale switches are pre-configured by the configuration center, and the grayscale switch instance hot update device can synchronize the plurality of grayscale switches from the configuration center and instantiate and store them in the local memory, and then the grayscale switch instance hot update device regenerates a target package class object corresponding to the first key, at which time the variables in the target package class object are determined based on the first key, the first value, and the plurality of grayscale switch instances, and the target package class object includes a reference to the grayscale switch instance matching the first key; then, when the grayscale switch corresponding to the first key is detected When an update occurs, that is, the configuration center updates the configuration of the grayscale switch corresponding to the first key. Through detection, the grayscale switch instance hot update device can actively perceive that the grayscale switch has been updated. Since the target package class object belongs to the reference data type, and the target package class object includes a reference to the grayscale switch instance that matches the first key, the grayscale switch instance hot update device can obtain the reference to the grayscale switch instance that matches the first key based on the target package class object after obtaining the target package class object. Then, the grayscale switch instance hot update device can obtain the updated grayscale switch instance corresponding to the first key based on the reference of the matching grayscale switch instance. There is no need to obtain the updated grayscale switch instance from the local memory of the grayscale switch instance hot update device, that is, the memory manager, again. Instead, the old grayscale switch instance is directly updated to the new grayscale switch instance based on the reference, thereby realizing the hot update of the grayscale switch instance. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0018] Figure 1 A schematic diagram of a grayscale switch example hot update system provided in an embodiment of the present application;
[0019] Figure 2 A schematic diagram of another grayscale switch example hot update system provided in an embodiment of the present application;
[0020] Figure 3 A schematic diagram of a hot update system for another grayscale switch example provided in an embodiment of the present application;
[0021] Figure 4 A schematic diagram of a grayscale switch instance hot update method provided in an embodiment of the present application;
[0022] Figure 5 A schematic diagram of storage of grayscale switch instances and packaging class objects in a memory manager provided in an embodiment of the present application;
[0023] Figure 6 A schematic diagram of a UML class diagram based on a packaging class object provided in an embodiment of the present application;
[0024] Figure 7 A schematic diagram of a UML class diagram based on weak references provided in an embodiment of the present application;
[0025] Figure 8 A schematic diagram of hot update of a grayscale switch instance provided in an embodiment of the present application;
[0026] Fig. 9 A block diagram of the functional units of a grayscale switch example hot update device provided in an embodiment of the present application;
[0027] Fig.10 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0028] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0029] The terms "first", "second", "third" and "fourth" etc. in the specification, claims and drawings of the present application are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.
[0030] Reference to "embodiments" herein means that a particular feature, result, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0031] First, the relevant technologies and terms involved in this application are explained:
[0032] Grayscale switch: The configuration center can configure the grayscale switch online. Each grayscale switch is configured with a key and a value. The value of the grayscale switch includes but is not limited to one or more of the following: total volume, volume range, whitelist, blacklist, etc. The value of the grayscale switch can be a string type configuration.
[0033] Grayscale switch instance: After the configuration center configures the grayscale switch, the server will synchronize the grayscale switch from the configuration center and instantiate the synchronized grayscale switch to obtain the corresponding grayscale switch instance; further, the grayscale switch instance can also be stored in the local memory of the server, such as storing it in an associative array structure, with the key corresponding to the grayscale switch instance as the key of the associative array, and the grayscale switch instance as the value of the associative array.
[0034] Reference: In JAVA, a reference is the address of an object in memory, and objects can be accessed and operated through references; the reference types in JAVA mainly include: strong reference, soft reference, weak reference, etc. Different types of references determine the life cycle of objects in memory and the behavior of garbage collection. For example, the collector will not recycle objects with strong references; objects with soft references will only be recycled by the collector when there is insufficient memory; objects with weak references can only survive until the next garbage collection occurs. Regardless of whether the current memory is sufficient, the collector will recycle objects that are only associated with weak references. It should be noted that the embodiments of the present application are mainly explained by taking strong references as an example, for example, a reference to a wrapper class object includes a strong reference to a wrapper class object, a reference to a grayscale switch instance that matches a first key includes a strong reference to a grayscale switch instance that matches the first key, a reference to a first value includes a strong reference to the first value, and a preset reference includes a preset strong reference.
[0035] In the field of grayscale expansion or grayscale ratio and flow control, the client can send a grayscale request to the server, and each grayscale request carries the key A and value A corresponding to the grayscale switch to be queried (the value A can also be called the "default value" in this case, which is used when there is no grayscale switch instance corresponding to the grayscale expansion request in the local memory of the server, which means that the configuration center has not configured the grayscale switch corresponding to the key A, and then the default value of the grayscale switch, that is, value A, is used to judge the grayscale result). It should be noted that when the key of the grayscale switch carried by each grayscale request is the same, the default value carried by each grayscale request can be the same or different. Then, it is determined whether there is a grayscale switch instance matching the key A carried by the grayscale request in the local memory of the server; if so, the server obtains the grayscale switch instance matching the key A from the local memory, and judges the grayscale result based on the matching grayscale switch instance; if not, the server judges the grayscale result based on value A.
[0036] Since the grayscale switch instance obtained by instantiating the grayscale switch is a read-only, immutable or unmodifiable object, after the server obtains the grayscale switch instance that matches the grayscale request from the local memory, if the configuration center updates the configuration of the grayscale switch corresponding to the matching grayscale switch instance, although the local memory can synchronize the updated grayscale switch from the configuration center and instantiate the updated grayscale switch instance (for example, the updated grayscale switch instance replaces the updated previous grayscale switch instance), since the grayscale switch instance directly obtained by the server from the local memory is not modifiable, the grayscale switch instance obtained from the local memory will not be updated due to the update of the grayscale switch instance by the local memory. If the updated grayscale switch instance is to be obtained, the server needs to obtain the updated grayscale switch instance from the local memory again, which is inefficient and cannot achieve hot update of the grayscale switch instance obtained from the local content.
[0037] In addition, when the server's local memory does not contain a grayscale switch instance corresponding to the grayscale request, that is, the server has not obtained a matching grayscale switch instance from the local memory, that is, the configuration center has not configured the grayscale switch corresponding to key A, the server uses the default value carried in the grayscale request. Similarly, if the configuration center updates the grayscale switch corresponding to key A (that is, the configuration center has added a configuration of the grayscale switch corresponding to key A at this time), although the server's local content will synchronize and instantiate the newly added grayscale switch, it is equivalent to that the local memory has a grayscale switch instance corresponding to key A at this time, but the server makes a grayscale result judgment based on the obtained value A, or it is understood that the server obtains the corresponding value A based on the reference corresponding to value A. Even if a grayscale switch instance matching key A is added, the server cannot obtain the newly added grayscale switch instance from the local memory based on the reference of value A, that is, the hot update of the grayscale switch instance cannot be realized.
[0038] Therefore, in an embodiment of the present application, a grayscale switch instance hot update device obtains a grayscale request, and the grayscale request includes parameters such as a first key and a first value corresponding to the first key; then the grayscale switch instance hot update device obtains a target package class object corresponding to the first key based on the first key, the first value, and a plurality of pre-configured grayscale switch instances, wherein the plurality of grayscale switch instances are obtained by instantiating the pre-configured plurality of grayscale switches, that is, the plurality of grayscale switches are pre-configured by the configuration center, and the grayscale switch instance hot update device can synchronize the plurality of grayscale switches from the configuration center and instantiate and store them in the local memory, and then the grayscale switch instance hot update device regenerates the target package class object corresponding to the first key. A target packaging class object, at this time, the variables in the target packaging class object are determined based on the first key, the first value and multiple grayscale switch instances, and the target packaging class object includes a reference to the grayscale switch instance matching the first key; then when it is detected that the grayscale switch corresponding to the first key is updated, that is, the configuration center updates the configuration of the grayscale switch corresponding to the first key, through detection, the grayscale switch instance hot update device can actively perceive that the grayscale switch has been updated, and because the target packaging class object belongs to the reference data type, and the target packaging class object includes a reference to the grayscale switch instance matching the first key, the grayscale switch instance hot update device can obtain the target packaging class object. Based on the target package class object, a reference to the grayscale switch instance matching the first key is obtained, and then the grayscale switch instance hot update device can directly obtain the updated grayscale switch instance corresponding to the first key based on the reference of the matching grayscale switch instance, without having to obtain the updated grayscale switch instance from the local memory of the grayscale switch instance hot update device again, but directly updating the old grayscale switch instance to the new grayscale switch instance based on the reference, that is, realizing the hot update of the grayscale switch instance; in other words, regardless of whether the local memory of the grayscale switch instance hot update device corresponds to the first key, the embodiment of the present application will generate a target package class object corresponding to the first key. The target packaging class object is a package class object. At this time, the variable of the target packaging class object includes a reference to the grayscale switch instance that matches the first key. The grayscale switch instance hot update device can obtain the reference to the grayscale switch instance that matches the first key based on the target packaging class object. Furthermore, even if the configuration center modifies the configuration of the grayscale switch that matches the first key or newly configures the grayscale switch corresponding to the first key, since the local memory of the grayscale switch instance hot update device will be synchronously updated from the configuration center in real time, the grayscale switch instance hot update device can directly obtain the latest grayscale switch instance that matches the first key from the local memory based on the reference to the grayscale switch instance that matches the first key, thereby realizing the hot update of the grayscale switch.
[0039] See also Figure 1 , Figure 1A schematic diagram of a grayscale switch instance hot update system provided in an embodiment of the present application.
[0040] Figure 1 The grayscale switch instance hot update system shown includes a grayscale switch instance hot update device, a client, and a gateway; wherein the grayscale switch instance hot update device can be a server, such as an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, as well as basic cloud computing services such as big data and artificial intelligence platforms, which are not specifically limited in this application; the client can be a smart phone, tablet computer, laptop computer, desktop computer, smart TV, desktop computer, etc., which is not specifically limited in this application. In addition, this application does not limit the number of clients and gateways.
[0041] First, the client sends a grayscale request to the gateway, and then the gateway sends the grayscale request to the grayscale switch instance hot update device, wherein the grayscale request includes a first key and a first value corresponding to the first key; then the grayscale switch instance hot update device obtains a target packaging class object corresponding to the first key based on the first key, the first value, and a plurality of pre-configured grayscale switch instances, wherein the pre-configured plurality of grayscale switch instances are instantiated based on a plurality of grayscale switches pre-configured by the configuration center, and the target packaging class object includes a reference to the grayscale switch instance matching the first key; then, when it is detected that the grayscale switch corresponding to the first key is updated, the grayscale switch instance is hot updated. The device obtains an updated grayscale switch instance based on a reference to the grayscale switch instance that matches the first key in the target packaging class object, and then enables the grayscale switch instance hot update device to perform a grayscale result judgment based on the obtained updated grayscale switch instance (which will be described in detail below and will not be elaborated here); further, the grayscale switch instance hot update device can send a grayscale result corresponding to the grayscale request to the gateway, and the gateway sends the grayscale request to a processing environment corresponding to the grayscale result based on the grayscale result for processing, such as a grayscale environment and a non-grayscale environment, both of which can be server clusters or independent servers, and this application does not make specific limitations.
[0042] In an alternative embodiment, see Figure 2 , Figure 2 A schematic diagram of another grayscale switch example hot update system provided in an embodiment of the present application.
[0043] Figure 2 The grayscale switch instance hot update system shown includes a grayscale switch instance hot update device, a client, and a gateway; wherein the grayscale switch instance hot update device may also include a request call processor and a memory manager (ie, equivalent to the local memory of the above-mentioned server).
[0044] After the client sends a grayscale request to the gateway, the request call processor receives the grayscale request from the gateway; then the request call processor sends the first key and the first value in the grayscale request to the memory manager; then the memory manager obtains the target wrapper class object corresponding to the first key based on the first key, the first value, and multiple pre-configured grayscale switch instances, wherein the memory manager stores multiple pre-configured grayscale switch instances; then the memory manager stores the target wrapper class object to the corresponding target associative array, the key of the target associative array being the first key, that is, the memory manager stores the target wrapper class object to the target associative array in the local memory; then the memory manager returns a reference to the target wrapper class object to the request call processor; when an update of the grayscale switch corresponding to the first key is detected, the request call processor can obtain an updated grayscale switch instance based on a reference to the grayscale switch instance matching the first key in the target wrapper class object; and then the request call processor makes a grayscale result judgment based on the obtained updated grayscale switch instance (which will be described in detail below and will not be elaborated here).
[0045] It should be stated that Figure 2 Other descriptions of the grayscale switch example hot update device, client, and gateway in the embodiment can refer to Figure 1 The description related to the grayscale switch instance hot update device, client, and gateway in the embodiment will not be repeated here.
[0046] In an alternative embodiment, see Figure 3 , Figure 3 A schematic diagram of a hot update system for another grayscale switch example provided in an embodiment of the present application.
[0047] Figure 3 The grayscale switch instance hot update system shown includes a grayscale switch instance hot update device, a client, and a gateway; wherein the grayscale switch instance hot update device includes not only a request call processor and a memory manager, but also a garbage collection device.
[0048] The recycler determines whether the preset recycling conditions are met, wherein the preset recycling conditions include that the difference between the current time and the last recycling time is greater than a first threshold and / or the number of current packaging class objects is greater than a second threshold; if the preset recycling conditions are met, the recycler recycles the packaging class objects that do not include references in the associative array in the local memory to release memory and avoid invalid memory occupation.
[0049] It should be stated that Figure 3 Other descriptions of the grayscale switch example hot update device, client, and gateway in the embodiment can refer to Figure 1 Examples and Figure 2The description related to the grayscale switch instance hot update device, client, and gateway in the embodiment will not be repeated here.
[0050] To facilitate understanding, some scenarios involved in the embodiments of the present application are introduced below.
[0051] First, grayscale control of grayscale request traffic.
[0052] In the embodiments of the present application, in the field of media processing, corresponding workflows (one or more in number, to be set in combination with actual needs) will be pre-configured for the processing of each media file to be processed (such as audio, video, image, etc.), and each workflow will be scheduled to the corresponding processing cluster for processing (of course, it can also be an independent server, which is not limited in this application, and the embodiments of the present application are mainly explained using the cluster as an example). Each workflow may include one or more processing tasks. For example, when the media file to be processed is a video, its corresponding workflow may include tasks such as transcoding and frame extraction.
[0053] As the processing request traffic increases, for situations where each workflow includes multiple tasks, the existing processing cluster corresponding to the workflow (also referred to as the "old processing cluster") cannot meet the processing needs. In this case, a new workflow can be created and the new workflow can be scheduled to the new processing cluster for processing. For example, if workflow A includes transcoding and frame extraction tasks, and workflow A was originally scheduled to the old processing cluster for processing, the frame extraction task in workflow A can be scheduled to the new processing cluster for processing with a new workflow. At this time, the old processing cluster still processes workflow A. Since workflow A includes frame extraction tasks, the old processing cluster and the new processing cluster are prone to double-write processing when processing, that is, they are executing the same frame extraction task at the same time, which not only wastes processing resources but also doubles the media processing volume. Therefore, it is necessary to control the frame extraction tasks in workflow A to be gradually switched from the old processing cluster to the new processing cluster for processing, which requires determining the ratio of the gradual switching of frame extraction tasks.
[0054] Therefore, the embodiment of the present application provides a grayscale switch instance hot update method. Based on this method, the grayscale switch instance hot update device can obtain an updated grayscale switch instance. At this time, the grayscale request can be understood as a request corresponding to workflow A, and then the grayscale switch instance hot update device can perform grayscale result judgment based on the updated grayscale switch instance, and determine the proportion of each switching based on the grayscale result. Specifically: the grayscale switch instance hot update device determines the grayscale hit result based on the identification information (at this time, the identification information is used to execute the to-be-processed media file corresponding to workflow A) and the updated grayscale switch instance. For example, based on the identification information, a modulo operation is performed on the total number of releases to obtain a judgment index; if the judgment index is within the release range, the grayscale hit result is determined to be a hit grayscale; if the judgment index is not within the release range, the grayscale hit result is determined to be a miss grayscale.
[0055] Then, based on the grayscale hit result, the grayscale ratio corresponding to the grayscale request is determined, so as to control the grayscale release based on the grayscale ratio. For example, if the grayscale is not hit, that is, the grayscale ratio is the preset value, that is, zero, which means that the task in workflow A cannot be switched to the new processing cluster for processing at this time, then workflow A will still be scheduled to the old processing cluster for processing, and the grayscale switch instance hot update device sends the grayscale hit result and the corresponding grayscale ratio to the gateway, and then the gateway schedules the grayscale request corresponding to the workflow A to the old processing cluster for processing; if the grayscale is hit, then based on the total release amount, the minimum grayscale ratio corresponding to the identification information is determined, for example, the minimum grayscale ratio is the inverse of the total release amount, and then based on the minimum grayscale ratio and the release range, the grayscale is determined. Ratio, wherein the grayscale ratio is greater than or equal to the minimum grayscale ratio and is within the range of volume expansion. For example, the grayscale ratio can be a certain ratio of the minimum grayscale ratio. Similarly, the grayscale switch instance hot update device sends the grayscale hit result and the corresponding grayscale ratio to the gateway, and then the gateway can switch the frame extraction task in workflow A to the new processing cluster for processing at the grayscale ratio each time until the total switching ratio of the frame extraction tasks in workflow A reaches the maximum value in the range of volume expansion. Accordingly, each time the frame extraction task in workflow A switches the grayscale ratio to the new processing cluster, the frame extraction task in workflow A will reduce or delete the grayscale ratio tasks, so as to avoid the situation where the old processing cluster and the new processing cluster double-write the same subtask in the frame extraction task.
[0056] Second, grayscale control of version updates.
[0057] Based on the first scenario above, since the version of each workflow itself will also be continuously updated iteratively, that is, the version of the tasks in the workflow, such as transcoding, will be updated, in order to control the risks in the update process, it is necessary to support the grayscale capabilities of the workflow version itself. Therefore, for each version of the workflow, through the grayscale switch instance hot update method provided in the embodiment of the present application, the grayscale switch instance hot update device obtains the updated grayscale switch instance. At this time, the grayscale request can be understood as a request to update each version of the workflow, and then the grayscale result judgment is performed based on the updated grayscale switch instance (no further details are given here). If the grayscale is hit, the grayscale ratio corresponding to each version of the workflow is determined, and each version of the workflow can be further grayscale released according to the grayscale ratio.
[0058] It should be noted that the embodiments of the present application only list some scenario examples. Other scenarios with grayscale and ratio control requirements can also be applied to the embodiments of the present application, which will not be elaborated here one by one.
[0059] See also Figure 4 , Figure 4 A schematic diagram of a grayscale switch instance hot update method provided in an embodiment of the present application. Figure 4 The method shown is applied to the grayscale switch instance hot update device in the above embodiment, and the method includes but is not limited to the following steps S401-S403:
[0060] S401: Obtain a grayscale request.
[0061] In an embodiment of the present application, the client sends a grayscale request to a gateway, and then the gateway sends the grayscale request to a request call processor of a grayscale switch instance hot update device, where the grayscale request includes a first key and a first value corresponding to the first key.
[0062] S402: Based on the first key, the first value, and a plurality of preconfigured grayscale switch instances, obtain a target packaging class object corresponding to the first key.
[0063] In an embodiment of the present application, multiple grayscale switch instances are stored in a memory manager of a grayscale switch instance hot update device. The multiple grayscale switch instances are obtained based on instantiation of multiple pre-configured grayscale switches, that is, the configuration center pre-configures multiple grayscale switches, and then the grayscale switch instance hot update device synchronizes and instantiates the multiple grayscale switches from the configuration center, correspondingly obtaining the above-mentioned multiple grayscale switch instances, and storing the multiple grayscale switch instances in the memory manager of the grayscale switch instance hot update device, that is, storing them in local memory. Optionally, each grayscale switch instance can be stored in a key-value data structure Map, with the second key corresponding to each grayscale switch instance serving as the key of the Map structure, and each grayscale switch instance serving as the value of the Map structure; the target wrapper class object includes a reference to the grayscale switch instance matching the first key, that is, the variable in the target wrapper class object includes a reference to the grayscale switch instance matching the first key, and at this time, the reference to the grayscale switch instance matching the first key includes a strong reference to the grayscale switch instance matching the first key.
[0064] After the request call processor of the grayscale switch instance hot update device obtains the first key and the first value, the request call processor sends the first key and the first value to the memory manager of the grayscale switch instance hot update device; then the memory manager obtains the target packaging class object corresponding to the first key based on the first key, the first value, and the above-mentioned multiple grayscale switch instances. It should be noted that the memory manager first determines whether there is a target packaging class object corresponding to the first key in the local memory based on the first key. If so, the target packaging class object corresponding to the first key is directly obtained. If not, the target packaging class object corresponding to the first key is generated based on the first key, the first value, and the above-mentioned multiple grayscale switch instances. Specifically: the first key is matched with multiple second keys corresponding to multiple grayscale switch instances in the memory manager to obtain a matching result corresponding to the first key; then the memory manager generates the target packaging class object based on the matching result, multiple grayscale switch instances, the first key, and the first value. Exemplarily, based on the matching result, the reference of the grayscale switch instance that matches the first key is determined. If the matching result is empty, the preset reference of the grayscale switch instance corresponding to the first key is determined as the reference of the grayscale switch instance that matches the first key. In other words, the multiple second keys corresponding to the multiple grayscale switch instances in the memory manager do not match the first key, indicating that there is no grayscale switch instance that matches the first key in the memory manager, and also indicating that the configuration center has not configured a grayscale switch that matches the first key, and there is no reference to the grayscale switch instance that matches the first key in the corresponding memory manager. Similarly, if the matching result is empty, the preset reference of the grayscale switch instance corresponding to the first key is determined as the reference of the grayscale switch instance that matches the first key. If the matching result is not empty, the reference to the first grayscale switch instance is determined as the reference to the grayscale switch instance that matches the first key, wherein the first grayscale switch instance is the grayscale switch instance that matches the first key among multiple grayscale switch instances, that is, there is a grayscale switch instance that matches the first key among multiple second keys corresponding to the multiple grayscale switch instances in the memory manager, indicating that there is a grayscale switch instance that matches the first key, namely, the first grayscale switch instance, in the memory manager, and also indicating that the configuration center has configured the grayscale switch that matches the first key, and the corresponding memory manager also has a reference to the first grayscale switch instance that matches the first key. Then, the memory manager generates a target wrapper class object based on the reference to the first value (wherein the reference to the first value includes a strong reference to the first value) and the reference to the grayscale switch instance that matches the first key. That is to say, a wrapper class (Wrapper Classes) is generated by the reference to the first value and the reference to the grayscale switch instance that matches the first key. At this time, the variables of the target wrapper class object include the reference to the first value and the reference to the grayscale switch instance that matches the first key. Optionally, the target wrapper class object may also include the first key, that is, the memory manager generates the target wrapper class object based on the first key, the reference to the first value, and the reference to the grayscale switch instance that matches the first key. At this time, the variables of the obtained target wrapper class object include the first key, the reference to the first value, and the reference to the grayscale switch instance that matches the first key.
[0065] It can be seen that in this embodiment, the generated target wrapper class object includes a reference to the first value and a reference to the grayscale switch instance matching the first key. The subsequent memory manager can directly send the reference to the target wrapper class object to the request call processor, and the request call processor can obtain a reference to the first value and a reference to the grayscale switch instance matching the first key based on the target wrapper class object reference; if the configuration center does not configure a grayscale switch matching the first key, that is, the memory manager does not have a grayscale switch instance matching the first key, the request call processor obtains the first value based on the reference to the first value, and then the request call processor performs grayscale switching based on the first value. When it is detected that the grayscale switch matching the first key is updated, that is, the configuration center has added a configuration of the grayscale switch matching the first key, then the memory manager will also have a corresponding grayscale switch instance matching the first key. At this time, the request calling processor can directly obtain the newly configured grayscale switch instance matching the first key based on the reference of the grayscale switch instance matching the first key in the target packaging class object (this is the preset reference). That is, at this time, the value of the grayscale result judgment performed by the request calling processor is updated from the first value to the newly configured grayscale switch instance matching the first key, which realizes the hot update of the grayscale switch instance compared to the prior art. Similarly, if the configuration center configures a grayscale switch that matches the first key, that is, there is a grayscale switch instance that matches the first key in the memory manager, then the request call processor can directly obtain the grayscale switch instance that matches the first key based on the reference of the grayscale switch instance that matches the first key in the target wrapper class object, and then the request call processor performs a grayscale result judgment based on the grayscale switch instance that matches the first key. When it is detected that the grayscale switch that matches the first key is updated, that is, the configuration center modifies the configuration of the grayscale switch that matches the first key, the request call processor can still directly obtain the modified grayscale switch instance based on the reference of the grayscale switch instance that matches the first key, which also realizes hot update of the grayscale switch instance compared to the prior art.
[0066] After generating the target wrapper class object, the memory manager may further store the target wrapper class object into a corresponding target associative array, wherein the key of the target associative array is the first key, that is, the memory manager stores a target associative array, and the key of the target associative array is the first key, and the value includes the target wrapper class object, or the value of the target associative array includes the target wrapper class object whose key is the first key, that is, the target wrapper class objects generated corresponding to all grayscale requests carrying the first key are stored in the target associative array; however, since the first value carried by the grayscale request carrying the first key may be the same or different, the references to the first value in the corresponding generated target wrapper class objects may be the same or different. If the references to the first value in the corresponding generated target wrapper class objects are the same, it means that the same target wrapper class object exists in the target associative array, and multiple same target wrapper class objects are stored in the target associative array, which is equivalent to generating duplicate target wrapper class objects for grayscale requests carrying the same first value, which not only wastes storage resources but also increases the recycling pressure for subsequent recyclers.
[0067] Therefore, the embodiment of the present application can also take corresponding measures to further improve, specifically: for the first grayscale request, the memory manager determines whether there is a first associative array matching the third key in the memory manager, wherein the first grayscale request includes the third key and the second value; if the first associative array exists, the memory manager determines whether there is a first packaging class object matching the second value in the first associative array; if the first packaging class object exists, the memory manager no longer generates a packaging class object corresponding to the first grayscale request, and directly determines the first packaging class object as the packaging class object corresponding to the first grayscale request, which is equivalent to only including one first packaging class object in the first associative array; if the first packaging class object does not exist, the memory manager generates a packaging class object corresponding to the first grayscale request based on the third key, the second value, and multiple pre-configured grayscale switch instances, and stores the packaging class object corresponding to the first grayscale request to the first associative array; if the first associative array does not exist, the memory manager also generates a packaging class object corresponding to the first grayscale request based on the third key, the second value, and multiple pre-configured grayscale switch instances, and stores the packaging class object corresponding to the first grayscale request in the first associative array. In short, the wrapper objects generated for grayscale requests carrying the same key and different values are all stored in an associative array, and then for subsequent repeated grayscale requests (i.e., the carried keys and values have corresponding wrapper objects in the memory manager), the memory manager can directly return a reference to the corresponding wrapper object to the request call processor, without the need to regenerate the same wrapper object, thus achieving instance reuse, i.e., reuse of wrapper objects, which not only saves storage resources, but also reduces the recycling pressure of subsequent recyclers. It should be noted that the principle of the grayscale request carrying the first key and the first value in the embodiment of the present application is similar to the explanation of the first grayscale request mentioned above, and will not be repeated here.
[0068] For easier understanding, see Figure 5 , Figure 5 A schematic diagram of storage of grayscale switch instances and wrapper class objects in a memory manager provided in an embodiment of the present application.
[0069] Assume that the configuration center pre-configures three grayscale switches, and the keys corresponding to the three grayscale switches are key1, key2, and key3, respectively. The values of the three grayscale switches are string configurations (for example, configurations including one or more of the total number of releases, release range, whitelist, blacklist, etc., and the present application does not limit the value of each grayscale switch); then the grayscale switch instance hot update device synchronizes the three grayscale switches from the configuration center and instantiates them respectively to obtain the corresponding three grayscale switch instances, and stores the three grayscale switch instances in the memory manager in an associative array structure (such as a Map structure), such as Figure 5As shown, the three grayscale switch instances are TailGraySwitch_1, TailGraySwitch_2, and TailGraySwit ch_3, wherein TailGraySwitch_1 stores a Map structure with a key of key1, TailGraySwitch_2 stores a Map structure with a key of key2, and TailGraySwitch_3 stores a Map structure with a key of key3.
[0070] Further, when the grayscale switch instance hot update device obtains multiple grayscale requests, it then generates corresponding wrapper class objects based on the key and value carried by each grayscale request and the three pre-configured grayscale switch instances (the specific principle is not repeated here), and stores the wrapper class objects in the corresponding associative array, as shown in Figure 5As shown, the target associative array with the key key1 includes multiple wrapper class objects corresponding to key1, namely TailGraySwitchWrapper_11(value_11,TailGraySwitch_1), TailGraySwitchWrapper_12(value_12,TailGraySwitch_1), ..., TailGraySwitchWrapper_1a(value_1a,TailGraySwitch_1), among which TailGraySwitchWrapper_11(value_11,TailGraySwitch_1 ) indicates a wrapper class object 11 including a strong reference to the value value_11 carried by a grayscale request and a strong reference to TailGraySwitch_1. TailGraySwitchWrapper_12(value_12,TailGraySwitch_1) indicates a wrapper class object 12 including a strong reference to the value value_12 carried by a grayscale request and a strong reference to TailGraySwitch_1. TailGraySwitchWrapper_1a(value_1a,TailGraySwitch_1) indicates a wrapper class object 12 including a strong reference to the value value_1a carried by a grayscale request and a strong reference to TailGraySwitch_1. Witch_1 is a strongly referenced wrapper class object 1a, where value_11, value_12, ..., value_1a are all different, that is, if there are multiple second grayscale requests carrying the same key key and value value, such as key1 and value_11, then for the third grayscale request, the grayscale switch instance hot update device will generate a wrapper class object 11 corresponding to the third grayscale request, and store the wrapper class object 11 in the target associative array with the key key1 in the memory manager, where the third grayscale request is the grayscale request that is first in the time sequence among the multiple second grayscale requests, and then for the grayscale requests other than the third grayscale request among the multiple second grayscale requests, since the wrapper class object 11 exists in the memory manager, the grayscale switch instance hot update device will not repeatedly generate the wrapper class object 11, and can directly use the wrapper class object 11 for subsequent grayscale result judgment. It should be noted that Figure 5 The wrapper class objects in the target associative array with the key key2 and the wrapper class objects in the target associative array with the key key3 shown can refer to the explanation of the wrapper class objects in the target associative array with the key key1 above, which will not be repeated here.
[0071] Further, the following describes the relationship between the packaging class object and the grayscale switch instance in conjunction with the UML class diagram. Figure 6 , Figure 6 A schematic diagram of a UML class diagram based on a packaging class object provided in an embodiment of the present application. Figure 6 As shown, the interface class < <interface>> is named "TailGraySwitch", the method implemented by the interface class is "-isOnFor(long):bool" (used to indicate receiving a long type parameter and returning a Boolean type logical value, such as receiving long type identification information in the embodiment of the present application and returning a grayscale hit result of true or false); the class name of a wrapper class object is "TailGraySwitchWrapper", and the properties or variables in this class include "-rootTailGraySwitcher:TailGrayS witcher" (used to indicate a strong reference to the grayscale switch example matching the first key), "-defaultTailGraySwitcher:TailGraySwitcher" (used to indicate a strong reference to the first value), and "-key:string" (used to indicate the first key). The methods in this class include "#TailGraySwitchWrapper()" (used to indicate generating a wrapper class object), "#getKey():string g" (used to indicate the key corresponding to the wrapper class object), "#setRootTailGraySwitcher(TailGraySwitcher):viod" (used to indicate the generation of a wrapper class object based on the grayscale switch instance), "+isOnFor(long):bool"; the class name of a grayscale switch instance is "TailGraySwitcher", and the properties or variables in this class include "-total:int" (used to indicate the total number of categories), "-onRange:int" (used to indicate the volume range), "-whiteList:list <int>"(used to indicate a whitelist), "-blackList:list <int>” (used to indicate a whitelist), the methods in this class include "-TailGraySwitcher()" (used to indicate instantiation of a grayscale switch to obtain a grayscale switch instance), "+isOnFor(long):bool", "+from(string):Tai lGraySwitcher", "+from(string,bool):TailGraySwitcher" (used to indicate receiving a string parameter, such as the value in a grayscale switch, and returning a grayscale switch instance, i.e. instantiation); in addition, Figure 6 The arrow corresponding to R1 represents the "implementation" relationship, which is used to indicate that the class named "TailGraySwitchWrapper" and the class named "TailGraySwitcher" implement the interface class named "TailGraySwitch"; the arrow corresponding to R2 represents the "aggregation" relationship, which is used to indicate that the class named "TailGraySwitchWrapper" includes the class named "TailGraySwitcher"; in addition, the above "int" represents an integer type, "string" represents a string type, "bool" represents a Boolean type, that is, a logical value (such as true, false), and "viod" represents a void type, that is, a method that has no return value.
[0072] S403: When it is detected that the grayscale switch corresponding to the first key is updated, based on the reference of the grayscale switch instance matching the first key in the target packaging class object, obtain the updated grayscale switch instance.
[0073] In an embodiment of the present application, after generating a target wrapper class object corresponding to the first key and storing it in the memory manager, the memory manager sends a reference to the target wrapper class object corresponding to the first key to the request call processor (wherein the reference to the target wrapper class object includes a strong reference to the target wrapper class object); then the request call processor can obtain a reference to the first value in the target wrapper class object and a reference to the grayscale switch instance matching the first key based on the reference to the target wrapper class object, i.e., the strong reference; further, the request call processor can obtain the target grayscale switch instance based on the reference to the first value or the reference to the grayscale switch instance matching the first key, specifically: if the above matching result is empty, then the first value is determined to be the target grayscale switch instance; if the above matching result is not empty, then the grayscale switch instance matching the first key is determined to be the target grayscale switch instance; then the request call processor can make a grayscale result judgment based on the target grayscale switch instance.
[0074] Of course, in an optional embodiment, when it is detected that the grayscale switch corresponding to the first key is updated, the update includes two situations. First, an update from nothing to something means that the configuration center initially does not configure the grayscale switch matching the first key, and now the configuration center has added the configuration of the grayscale switch corresponding to the first key; second, an update from old to new means that the configuration center initially configures the grayscale switch matching the first key, and now the configuration center modifies the configuration of the grayscale switch matching the first key; then the request calling processor can directly obtain the updated grayscale switch instance based on the reference of the grayscale switch instance matching the first key in the target wrapper class object, that is, at this time, the target grayscale switch instance is updated to the updated grayscale switch instance, that is, when it is detected that the grayscale switch corresponding to the first key is updated, the request calling processor obtains the reference of the grayscale switch instance matching the first key in the target wrapper class object based on the reference of the target wrapper class object sent by the memory manager, and then the request calling processor obtains the updated grayscale switch instance matching the first key based on the reference of the grayscale switch instance matching the first key.
[0075] Further, after obtaining the updated grayscale switch instance, the request calling processor can make a grayscale result judgment based on the updated grayscale switch instance. Exemplarily, the grayscale request in the embodiment of the present application can also include identification information, such as the ID of the above-mentioned media file to be processed, and the type of the identification information is long type, and then the request calling processor determines the grayscale hit result based on the identification information and the updated grayscale switch instance. Specifically: the updated grayscale switch instance can include the total volume and the volume range, then the request calling processor performs a modulus operation on the total volume based on the identification information to obtain a judgment index, that is, a remainder operation is performed on the total volume based on the identification information, and the judgment index is the remainder obtained by the remainder operation; if the judgment index is within the volume range, the grayscale hit result is determined to be a hit grayscale; if the judgment index is not within the volume range, the grayscale hit result is determined to be a miss grayscale. Optionally, the updated grayscale switch instance may also include a whitelist and a blacklist. Then, based on the identification information, a modulo operation is performed on the total volume. Before obtaining the judgment index, a request is made to call the processor to determine whether the identification information exists in the whitelist or the blacklist. If it exists in the whitelist, the grayscale hit result is determined to be a hit grayscale. If it exists in the blacklist, the grayscale hit result is determined to be a miss grayscale. If it does not exist in the whitelist or the blacklist, a modulo operation is performed on the total volume based on the identification information to obtain the above-mentioned judgment index, which will not be repeated here.
[0076] Furthermore, the request calling processor determines the grayscale ratio corresponding to the grayscale request based on the grayscale hit result, so as to control the grayscale volume release based on the grayscale ratio. For example, if the grayscale hit result is a hit grayscale, the request calling processor determines the minimum grayscale ratio based on the total volume release, such as the minimum grayscale ratio being the inverse of the total volume release; then the request calling processor determines the grayscale ratio corresponding to the grayscale request based on the minimum grayscale ratio and the volume release range, wherein the grayscale ratio is within the volume release range and is greater than or equal to the minimum grayscale ratio, such as the grayscale ratio can be a preset ratio of the minimum grayscale ratio, which is not limited in this application; if the grayscale hit result is a miss grayscale, the grayscale ratio corresponding to the grayscale request is determined to be a preset value, i.e., zero. Then, after determining the grayscale ratio corresponding to the grayscale request, the request call processor will send the grayscale hit result to the gateway, as well as the grayscale ratio corresponding to the grayscale request to the gateway. For example, if the grayscale is hit, the request call processor sends true and the grayscale ratio corresponding to the grayscale request to the gateway, and then the gateway sends the tasks (or part of the tasks) in the workflow corresponding to the grayscale request to the grayscale environment for processing according to the grayscale ratio, that is, the new processing cluster in the above embodiment is used for processing; similarly, if the grayscale is not hit, the request call processor sends false to the gateway, and then the gateway sends the tasks in the workflow corresponding to the grayscale request to the non-grayscale environment for processing, that is, the old processing cluster in the above embodiment is used for processing.
[0077] In an optional embodiment, the recycler in the grayscale switch instance hot update device can also determine whether a preset recycling condition is met, wherein the preset recycling condition includes that the difference between the current time and the last recycling time is greater than a first threshold and / or the number of current wrapper class objects is greater than a second threshold; if the preset recycling condition is met, the recycler recycles the wrapper class objects that do not include references in the associated array, that is, recycles the wrapper class objects that do not include strong references, or recycles the wrapper class objects that only include weak references; that is, when any one or more of the above-mentioned preset recycling conditions are met, the recycler recycles the wrapper class objects that do not include strong references in the memory manager; in order to avoid invalid memory occupation, an embodiment of the present application sets corresponding strong references and weak references for each wrapper class object, that is, the strong reference and weak reference of each wrapper class object are recorded in the associative array, and the memory manager returns a strong reference to the wrapper class object to the request call processor. Therefore, when the preset recycling condition is met, the recycler recycles the wrapper class objects that only include weak references in the memory manager to release storage resources.
[0078] Further, the following describes the relationship between weak references in conjunction with the UML class diagram. Figure 7 , Figure 7 A schematic diagram of a UML class diagram based on weak references provided in an embodiment of the present application. Figure 7 As shown, the interface class < <interface>> is named "WeakReference", and the method of the interface class is "+WeakReference(T)" (used to indicate a weak reference to the target wrapper class object corresponding to the grayscale hit result of true); the class that belongs to the "implementation" relationship with the interface class (i.e., the class corresponding to arrow R1) is named "FinalizableWeakReference", and the variables or properties of this class include "+queue:ReferenceQueue <object>” (a queue for indicating object references), the methods of this class include “#FinalizableWeakReference(T,Fi nalizableReferenceQueue)” (used to indicate weak references to target wrapper class objects corresponding to true grayscale hit results); the class that belongs to the “inheritance” relationship with the class named “FinalizableWeakReference” (i.e., the class corresponding to arrow R3) is named “TailGraySwitchWrapperWeakRef”, the variables or properties of this class include “-key:string” (here used to indicate the key corresponding to the weak reference wrapper class object), and the methods of this class include “+finalizeReferent():viod” (used to indicate the recycling of the weak reference wrapper class object); wherein, Figure 7 The arrow corresponding to R1 represents the "implementation" relationship, which is used to indicate that the class named "FinalizableWeakReference" implements the interface class named "WeakReference"; the arrow corresponding to R3 represents the "inheritance" relationship, which is used to indicate that the class named "TailGraySwitchWrapperWeakRef" inherits from the class named "FinalizableWeakReference".
[0079] For further understanding, see Figure 8 , Figure 8 A schematic diagram of a grayscale switch instance hot update provided in an embodiment of the present application. Figure 8 As shown, the configuration center can pre-configure multiple grayscale switches, and then the grayscale switch instance hot update device synchronizes and instantiates the multiple grayscale switches to obtain the corresponding multiple grayscale switch instances and store them in the memory manager; then the client sends a grayscale request to the gateway, and the grayscale request includes a first value, a first key and identification information; then the gateway sends the first value, the first key and the identification information in the grayscale request to the request call processor of the grayscale switch instance hot update device; then the request call processor sends the first value and the first key to the memory manager; then the memory manager generates a target wrapper class object corresponding to the first key based on the first key, the first value and the multiple grayscale switch instances in the memory manager (the principle is not repeated here). It should be noted that this is only generated under the premise that the target wrapper class object corresponding to the first key does not exist in the memory manager, which is not repeated here; then the target wrapper class object is stored in the target associative array in the memory manager whose key is the first key; then the memory manager returns a strong reference to the target wrapper class object to the request call processor; then the request call processor The processor can obtain a strong reference to the grayscale switch instance matching the first key in the target packaging class object based on the strong reference of the target packaging class object. When it is detected that the grayscale switch corresponding to the first key in the configuration center is updated, the request calling processor can directly obtain the updated grayscale switch instance based on the strong reference of the grayscale switch instance matching the first key; then the request calling processor performs a grayscale hit result judgment based on the obtained grayscale switch instance and identification information (which will not be repeated here). If the grayscale is hit, the request calling processor sends a grayscale hit result of "true" to the gateway, and then the gateway sends the grayscale request (or the task of grayscale ratio in the workflow corresponding to the grayscale request) to the grayscale environment (i.e., the grayscale server, equivalent to the new processing cluster in the above embodiment) for processing; if the grayscale is not hit, the request calling processor sends a grayscale hit result of "false" to the gateway, and then the gateway sends the grayscale request to the non-grayscale environment (i.e., the non-grayscale server, equivalent to the old processing cluster in the above embodiment) for processing. Of course, the recycler in the grayscale switch instance hot update device can also determine whether the preset recycling conditions are met; if the preset recycling conditions are met, the recycler will recycle the packaging class objects that do not include strong references in the memory manager to avoid invalid memory occupation and release storage resources.
[0080] It can be seen that in the embodiment of the present application, a target packaging class object corresponding to the first key is generated based on the first key, the first value, and the pre-configured multiple grayscale switch instances in the grayscale request; then when it is detected that the grayscale switch corresponding to the first key is updated, that is, the configuration center updates the configuration of the grayscale switch corresponding to the first key, and through detection, the grayscale switch instance hot update device can actively perceive that the grayscale switch has been updated. Since the target packaging class object belongs to the reference data type, and the target packaging class object includes a reference to the grayscale switch instance that matches the first key, the server obtains the target packaging class object. After referencing the object, the reference of the grayscale switch instance matching the first key in the target packaging class object can be obtained based on the reference of the target packaging class object, and then the grayscale switch instance hot update device can directly obtain the updated grayscale switch instance corresponding to the first key based on the reference of the matching grayscale switch instance, without having to obtain the updated grayscale switch instance from the memory manager again as in the prior art, but directly updating the old grayscale switch instance to the new grayscale switch instance based on the reference, that is, realizing the hot update of the grayscale switch instance; in addition, whether there is a grayscale switch instance matching the first key in the memory manager Regarding the instance, the embodiments of the present application will generate a target wrapper class object corresponding to the first key. In the prior art, if the memory manager does not have a grayscale switch instance that matches the first key, the memory manager directly returns the first value to the request call processor. If the configuration center adds a configuration of the grayscale switch corresponding to the first key at this time, since the request call processor only has a reference to the first value, it is impossible to directly obtain the updated grayscale switch instance based on the reference to the first value, and it is also necessary to obtain it from the memory manager again. However, even if the memory manager does not have a grayscale switch instance that matches the first key, the memory manager returns the grayscale switch instance to the request call processor. The processor sends a reference to the target wrapper class object, and based on the reference, it can obtain the variables in the target wrapper class object, that is, the reference to the grayscale switch instance matching the first key and the reference to the first value, and then request the call processor to use the first value to judge the grayscale result. When it is detected that the configuration center has added a grayscale switch corresponding to the first key, that is, the memory manager has a grayscale switch instance matching the first key, the request call processor can directly obtain the newly added grayscale switch instance matching the first key based on the obtained reference to the grayscale switch instance matching the first key, thereby realizing hot update of the grayscale switch instance compared to the prior art.
[0081] See also Fig. 9 , Fig. 9 A functional unit composition block diagram of a grayscale switch instance hot update device provided in an embodiment of the present application. The grayscale switch instance hot update device 900 includes: a request calling module 901, an acquisition module 902;
[0082] A request calling module 901 is used to obtain a grayscale request, wherein the grayscale request includes a first key and a first value corresponding to the first key;
[0083] An acquisition module 902 is used to acquire a target packaging class object corresponding to the first key based on the first key, the first value, and a plurality of pre-configured grayscale switch instances, wherein the plurality of grayscale switch instances are obtained by instantiating the plurality of pre-configured grayscale switches, and the target packaging class object includes a reference to the grayscale switch instance matching the first key;
[0084] The request calling module 901 is further used to obtain an updated grayscale switch instance based on a reference to the grayscale switch instance matching the first key in the target wrapper class object when it is detected that the grayscale switch corresponding to the first key is updated.
[0085] In one embodiment of the present application, in terms of acquiring a target packaging class object corresponding to the first key based on the first key, the first value, and a plurality of preconfigured grayscale switch instances, the acquisition module 902 is specifically configured to:
[0086] Matching the first key with multiple second keys corresponding to the multiple grayscale switch instances to obtain a matching result corresponding to the first key;
[0087] A target packaging class object is determined based on the matching result, the multiple grayscale switch instances, the first key, and the first value.
[0088] In one embodiment of the present application, in determining the target packaging class object based on the matching result, the plurality of grayscale switch instances, the first key, and the first value, the acquisition module 902 is specifically configured to:
[0089] Based on the matching result, determining a reference to a grayscale switch instance that matches the first key;
[0090] A target wrapper class object is generated based on a reference to the first value and a reference to the grayscale switch instance matching the first key.
[0091] In one embodiment of the present application, after generating the target packaging class object corresponding to the first key, the acquisition module 902 is specifically used to:
[0092] Store the target wrapper class object into the corresponding target associative array, where the key of the target associative array is the first key.
[0093] In one embodiment of the present application, Fig. 9 As shown, the grayscale switch instance hot update device 900 further includes a recovery module 903, and the recovery module 903 is specifically used for:
[0094] Determine whether a preset recycling condition is met, wherein the preset recycling condition includes that the difference between the current time and the last recycling time is greater than a first threshold or the number of current packaging objects is greater than a second threshold;
[0095] If the preset recycling conditions are met, the packaging class objects that do not include references in the associative array will be recycled.
[0096] In one embodiment of the present application, the grayscale request further includes identification information. After obtaining the updated grayscale switch instance, the obtaining module 902 is specifically configured to:
[0097] Determine a grayscale hit result based on the identification information and the updated grayscale switch instance;
[0098] Based on the grayscale hit result, the grayscale ratio corresponding to the grayscale request is determined, so as to perform grayscale volume control based on the grayscale ratio.
[0099] In one embodiment of the present application, the updated grayscale switch instance includes the total number of volume releases and the volume release range. In determining the grayscale hit result based on the identification information and the updated grayscale switch instance, the acquisition module 902 is specifically used to:
[0100] Based on the identification information, the total volume is modulo-calculated to obtain the judgment index;
[0101] If the indicator is judged to be within the range of volume expansion, the grayscale hit result is determined to be a hit grayscale;
[0102] If the indicator is judged not to be within the range of large volume, the grayscale hit result is determined to be a grayscale miss.
[0103] In a specific implementation, the request calling module 901, the acquisition module 902, and the recycling module 903 described in the embodiment of the present invention may correspond to other implementation methods described in the embodiment of the grayscale switch instance hot update method provided in the embodiment of the present invention, which will not be repeated here.
[0104] See also Fig.10 , Fig.10 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Fig.10 As shown, the electronic device 1000 includes a transceiver 1001, a processor 1002 and a memory 1003. They are connected via a bus 1004. The memory 1003 is used to store computer programs and data, and can transmit the data stored in the memory 1003 to the processor 1002.
[0105] The processor 1002 is used to read the computer program in the memory 1003 and perform the following operations:
[0106] Controlling the transceiver 1001 to obtain a grayscale request, wherein the grayscale request includes a first key and a first value corresponding to the first key;
[0107] Based on a first key, a first value, and a plurality of preconfigured grayscale switch instances, obtaining a target packaging class object corresponding to the first key, wherein the plurality of grayscale switch instances are obtained by instantiating the plurality of preconfigured grayscale switches, and the target packaging class object includes a reference to the grayscale switch instance matching the first key;
[0108] When it is detected that the grayscale switch corresponding to the first key is updated, the updated grayscale switch instance is obtained based on the reference of the grayscale switch instance matching the first key in the target packaging class object.
[0109] Specifically, the transceiver 1001 may be Fig. 9 The grayscale switch example of the embodiment of the hot update device 900 of the acquisition module 902, the above processor 1002 can correspond to Fig. 9 The grayscale switch instance hot update device 900 of the embodiment includes a request calling module 901 and a recycling module 903 .
[0110] In a specific implementation, the transceiver 1001 and the processor 1002 described in the embodiment of the present invention may also execute other implementation methods described in the embodiment of the grayscale switch instance hot update method provided in the embodiment of the present invention, which will not be repeated here.
[0111] It should be understood that the electronic device in this application can be a grayscale switch instance hot update device, and the grayscale switch instance hot update device can be a server, such as an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, and basic cloud computing services such as big data and artificial intelligence platforms, which are not specifically limited in this application. The above electronic devices are only examples, not exhaustive, and include but are not limited to the above electronic devices.
[0112] It should be understood that an embodiment of the present application also provides a computer-readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement part or all of the steps of any grayscale switch instance hot update method recorded in the above method embodiments.
[0113] An embodiment of the present application also provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program can be operated to cause a computer to execute part or all of the steps of any grayscale switch instance hot update method recorded in the above method embodiments.
[0114] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.
[0115] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0116] In the several embodiments provided in the present application, it should be understood that the disclosed device can be implemented in other ways. For example, the device embodiments described above are only schematic, such as the division of units, which is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical or other forms.
[0117] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0118] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit may be implemented in the form of hardware or in the form of a software program module.
[0119] If the integrated unit is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a memory and includes several instructions for a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of each embodiment method of the present application. The aforementioned memory includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.
[0120] A person skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable memory, and the memory can include: a flash drive, a read-only memory (English: Read-Only Memory, abbreviated as: ROM), a random access memory (English: Random Access Memory, abbreviated as: RAM), a magnetic disk or an optical disk, etc.
[0121] The embodiments of the present application are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the idea of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.< / object> < / interface> < / int> < / int> < / interface>
Claims
1. A grayscale switch instance hot update method, It is characterized in that The method comprises: Obtaining a grayscale request, wherein the grayscale request includes a first key and a first value corresponding to the first key; Based on the first key, the first value, and a plurality of pre-configured grayscale switch instances, obtaining a target packaging class object corresponding to the first key, wherein the plurality of grayscale switch instances are obtained by instantiating the pre-configured plurality of grayscale switches, and the target packaging class object includes a reference to the grayscale switch instance matching the first key; When it is detected that the grayscale switch corresponding to the first key is updated, the updated grayscale switch instance is obtained based on the reference of the grayscale switch instance matching the first key in the target packaging class object.
2. The method according to claim 1, It is characterized in that The step of generating a target packaging class object corresponding to the first key based on the first key, the first value, and a plurality of preconfigured grayscale switch instances includes: Matching the first key with a plurality of second keys corresponding to the plurality of grayscale switch instances to obtain a matching result corresponding to the first key; The target packaging class object is determined based on the matching result, the multiple grayscale switch instances, the first key, and the first value.
3. The method according to claim 2, It is characterized in that The determining the target packaging class object based on the matching result, the multiple grayscale switch instances, the first key, and the first value includes: Based on the matching result, determining a reference to the grayscale switch instance that matches the first key; The target wrapper class object is generated based on a reference to the first value and a reference to the grayscale switch instance that matches the first key.
4. The method according to any one of claims 1 to 3, It is characterized in that After generating the target packaging class object corresponding to the first key, the method further includes: The target wrapper class object is stored in a corresponding target associative array, wherein the key of the target associative array is the first key.
5. The method according to any one of claims 1 to 4, It is characterized in that The method further comprises: Determine whether a preset recycling condition is met, wherein the preset recycling condition includes that the difference between the current time and the last recycling time is greater than a first threshold and / or the number of current packaging objects is greater than a second threshold; If the preset recycling condition is met, the packaging class objects that do not include references in the associative array are recycled.
6. The method according to any one of claims 1 to 5, It is characterized in that The grayscale request further includes identification information. After obtaining the updated grayscale switch instance, the method further includes: Determine a grayscale hit result based on the identification information and the updated grayscale switch instance; Based on the grayscale hit result, a grayscale ratio corresponding to the grayscale request is determined, so as to perform grayscale volume control based on the grayscale ratio.
7. The method according to claim 6, It is characterized in that The updated grayscale switch instance includes the total volume and the volume range, and the determining the grayscale hit result based on the identification information and the updated grayscale switch instance includes: Based on the identification information, a modulo operation is performed on the total volume to obtain a judgment index; If the judgment indicator is within the volume range, determining the grayscale hit result as a hit grayscale; If the judgment indicator is not within the volume expansion range, it is determined that the grayscale hit result is a miss grayscale.
8. A grayscale switch instance hot update device, It is characterized in that The device comprises a request calling module and an acquisition module; The request calling module is used to obtain a grayscale request, wherein the grayscale request includes a first key and a first value corresponding to the first key; The acquisition module is configured to acquire a target packaging class object corresponding to the first key based on the first key, the first value, and a plurality of pre-configured grayscale switch instances, wherein the plurality of grayscale switch instances are obtained by instantiating the pre-configured plurality of grayscale switches, and the target packaging class object includes a reference to the grayscale switch instance matching the first key; The request calling module is further used to obtain an updated grayscale switch instance based on a reference to the grayscale switch instance matching the first key in the target packaging class object when it is detected that the grayscale switch corresponding to the first key is updated.
9. An electronic device, It is characterized in that include: A processor and a memory, wherein the processor is connected to the memory, the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device executes the method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and the computer program is executed by a processor to implement the method according to any one of claims 1 to 7.
