Resource allocation method and related device

By obtaining the resource file queue and domain name queue, and using the element index and domain name configuration quantity to automatically allocate file elements, it solves the resource loading blocking problem caused by browser request limitations, achieves efficient and accurate resource allocation, and simplifies the domain name configuration process.

CN118535341APending Publication Date: 2024-08-23太保科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410720492.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-04
Publication Date
2024-08-23

AI Technical Summary

Technical Problem

Browsers have a limit on the number of requests for the same domain name at the same time, causing resource loading to be blocked. The existing manual domain name allocation method is complex and unsatisfactory, and there is a lack of efficient and accurate resource allocation methods.

Method used

By obtaining the resource file queue and domain name queue, based on the element index and the number of domain name configurations, automatically allocate file elements to domain name configurations, using technologies such as hook functions, AST abstract syntax trees, and file processing modules to achieve even distribution of resources and avoid local resource loading. block.

Benefits of technology

It realizes the automation of resource allocation, improves allocation efficiency and accuracy, reduces the need for manual intervention, avoids local blockage caused by excessive concentration of file elements, and simplifies the domain name configuration process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118535341A
    Figure CN118535341A
Patent Text Reader

Abstract

The invention discloses a resource allocation method and a related device, which are applied to the field of big data. In the application, a resource file queue is obtained, the resource file queue comprises one or more file elements, and the file elements have corresponding element indexes. Then obtaining a domain name queue, and determining the number of domain name configurations in the domain name queue; and finally, determining the domain name configuration corresponding to the file element based on the quantity of the domain name configuration and the element index to obtain a resource allocation result. According to the method and the device, automatic allocation of the resource files is realized, manual participation is not needed in the allocation process, and the accuracy of resource allocation can be ensured to a certain extent while resource allocation is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of big data technology, and in particular to a resource allocation method and related devices. Background Art

[0002] Due to the browser's own concurrency limit and the influence of the network environment, the browser has a limit on the number of requests for the same domain name at the same time. When resources need to be loaded, if the number exceeds the browser's limit, a blockage will occur. This blocking situation is not conducive to the smooth progress of the resource loading process, and will cause the browser's page loading speed to slow down or the resource cannot be loaded in time.

[0003] In the related art, domain names are allocated to different resources by manual maintenance. The allocation process relies on manual work, and the process is complicated and the effect of resource allocation is not ideal.

[0004] Therefore, there is an urgent need for an efficient and accurate resource allocation method. Summary of the invention

[0005] In view of this, an embodiment of the present application provides a resource allocation method and related devices, aiming to improve the efficiency of resource allocation.

[0006] In a first aspect, an embodiment of the present application provides a resource allocation method, which is applied to a construction tool, and the method includes:

[0007] Acquire a resource file queue, wherein the resource file queue includes one or more file elements, and the file elements have corresponding element indexes;

[0008] Obtain a domain name queue, and determine the number of domain name configurations in the domain name queue;

[0009] Based on the number of the domain name configurations and the element index, the domain name configuration corresponding to the file element is determined to obtain a result of resource allocation.

[0010] Optionally, when the construction tool is a non-customized construction tool, determining the domain name configuration corresponding to the file element based on the number of the domain name configurations and the element index includes:

[0011] Obtaining the hook function corresponding to the construction tool;

[0012] Traversing the file elements in the resource file queue based on the hook function;

[0013] According to the number of the domain name configurations and the element indexes corresponding to the file elements, the file elements are evenly distributed to the domain name configurations.

[0014] Optionally, when the construction tool is a custom construction tool, the method further includes:

[0015] Generate a corresponding AST abstract syntax tree based on the file element, wherein the AST abstract syntax tree includes nodes;

[0016] Traversing the nodes of the AST abstract syntax tree to identify resource reference identifiers;

[0017] Determine a domain name configuration according to the node corresponding to the resource reference identifier;

[0018] The node is string-adjusted based on the domain name configuration to obtain a resource allocation result.

[0019] Optionally, when the construction tool is a custom construction tool and there is no compilation process, determining the domain name configuration corresponding to the file element based on the number of the domain name configurations and the element index includes:

[0020] Packing the file elements to obtain a target file package;

[0021] The file element in the target file package is read by using a file processing module, and the domain name configuration corresponding to the file element is determined based on the number of the domain name configurations and the element index.

[0022] Optionally, the evenly distributing the file elements to the domain name configurations according to the number of the domain name configurations and the element indexes corresponding to the file elements includes:

[0023] When the number of the domain name configurations is N, the element index corresponding to the file element is divided by the number of the domain name configurations, and the remainder obtained is used as the basis for allocating the domain name configurations to the file element to complete the allocation of the domain name configurations of the file element, and N>1.

[0024] Optionally, the resource file queue is obtained in the following manner:

[0025] Based on any one of the acquisition in the life cycle of the build tool, the acquisition by traversing the AST tree, and the acquisition by reading the file after the build is completed.

[0026] In a second aspect, an embodiment of the present application provides a resource allocation device, which is applied to a construction tool, and the device includes: an acquisition module, a first determination module, and a second determination module;

[0027] The acquisition module is used to acquire a resource file queue, wherein the resource file queue includes one or more file elements, and the file elements have corresponding element indexes;

[0028] The first determination module is used to obtain a domain name queue and determine the number of domain name configurations in the domain name queue;

[0029] The second determination module is used to determine the domain name configuration corresponding to the file element based on the number of the domain name configurations and the element index, and obtain a result of resource allocation.

[0030] In a third aspect, the present application provides a domain name sharding plug-in, and the domain name sharding plug-in is used to execute the method described in any one of the first aspects above.

[0031] In a fourth aspect, the present application provides an electronic device, the device comprising: a processor, a memory, and a system bus;

[0032] The processor and the memory are connected via the system bus;

[0033] The memory is used to store one or more programs, and the one or more programs include instructions, which, when executed by the processor, enable the processor to execute the method described in the first aspect.

[0034] In a fifth aspect, an embodiment of the present application provides a computer storage medium, in which a code is stored. When the code is executed, a device executing the code implements any method described in the first aspect.

[0035] The present application provides a resource allocation method and related devices. When executing the method, first obtain a resource file queue, wherein the resource file queue includes one or more file elements, and the file element has a corresponding element index. Then obtain a domain name queue, and determine the number of domain name configurations in the domain name queue. Finally, based on the number of domain name configurations and the element index, determine the domain name configuration corresponding to the file element, and obtain the result of resource allocation. In this way, by obtaining the resource file queue and the domain name queue, it is possible to determine the corresponding domain name configuration for the file element based on the number of domain name configurations in the domain name queue and the element index of the file element in the resource file queue, and complete the resource allocation of the file element for different domain names. The process is realized automatically without manual intervention, and the number of domain name configurations is combined in the allocation process, which can avoid the situation of centrally allocating file elements to individual domain names, resulting in local resource loading blocking. At the same time, because the file element has a corresponding element index, it can ensure that when determining the domain name configuration for the file element, the difficulty of allocation is reduced while the efficiency of allocation is improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] In order to more clearly illustrate the technical solutions in this embodiment or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0037] Figure 1 A flowchart of a resource allocation method provided in an embodiment of the present application;

[0038] Figure 2 A schematic diagram of a resource allocation method provided in an embodiment of the present application;

[0039] Figure 3 A schematic diagram of the structure of a resource allocation device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0040] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0041] In this application, the terms "comprises", "comprising" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element.

[0042] In the study of related technologies, it was found that due to the browser's own concurrency limit and the network environment and other factors, the browser has a limit on the number of requests under the same domain name at the same time. When loading resources, if the number of requests exceeds the browser's limit, resource loading will be blocked. In related technologies, the problem of resource loading blocking is solved by manually allocating domain names for different resources, but this method will consume a lot of human resources, and the process is complicated and the resource allocation effect is not ideal.

[0043] Based on this, the present application proposes a resource allocation method and related device. By acquiring a resource file queue and a domain name queue, the domain name configuration corresponding to the file element can be determined according to the element index in the resource file queue and the number of domain name configurations in the domain name queue, so as to realize the automatic allocation of resource files, and no manual participation is required in the allocation process. While improving resource allocation, the accuracy of resource allocation can be guaranteed to a certain extent.

[0044] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only 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.

[0045] Figure 1 A flowchart of a resource allocation method provided in an embodiment of the present application is provided in Figure 1 As shown, a resource allocation method provided in an embodiment of the present application is applied to a construction tool, and the method includes:

[0046] S11: Obtain resource file queue.

[0047] A build tool is a software tool used to automate the building of projects, usually for front-end and back-end development. Common build tools include webpack, gulp, grunt, and vite, which can simplify the development process, improve development efficiency, and can be customized and extended according to project requirements.

[0048] In an embodiment of the present application, build tools can be divided into non-customized build tools and customized build tools, wherein the customized build tools include build tools with compilation process and build tools without compilation process, and different build tools all have resource allocation requirements.

[0049] The resource file queue refers to a data structure used to manage and schedule resource files to be loaded. When a browser requests to load a page, it will encounter multiple resource files (i.e., file elements, such as HTML (a markup language used to create web page structure, HyperText Markup Language), CSS (a style sheet language used to define web page style and layout, Cascading Style Sheets) and pictures, etc.). These resource files need to be loaded in a certain order to ensure that the page in the browser is displayed correctly and the functions run normally. Through the resource file queue, the browser can effectively manage and schedule the loading order of resource files. The resource file queue includes one or more file elements, and the file elements have corresponding element indexes. That is, the resource file queue is composed of file elements. Different types of file elements can be contained in a resource file queue, and each file element has a corresponding element index.

[0050] The element index can be presented in the form of an index value. The element index can be the position order of the file element in the resource file queue, or it can be a unique identifier such as the ID or class name of the file element, which is not limited here. There is a one-to-one correspondence between the file element and the element index, so that when the domain name configuration of the file element is determined later, the correspondence between the domain name configuration and the file element is guaranteed to be one-to-one to a certain extent, avoiding confusion of the file element. At the same time, due to the existence of the element index, the domain name configuration can be determined based on the element index.

[0051] S12: Obtain a domain name queue, and determine the number of domain name configurations in the domain name queue.

[0052] A domain name queue refers to a data structure used to manage and schedule domain names to be resolved. When a browser initiates a network request, the domain name needs to be resolved into a corresponding IP address in order to establish a connection and obtain resources. The domain name queue includes one or more domain name configurations. It should be noted that the domain name configuration can be set by those skilled in the art according to actual conditions and application scenarios, and the number of domain name configurations can also be freely determined and is not limited here.

[0053] For example, the domain name queue can be:

[0054] ['http: / / domain-1.com','http: / / domain-2.com','http: / / domain-3.com']

[0055] It can be seen that the domain name queue includes three domain name configurations, namely: http: / / domain-1.com, http: / / domain-2.com and http: / / domain-3.com.

[0056] S13: Based on the number of the domain name configurations and the element index, determine the domain name configuration corresponding to the file element to obtain a result of resource allocation.

[0057] After obtaining the resource file queue and the domain name queue, the domain name configuration corresponding to each file element can be determined based on the element index of the file element in the resource file queue and the number of domain name configurations in the domain name queue to complete the resource allocation result. In the process of resource allocation, a file element is located in a domain name configuration. The corresponding domain name configuration can be determined for each file element in turn by traversing the file elements in the resource file queue.

[0058] The above describes the types of build tools. When the build tool is a non-customized build tool, the method for determining the domain name configuration mentioned in S13 above, "determining the domain name configuration corresponding to the file element based on the number of the domain name configuration and the element index", is as follows: first obtain the hook function corresponding to the build tool, and then traverse the file elements in the resource file queue based on the hook function. Finally, according to the number of domain name configurations and the element index corresponding to the file element, the file elements are evenly distributed to the domain name configuration.

[0059] A hook function is a function that is automatically executed when a specific event occurs, and is commonly found in event-driven and callback mechanisms in programming. In an embodiment of the present application, when a construction tool needs to allocate resources, the hook function corresponding to the construction tool is called to traverse the file elements in the resource file queue. It should be noted that the hook functions corresponding to different construction tools are different.

[0060] Taking webpack as an example, hooks.emit.tapAsync is a hook function in webpack, which is used to register asynchronous event listeners. When a specific event (i.e., resource allocation event) is triggered, these registered listeners will be executed. In webpack, hooks.emit represents an event that is executed before generating resources and outputting them to the target directory. Through the tapAsync method, you can register an asynchronous event listener to perform corresponding operations at a specific time (i.e., traverse the file elements in the resource file queue).

[0061] The file elements in the resource file queue can be obtained based on the life cycle of the build tool, by traversing the Abstract Syntax Tree (AST), or by reading the built file.

[0062] The life cycle of a build tool refers to the various stages and processes of a build tool during the execution of a build, usually including initialization, dependency resolution, compilation, packaging, testing, deployment, etc. An abstract syntax tree is a tree representation of an abstract syntax structure of a programming language code, consisting of nodes, each of which represents a syntax structure in the source code.

[0063] When the file elements in the resource file queue are obtained, the file elements in the resource file queue obtained by traversing the hook function can be evenly distributed to the domain name configuration according to the number of domain name configurations and the element index corresponding to the file element. By evenly distributing the file elements to the domain name configuration, it is possible to avoid the situation where the domain name configuration is sparsely allocated with file elements, that is, some domain name configurations are allocated with a large number of file elements, and some domain name configurations are allocated with a small number of file elements. That is, the file elements allocated to each domain name configuration can be more evenly distributed, avoiding excessive concentration of file element allocation, which leads to local blockage of the domain name configuration.

[0064] The hook function can obtain compilation.assets (all resource files) and evenly distribute the resources to the domain name configuration by traversing and modifying webpack_public_path.

[0065] Through the above-provided method for determining domain name configuration, the hook function corresponding to the build tool is obtained, and the file elements in the resource file queue are traversed based on the hook function. According to the number of domain name configurations and the element index of the file element, the file elements are evenly distributed to the domain name configuration. Resource allocation for non-customized build tools is realized, and an even distribution method is adopted in the distribution process, which avoids excessive concentration of file element allocation and causes local blockage of domain name configuration.

[0066] It is mentioned above that "file elements are evenly distributed to domain name configurations according to the number of domain name configurations and the element index corresponding to the file element". The implementation method of this even distribution can be: when the number of domain name configurations is N, the element index corresponding to the file element is divided by the number of domain name configurations, and the remainder obtained is used as the basis for allocating domain name configurations to the file elements, thereby completing the allocation of domain name configurations to the file elements, and N>1.

[0067] As mentioned above, the element index is presented in the form of an index value, and there is a one-to-one correspondence between the element index and the file element. Therefore, when it is determined that the number of domain name configurations is N, the remainder is used as the basis for allocating the domain name configuration of the file element by dividing the element index corresponding to the file element by the number of domain name configurations. For example, when the remainder is 1, the file element is allocated to the first domain name configuration; when the remainder is 2, the file element is allocated to the second domain name configuration.

[0068] For example, the domain name queue configured by the user is: ['http: / / domain-1.com', 'http: / / domain-2.com', 'http: / / domain-3.com']. At this time, the resource file queue A is traversed. Since there are 3 domain name configurations in the domain name queue, according to the element index in the resource file queue A, the element with a remainder of 1 when the element index is divided by 3 is assigned to http: / / domain-1.com, the element with a remainder of 2 is assigned to http: / / domain-2.com, and the element with an integer index is assigned to http: / / domain-3.com.

[0069] Through the above-provided method for evenly distributing file elements, the index value of the element index corresponding to the file element is divided by the number of domain name configurations, and the remainder obtained is used as the basis for allocating domain name configurations for the file elements, thereby achieving even distribution of file elements. The process is simple and easy, and can improve the allocation efficiency of file elements. Local congestion of domain name configuration can be avoided through even distribution.

[0070] In this embodiment, a resource allocation method is proposed. The method first obtains a resource file queue, wherein the resource file queue includes one or more file elements, and the file elements have corresponding element indexes. Then, a domain name queue is obtained, and the number of domain name configurations in the domain name queue is determined. Finally, based on the number of domain name configurations and the element index, the domain name configuration corresponding to the file element is determined to obtain the result of resource allocation. In this way, by obtaining the resource file queue and the domain name queue, the corresponding domain name configuration can be determined for the file element based on the number of domain name configurations in the domain name queue and the element index of the file element in the resource file queue, and the resource allocation of the file element for different domain names is completed. The process is realized automatically without manual intervention, and the number of domain name configurations is combined in the allocation process, which can avoid the situation where the file elements are concentratedly allocated to individual domain names, resulting in local resource loading blocking. At the same time, because the file elements have corresponding element indexes, it can ensure that when determining the domain name configuration for the file element, the difficulty of allocation is reduced while the efficiency of allocation is improved.

[0071] As mentioned above, in the embodiment of the present application, the construction tool can be a custom construction tool, which refers to a construction tool obtained by a user developing or selecting an existing construction tool according to the specific needs of the project, and performing customized configuration or expansion. When the construction tool is a custom construction tool, the method for allocating resources can be: first, a corresponding AST abstract syntax tree is generated based on the file elements, and the AST abstract syntax tree includes nodes. Then, the nodes of the AST abstract syntax tree are traversed to identify the resource reference identifier, and the domain name configuration is determined according to the node corresponding to the resource reference identifier. Finally, the node is string adjusted based on the domain name configuration to obtain the result of resource allocation.

[0072] The resource file queue includes one or more file elements, and the file elements can be presented in the form of code in the front-end language JavaScript. During the compilation process of the file elements, the code can be processed into a tree structure (i.e., an AST abstract syntax tree), and the nodes of the abstract syntax tree have resource reference identifiers, which can be presented in a form similar to {key=value}. The domain name configuration is determined based on the node corresponding to the resource reference identifier, and the string of the node is adjusted based on the domain name configuration to obtain the result of resource allocation. For example, after identifying a resource reference identifier such as src, link, etc., its corresponding value will be modified, and the domain name will be replaced according to the above-mentioned resource allocation method.

[0073] For example, when traversing the virtual syntax tree, a node {src = 'http: / / xxxx.com / image.png'} is found on the AST tree. This node is used to pull an image.png under the http: / / xxxx.com domain name. At this time, the domain name configuration in the domain name queue is still: ['http: / / domain-1.com', 'http: / / domain-2.com', 'http: / / domain-3.com']. Assuming that the node is the second node that meets the conditions, the node will be changed to {src = 'http: / / domain-2.com / image.png'} through regular matching replacement string. Regular matching replacement refers to using regular expressions to find a specific pattern in the text (i.e. {src = 'http: / / xxxx.com / image.png'}) and replace it with the specified content (i.e. {src = 'http: / / domain-2.com / image.png'}).

[0074] Through the resource allocation method provided above, a custom build tool generates a corresponding abstract syntax tree based on file elements, traverses the nodes in the abstract syntax tree to identify resource reference identifiers, determines domain name configuration according to the nodes corresponding to the resource reference identifiers, and performs string adjustment on the nodes based on the domain name configuration to obtain the result of resource allocation. The resource reference identifier can be identified based on the nodes of the abstract syntax tree, and the resource reference identifier is used as an identifier to determine the domain name configuration. The domain name configuration of the node can be realized by adjusting the node string based on the representation. The implementation process is simple and the efficiency of resource allocation can be improved.

[0075] As mentioned above, in the embodiment of the present application, the construction tool can be a custom construction tool, and the custom construction tool includes a construction tool without a compilation process. At this time, the method of resource allocation mentioned in the aforementioned S13 "determining the domain name configuration corresponding to the file element based on the number of the domain name configurations and the element index" can be: first, the file elements are packaged to obtain a target file package, and then the file elements in the target file package are read by the file processing module, and the domain name configuration corresponding to the file element is determined based on the number of domain name configurations and the element index.

[0076] That is, the file elements are packaged to obtain the target file package. After the address of the target file package is obtained, the file elements in the target file package are read using the file processing module. Based on the number of domain name configurations and the element index of the file element, the domain name configuration corresponding to the file element is determined. The process of determining the domain name configuration can be: reading the file element through fs.readFile, traversing and modifying the domain name configuration of the file element. In the embodiment of the present application, the construction of the file element is based on node implementation, and fs is the file processing module corresponding to node, so the file elements in the target file package can be read based on fs. Of course, other scripting languages ​​can also be used for processing, which is not limited here.

[0077] Figure 2 A schematic diagram of a resource allocation method provided in an embodiment of the present application is shown in FIG. Figure 2As shown, first, it is necessary to set a domain name queue (also known as a domain name array), which refers to a queue composed of one or more domain name configurations. Then, it is determined whether the construction tool that needs to allocate resources is a custom construction tool. When the construction tool is a non-custom construction tool, a hook function is used to traverse and evenly distribute file elements. Different non-custom construction tools have corresponding hook functions. The hook function is used to traverse the file elements in the resource file queue, and the file elements are evenly distributed to the domain name configuration according to the number of domain name configurations and the element index of the file element to obtain the resource allocation result. When the construction tool is a custom construction tool, it is also necessary to determine whether the AST can be obtained during the life cycle of the construction tool. The construction tool that can obtain the AST has a compilation process, and the construction tool that cannot obtain the AST does not have a compilation process. For construction tools with a compilation process, it is necessary to perform string adjustment on the nodes in the AST, and the process of string adjustment is the allocation process of the domain name configuration to obtain the resource allocation result. For construction tools without a compilation process, it is necessary to package the file elements to obtain the target file package, which is processed by the file processing module to obtain the resource allocation result.

[0078] It should be noted that the resource allocation method proposed in the present application can be implemented by a domain name sharding plug-in, that is, the domain name sharding plug-in can be used to configure it in various construction tools for resource allocation. This can avoid modifying the project code in the construction tool, reduce the cost of resource allocation, and improve the efficiency of resource allocation. The domain name sharding plug-in can be adapted to different types of construction tools and has a wide range of application scenarios.

[0079] Figure 3 A schematic diagram of a resource allocation device provided in an embodiment of the present application is shown in FIG. Figure 3 As shown, a resource allocation device specifically includes: an acquisition module 100, a first determination module 200 and a second determination module 300;

[0080] The acquisition module 100 is used to acquire a resource file queue, wherein the resource file queue includes one or more file elements, and the file elements have corresponding element indexes;

[0081] The first determination module 200 is used to obtain a domain name queue and determine the number of domain name configurations in the domain name queue;

[0082] The second determination module 300 is used to determine the domain name configuration corresponding to the file element based on the number of the domain name configurations and the element index, and obtain a result of resource allocation.

[0083] In a possible implementation, when the construction tool is a non-customized construction tool, the second determining module 300 is used to:

[0084] Obtaining the hook function corresponding to the construction tool;

[0085] Traversing the file elements in the resource file queue based on the hook function;

[0086] According to the number of the domain name configurations and the element indexes corresponding to the file elements, the file elements are evenly distributed to the domain name configurations.

[0087] In a possible implementation manner, the device further includes an adjustment module, and when the construction tool is a custom construction tool, the adjustment module is used to:

[0088] Generate a corresponding AST abstract syntax tree based on the file element, wherein the AST abstract syntax tree includes nodes;

[0089] Traversing the nodes of the AST abstract syntax tree to identify resource reference identifiers;

[0090] Determine a domain name configuration according to the node corresponding to the resource reference identifier;

[0091] The node is string-adjusted based on the domain name configuration to obtain a resource allocation result.

[0092] In a possible implementation, when the construction tool is a custom construction tool and has no compilation process, the second determining module 300 is used to:

[0093] Packing the file elements to obtain a target file package;

[0094] The file element in the target file package is read by using a file processing module, and the domain name configuration corresponding to the file element is determined based on the number of the domain name configurations and the element index.

[0095] In a possible implementation, the second determining module 300 is configured to:

[0096] When the number of the domain name configurations is N, the element index corresponding to the file element is divided by the number of the domain name configurations, and the remainder obtained is used as the basis for allocating the domain name configurations to the file element to complete the allocation of the domain name configurations of the file element, and N>1.

[0097] In a possible implementation, the resource file queue is obtained in the following manner:

[0098] Based on any one of the acquisition in the life cycle of the build tool, the acquisition by traversing the AST tree, and the acquisition by reading the file after the build is completed.

[0099] In this embodiment, a resource allocation method device is proposed, which includes: an acquisition module, a first determination module and a second determination module. The acquisition module is used to acquire a resource file queue, which includes one or more file elements, and the file elements have corresponding element indexes; the first determination module is used to acquire a domain name queue and determine the number of domain name configurations in the domain name queue; the second determination module is used to determine the domain name configuration corresponding to the file element based on the number of domain name configurations and the element index, and obtain the result of resource allocation. In this way, by acquiring the resource file queue and the domain name queue, the corresponding domain name configuration can be determined for the file element based on the number of domain name configurations in the domain name queue and the element index of the file element in the resource file queue, and the resource allocation of the file element for different domain names is completed. The process is realized automatically without manual intervention, and the number of domain name configurations is combined in the allocation process, which can avoid the situation of centrally allocating file elements to individual domain names, resulting in local resource loading blocking. At the same time, because the file element has a corresponding element index, it can ensure that when determining the domain name configuration for the file element, the difficulty of allocation is reduced while the efficiency of allocation is improved.

[0100] The flow chart and block diagram in the accompanying drawings illustrate the possible implementation architecture, function and operation of the device and method according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the module, the program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the box can also occur in a sequence different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0101] The embodiments of the present application also provide corresponding devices and computer-readable storage media for implementing the solutions provided by the embodiments of the present application.

[0102] The device includes a memory and a processor, the memory is used to store instructions or codes, and the processor is used to execute the instructions or codes so that the device executes a resource allocation method described in any embodiment of the present application.

[0103] In practical applications, the computer-readable storage medium can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present embodiment, the computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.

[0104] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0105] The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0106] Computer program code for performing the operations of the present invention may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0107] It should also be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0108] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A resource allocation method, characterized in that: Applied to a construction tool, the method comprises: Acquire a resource file queue, wherein the resource file queue includes one or more file elements, and the file elements have corresponding element indexes; Obtain a domain name queue, and determine the number of domain name configurations in the domain name queue; Based on the number of the domain name configurations and the element index, the domain name configuration corresponding to the file element is determined to obtain a result of resource allocation.

2. The method according to claim 1, characterized in that When the construction tool is a non-customized construction tool, determining the domain name configuration corresponding to the file element based on the number of the domain name configurations and the element index includes: Obtaining the hook function corresponding to the construction tool; Traversing the file elements in the resource file queue based on the hook function; According to the number of the domain name configurations and the element indexes corresponding to the file elements, the file elements are evenly distributed to the domain name configurations.

3. The method according to claim 1, characterized in that When the construction tool is a custom construction tool, the method further includes: Generate a corresponding AST abstract syntax tree based on the file element, wherein the AST abstract syntax tree includes nodes; Traversing the nodes of the AST abstract syntax tree to identify resource reference identifiers; Determine a domain name configuration according to the node corresponding to the resource reference identifier; The node is string-adjusted based on the domain name configuration to obtain a resource allocation result.

4. The method according to claim 1, characterized in that: When the construction tool is a custom construction tool and has no compilation process, determining the domain name configuration corresponding to the file element based on the number of the domain name configurations and the element index includes: Packing the file elements to obtain a target file package; The file element in the target file package is read by using a file processing module, and the domain name configuration corresponding to the file element is determined based on the number of the domain name configurations and the element index.

5. The method according to claim 2, characterized in that: The evenly allocating the file elements to the domain name configurations according to the number of the domain name configurations and the element indexes corresponding to the file elements comprises: When the number of the domain name configurations is N, the element index corresponding to the file element is divided by the number of the domain name configurations, and the remainder obtained is used as the basis for allocating the domain name configurations to the file element to complete the allocation of the domain name configurations of the file element, and N>1.

6. The method according to claim 2, characterized in that The resource file queue is obtained in the following manner: Based on any one of the acquisition in the life cycle of the build tool, the acquisition by traversing the AST tree, and the acquisition by reading the file after the build is completed.

7. A resource allocation device, characterized in that: Applied to a construction tool, the device comprises: an acquisition module, a first determination module and a second determination module; The acquisition module is used to acquire a resource file queue, wherein the resource file queue includes one or more file elements, and the file elements have corresponding element indexes; The first determination module is used to obtain a domain name queue and determine the number of domain name configurations in the domain name queue; The second determination module is used to determine the domain name configuration corresponding to the file element based on the number of the domain name configurations and the element index, and obtain a result of resource allocation.

8. A domain name sharding plug-in, characterized in that: The domain name sharding plug-in is used to execute the method described in any one of claims 1-7.

9. An electronic device, characterized in that: The device includes: a processor, a memory, and a system bus; The processor and the memory are connected via the system bus; The memory is used to store one or more programs, wherein the one or more programs include instructions, and when the instructions are executed by the processor, the processor executes the resource allocation method according to any one of claims 1 to 6.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores an implementation program for implementing the resource allocation method, and when the implementation program for implementing the resource allocation method is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.