Index optimization method and device, electronic equipment and readable storage medium

By adaptively switching index modes through the monitoring system, adjusting to sharded or merged index modes based on the ratio of write timeouts to query timeouts, the contradiction between write and query performance of inverted indexes is resolved, achieving dynamic performance balance and system stability.

CN121807846APending Publication Date: 2026-04-07CHINA TELECOM CLOUD TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511789867.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-01
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

In content delivery networks, intense lock contention during the writing process of inverted indexes leads to decreased write performance. While sharding alleviates write pressure, it increases query latency and impacts data computation performance.

Method used

The monitoring system adaptively switches index modes, dynamically adjusting to sharded index mode or merged index mode based on the ratio of write timeout to query timeout, thus balancing write and query performance.

Benefits of technology

By increasing throughput under high write pressure and optimizing response speed under high query pressure, a balanced optimization of write and query performance is achieved, thereby improving the availability and query efficiency of the monitoring system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121807846A_ABST
    Figure CN121807846A_ABST
Patent Text Reader

Abstract

The invention discloses an index optimization method and device, electronic equipment and a readable storage medium, and belongs to the field of computers. Determining a write-in timeout proportion based on the write-in time corresponding to the time sequence data written into the target database of each collection task, and determining a query timeout proportion based on the query time corresponding to the query time of the time sequence data inquired from the target database of each calculation task; under the condition that the write-in timeout proportion is greater than a first preset threshold value, switching a current index mode of a reverse index corresponding to the time sequence data into a fragment index mode; under the condition that the write-in overtime proportion is smaller than or equal to a first preset threshold value and the query overtime proportion is larger than a second preset threshold value, the current index mode is switched into a combined index mode. When the writing pressure is large, the throughput is improved through a fragment index mode, when the query pressure is large, the response speed is optimized through a combined index mode, the method adapts to load characteristics of different monitoring scenes, and balance optimization of writing and query performance is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the computer field, and in particular to an index optimization method and device, an electronic device, and a readable storage medium. BACKGROUND

[0002] With the continuous expansion of the business scale of a content delivery network (CDN), real-time monitoring and accurate analysis of performance data such as server network quality are increasingly highlighted. In the context of content delivery network monitoring, Prometheus can be used to collect server performance data, aggregate raw indicators, facilitate subsequent rapid calculation and processing, and provide data query services with high timeliness to meet the stringent requirements of businesses for real-time performance.

[0003] In related technologies, to accelerate query efficiency, a large number of inverted indexes need to be created to establish a mapping relationship between a label value and a time series. However, this leads to fierce lock competition in the index writing process, which severely restricts the writing performance. To alleviate this problem, the inverted indexes are often stored in shards to disperse the writing pressure and improve the overall throughput. However, the shard strategy introduces additional overhead of cross-shard queries due to the need to aggregate multiple shard data during data queries, resulting in increased query delay and significantly reduced data calculation performance due to cross-shard operations. SUMMARY

[0004] To overcome the problems in the related art, the present application provides an index optimization method, device, electronic device, and readable storage medium.

[0005] In a first aspect, an embodiment of the present application provides an index optimization method, which includes: determining a write timeout ratio based on a write time of writing time series data into a target database corresponding to each collection task, and determining a query timeout ratio based on a query time of querying time series data from the target database corresponding to each calculation task; switching a current index mode of an inverted index corresponding to the time series data to a shard index mode in a case where the write timeout ratio is greater than a first preset threshold; switching the current index mode of the inverted index corresponding to the time series data to a merged index mode in a case where the write timeout ratio is less than or equal to the first preset threshold and the query timeout ratio is greater than a second preset threshold.

[0006] In a second aspect, an embodiment of the present application provides an index optimization device, which includes: The first determining module is configured to determine a write timeout ratio based on a write time corresponding to writing time series data into a target database according to each collection task, and determine a query timeout ratio based on a query time corresponding to querying the time series data from the target database according to each computing task; The first switching module is configured to switch a current index mode of the inverted index corresponding to the time series data to a sharding index mode when the write timeout ratio is greater than a first preset threshold. The second switching module is configured to switch the current index mode of the inverted index corresponding to the time series data to a merged index mode when the write timeout ratio is less than or equal to the first preset threshold and the query timeout ratio is greater than a second preset threshold.

[0007] In a third aspect, an electronic device is provided, which includes a processor, a memory, and a program or instructions stored in the memory and executable on the processor, and the program or instructions, when executed by the processor, implement the steps of the method according to the first aspect.

[0008] In a fourth aspect, a readable storage medium is provided, which stores a program or instructions, and the program or instructions, when executed by a processor, implement the steps of the method according to the first aspect.

[0009] In a fifth aspect, a chip is provided, which includes a processor and a communication interface, the communication interface is coupled to the processor, and the processor is configured to execute a program or instructions to implement the method according to the first aspect.

[0010] In the embodiments of the present application, the write timeout ratio is determined based on a write time corresponding to writing time series data into a target database according to each collection task, and the query timeout ratio is determined based on a query time corresponding to querying the time series data from the target database according to each computing task; when the write timeout ratio is greater than a first preset threshold, the current index mode of the inverted index corresponding to the time series data is switched to a sharding index mode; when the write timeout ratio is less than or equal to the first preset threshold and the query timeout ratio is greater than a second preset threshold, the current index mode of the inverted index corresponding to the time series data is switched to a merged index mode. In this way, the index mode is switched adaptively according to the write timeout ratio and the query timeout ratio, the write and query performance is dynamically balanced, the throughput is improved through the sharding index mode when the write pressure is large, the response speed is optimized through the merged index mode when the query pressure is large, so as to adapt to the load characteristics of different monitoring scenarios and balance and optimize the write and query performance. BRIEF DESCRIPTION OF DRAWINGS

[0011] Figure 1is a step flow chart of an index optimization method provided by an embodiment of the present application. Figure 2 is a system architecture diagram corresponding to a monitoring system provided by an embodiment of the present application. Figure 3 is a specific step flow chart of an index optimization method provided by an embodiment of the present application. Figure 4 is a structure diagram of an index optimization device provided by an embodiment of the present application. Figure 5 is a structure diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION

[0012] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.

[0013] The terms "first", "second", and the like in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described herein. In addition, "and / or" in the specification and claims indicates at least one of the connected objects, and the character " / ", generally indicates that the front and rear associated objects are in an "or" relationship.

[0014] The index optimization provided by the embodiments of the present application will be described in detail below by specific embodiments and their application scenarios in combination with the drawings.

[0015] Figure 1 is a step flow chart of an index optimization method provided by an embodiment of the present application, as shown in Figure 1 the method can include: Step 101, based on each acquisition task, write the time series data into the corresponding write time of the target database, determine the write timeout ratio, and based on each calculation task, query the time series data from the target database corresponding to the query time, and determine the query timeout ratio.

[0016] In the embodiment of the application, in the process of collecting, storing and calculating data based on the monitoring system, the collection task is responsible for persisting the collected time series data to the target database. The monitoring system can be a Prometheus system, and the monitoring system can be integrated with a sharding control module and an index management module. The time series data can refer to a sequence of monitoring indicator values recorded in chronological order. The monitoring indicators can include processor usage, memory, disk, etc. The collection task can be a separate thread dynamically generated by the monitoring system according to the configured collection target. Each collection target corresponds to a dedicated write thread, which triggers data collection and write operation at a predetermined collection period. The collection target can be an application, a service, a node, etc. Each collection target exposes an indicator interface. The write time corresponding to the collection task can be the complete time interval from the start of the data write request of the write thread to the return of the write success response of the target database.

[0017] According to the write time of each collection task and the write timeout threshold, the collection task with write timeout is determined, and based on the number of collection tasks with write timeout and the total number of collection tasks in the statistical period, the write timeout ratio in the statistical period is determined. The write timeout threshold can be set according to actual needs, for example, it can be the collection period corresponding to the collection task. The write timeout ratio can be used to represent the write load pressure of the time series data.

[0018] The calculation task is responsible for reading the time series data from the target database according to the inverted index corresponding to the time series data to support monitoring analysis, alarm triggering and other scenarios. The calculation task can be a separate thread dynamically generated by the monitoring system according to the configured query rule. Each query rule corresponds to a dedicated calculation thread, which triggers data query operation at a predetermined calculation period. The query time can be the complete time interval from the start of the query request of the calculation thread to the return of the complete query result of the target database.

[0019] According to the query time of each calculation task and the query timeout threshold, the calculation task with query timeout is determined, and based on the number of calculation tasks with query timeout and the total number of calculation tasks in the statistical period, the query timeout ratio in the statistical period is determined. The query timeout threshold can be set according to actual needs, for example, it can be the collection period corresponding to the calculation task. The query timeout ratio is used to represent the data query performance and index efficiency.

[0020] Step 102, in the case where the write timeout ratio is greater than a first preset threshold, the current index mode of the inverted index corresponding to the time series data is switched to a sharding index mode.

[0021] In this embodiment of the invention, when write performance becomes a system bottleneck, write pressure can be distributed through a sharded index mode to improve overall throughput. Specifically, when the write timeout ratio exceeds a first preset threshold, an index mode switching process can be initiated. The first preset threshold can be dynamically set according to the business's tolerance for write real-time performance. When the write timeout ratio exceeds the first preset threshold, it indicates that the current write load is too high, and the index structure can be optimized to reduce write lock contention. Therefore, the current index mode of the inverted index corresponding to the time series data can be switched to a sharded index mode. An inverted index for time series data is an index structure that maps tag values ​​to time series indexes for quick location of time series data. A sharded index mode can refer to an inverted index structure that includes multiple sharded index instances split according to a preset number of shards. Each sharded index instance contains a partial tag-time series index mapping relationship to reduce write lock contention. The current index mode being sharded index mode can be used to instruct subsequent write operations to be directly routed to the corresponding sharded index instance.

[0022] Step 103: When the write timeout ratio is less than or equal to the first preset threshold and the query timeout ratio is greater than the second preset threshold, the current index mode of the inverted index corresponding to the time series data is switched to the merged index mode.

[0023] In this embodiment of the invention, when the system detects that the write timeout ratio is less than or equal to a first preset threshold and the query timeout ratio is greater than a second preset threshold, indicating insufficient query performance, the index structure can be optimized to reduce cross-shard query overhead. Therefore, the current index mode of the inverted index corresponding to the time series data can be switched to merged index mode. The current index mode being merged index mode can be used to indicate that subsequent write operations should be preferentially routed to the merged index instance to reduce cross-shard access. The merged index mode can refer to the inverted index structure including merging multiple shard index instances into a single merged index instance according to merging rules.

[0024] In summary, in this embodiment of the invention, the write timeout ratio is determined based on the write time corresponding to each acquisition task writing time series data to the target database, and the query timeout ratio is determined based on the query time corresponding to each computing task querying time series data from the target database. If the write timeout ratio is greater than a first preset threshold, the current index mode of the inverted index corresponding to the time series data is switched to sharded index mode. If the write timeout ratio is less than or equal to the first preset threshold, and the query timeout ratio is greater than a second preset threshold, the current index mode of the inverted index corresponding to the time series data is switched to merged index mode. Thus, by adaptively switching the index mode according to the write and query timeout ratios, write and query performance can be dynamically balanced. Under high write pressure, the sharded index mode improves throughput, and under high query pressure, the merged index mode optimizes response speed, thereby adapting to the load characteristics of different monitoring scenarios and achieving a balanced optimization of write and query performance.

[0025] Furthermore, by using a hash index sharding mechanism, the lock contention intensity is reduced to 1 / N of the original level (N being the number of shards), effectively solving the data write backlog problem, improving high-concurrency write throughput, and thus enhancing the availability of the monitoring system. Simultaneously, by monitoring write and query performance in real time, especially in scenarios with sudden write surges, such as restarts (without loading data) or significant changes in the target data collection, whenever write performance anomalies occur, the sharded index mode is prioritized to ensure write performance, thereby guaranteeing data integrity and implementing a write-first elastic resource scheduling strategy. In stable write scenarios, such as when write performance is normal but query performance is abnormal, the current index mode is switched to a merged index mode. This reduces redundancy and improves query performance. This adaptive, load-fluctuation-responsive elastic architecture dynamically balances query performance and storage efficiency.

[0026] Optionally, step 101 may include the following steps: Step 201: For any acquisition task, add the acquisition task to the write queue, and determine the write time based on the write start time and write end time corresponding to the acquisition task.

[0027] In this embodiment of the invention, the sharding control module can manage and make decisions on acquisition tasks and computing tasks. By analyzing the time information of acquisition tasks and computing tasks in the write queue and query queue, the write timeout ratio and query timeout ratio can be determined. Then, based on the rules, index mode decisions can be made to optimize system performance, such as sharding when write errors occur and merging when query errors occur.

[0028] For data acquisition tasks, when a task needs to be added, it registers with the sharding control module. Registration requires a unique task identifier and the task's acquisition cycle. Upon receiving the registration information, the sharding control module adds the task to the write queue. The write queue can be a container for storing information related to the data acquisition task, which will later be used for time calculations and decision analysis.

[0029] During execution, the data acquisition task pushes start and end time information to the sharding control module. Before starting to write data, the acquisition task first pushes the write start time to the sharding control module. Upon receiving this information, the sharding control module updates the start time of the corresponding acquisition task in the write queue. After the acquisition task completes data writing, it pushes the write end time, and the sharding control module updates the end time of the corresponding acquisition task in the write queue accordingly. Based on the write start and write end times, the write time corresponding to the acquisition task is calculated. For example, subtracting the write start time from the write end time yields the write time corresponding to the acquisition task.

[0030] Step 202: Determine the write timeout ratio based on the first number of acquisition tasks in the write queue whose write time is greater than the first preset period within the preset decision period.

[0031] In this embodiment of the invention, index mode decisions are made periodically, and the decision period can be set to a preset decision period. When the preset decision period is met, the write queue is traversed to obtain relevant information for all data collection tasks in the write queue, preparing for subsequent calculations and analysis. For example, the preset decision period is set to 10 minutes, meaning that a full traversal of the write queue is performed every 10 minutes.

[0032] The write timeout ratio is calculated by dividing the first number of write tasks in the write queue whose write time exceeds the first preset period by the queue length of the write queue within the preset decision period. The first preset period can be pre-set based on system performance and business requirements; for example, it can be set to the collection period corresponding to a collection task. That is, if the write time of a collection task exceeds the collection period corresponding to that task, the write operation of that collection task is considered abnormal.

[0033] For example, assuming the first preset period is set to 5 minutes, if there are 10 tasks in the write queue within the preset decision period, and the write time of 3 of the tasks is longer than 5 minutes, then the write timeout ratio is 3 / 10 = 30%.

[0034] In this embodiment of the invention, by recording the time consumed by the acquisition task and statistically analyzing the write timeout ratio, write anomalies can be detected in a timely manner, providing a basis for subsequent optimization measures such as sharding, ensuring the efficient and stable execution of the acquisition task, and improving the system's data writing performance.

[0035] Optionally, step 101 may include the following steps: Step 301: For any computing task, add the computing task to the query queue, and determine the query time based on the query start time and query end time corresponding to the computing task.

[0036] In this embodiment of the invention, when a computing task needs to be added, the computing task registers with the sharding control module. During registration, the unique task identifier corresponding to the computing task and the execution cycle of the task must be included. After receiving the registration information, the sharding control module adds this computing task to the query queue. The query queue is used to store relevant information about the computing task.

[0037] During execution, computation tasks push start and end time information to the sharding control module. Before starting to query data, each computation task first pushes its query start time to the sharding control module. Upon receiving this information, the sharding control module updates the start time of the corresponding computation task in the query queue. After completing the data query, the computation task pushes its query end time, and the sharding control module updates the end time of the corresponding computation task in the query queue accordingly. Based on the query start and end times, the query time for that computation task is calculated. For example, subtracting the query start time from the query end time yields the query time for that computation task.

[0038] Step 302: Determine the query timeout ratio based on the second number of computation tasks in the query queue whose query time is greater than the second preset period within the preset decision period.

[0039] In this embodiment of the invention, under the condition of satisfying a preset decision period, the query queue is traversed to obtain relevant information of all computing tasks in the query queue, in order to prepare for subsequent calculations and analysis. For example, the preset decision period is set to 10 minutes, that is, the query queue is fully traversed every 10 minutes.

[0040] The query timeout rate is calculated by dividing the second number of computation tasks in the query queue whose write time exceeds a second preset period within a preset decision period by the queue length of the query queue within the preset decision period. The second preset period can be pre-set based on system performance and business requirements; for example, it can be set to the execution period corresponding to the computation task. That is, if the query time of a computation task exceeds the execution period corresponding to that computation task, the query for that computation task is considered abnormal.

[0041] In this embodiment of the invention, by obtaining the query time of the computing task, the query timeout ratio can be used to quickly determine the query anomaly, thereby providing a reference for taking optimization strategies such as merging, ensuring efficient processing of computing tasks and improving system query performance.

[0042] Understandably, if a data collection or computation task is canceled for any reason, a deregistration operation is required. When deregistration is performed, the module will remove the task from the corresponding queue based on its type. That is, when a data collection task is deregistered, it is removed from the write queue; when a computation task is deregistered, it is removed from the query queue.

[0043] Optionally, step 102 may include the following steps: Step 401: Activate the mode switching lock.

[0044] In this embodiment of the invention, a mode switching lock is enabled before switching the sharded index mode. The mode switching lock is a mechanism for controlling resource access; once enabled, it prevents other operations that might affect data consistency (such as data writing) from occurring simultaneously. For example, in a distributed database system, when it is necessary to switch from the current index mode to the sharded index mode, the system can set a flag in memory to indicate that the mode switching lock is enabled. Other threads or processes will pause data writing operations upon detecting this flag.

[0045] Step 402: Switch the shard identifier to the first identifier corresponding to the shard index mode; the first identifier is used to indicate that the data to be written is written to the shard index instance.

[0046] In this embodiment of the invention, after enabling the mode switching lock, the shard identifier in the index management module can be switched to the first identifier corresponding to the shard index mode. The shard identifier is identification information used to indicate the data write location, and the first identifier is used to indicate that subsequent data to be written should be written to the shard index instance. A shard index instance is an instance that distributes data according to specific rules and stores it in different nodes or regions. This distributed storage can improve data processing efficiency and query performance.

[0047] Step 403: Close the mode switching lock.

[0048] In this embodiment of the invention, after the shard identifier switch is completed, the system closes the mode switching lock. Closing the mode switching lock means that other operations are allowed to continue. At this time, the monitoring system will receive and process data preparation in shard index mode, and subsequent data writing will be done to the corresponding shard index instance.

[0049] In this embodiment of the invention, the safe switching of index modes is achieved by opening and closing the mode switching lock and switching the fragment identifier, ensuring the correct writing and processing of data under different index modes.

[0050] Optionally, step 103 may include the following steps: Step 501: Activate the mode switching lock.

[0051] In this embodiment of the invention, a mode switching lock is enabled before switching the sharded index mode. The mode switching lock is a mechanism for controlling resource write permissions; once enabled, it prevents other data write operations that might affect data consistency from occurring simultaneously. For example, in a distributed database system, when switching from the current index mode to the merged index mode, the system can set a flag in memory to indicate that the mode switching lock is enabled. Other threads or processes will pause data write operations upon detecting this flag.

[0052] Step 502: Switch the shard identifier to the second identifier corresponding to the merge index mode; the second identifier is used to indicate that the data to be written is written to the merge index instance.

[0053] In this embodiment of the invention, after the mode switching lock is activated, the shard identifier is switched to the second identifier corresponding to the merged index mode. The second identifier is used to indicate that the data to be written is written to the merged index instance. The merged index instance is an instance that integrates and stores scattered data; merging simplifies data management and query operations.

[0054] Step 503: Close the mode switching lock.

[0055] In this embodiment of the invention, after the shard identifier is switched to the second identifier, the system closes the mode switching lock. At this time, the system has completed the switch to the merged index mode, and subsequent data writing will be done to the merged index instance.

[0056] In this embodiment of the invention, the safe switching of index modes is achieved by opening and closing the mode switching lock and switching the fragment identifier, ensuring the correct writing and processing of data under different index modes.

[0057] Optionally, embodiments of the present invention may further include the following steps: Step 601: When the fragment identifier is the first identifier, for any of the data to be written corresponding to the acquisition task, activate the mode switching lock.

[0058] In this embodiment of the invention, when the system detects that the fragment identifier is the first identifier and the data to be written for the acquisition task needs to be processed, a mode switching lock is activated. This establishes an exclusive access environment before the data writing operation begins, preventing other concurrent operations from interfering with the data storage structure or writing process during the data writing process, thus ensuring the atomicity and consistency of the data writing.

[0059] Step 602: Determine the target shard index instance corresponding to the data to be written from at least two shard index instances based on the data identifier corresponding to the data to be written and the preset number of shards.

[0060] In this embodiment of the invention, a data identifier corresponding to the data to be written is obtained. The data identifier can be a hash value corresponding to the data acquisition task. Then, this data identifier is used to perform a modulo operation on a preset number of shards. The preset number of shards is a number of shards that the system pre-sets for distributing and storing data. The result of the modulo operation is used as an index, and from at least two sets of shard index instances, the shard index instance whose index matches the remainder is selected as the target shard index instance. For example, if the hash value of the data identifier is 13 and the preset number of shards is 5, then taking the remainder of 13 divided by 5 gives 3, so the third shard index instance is selected as the target shard index instance.

[0061] Step 603: Write the index information corresponding to the data to be written into the target shard index instance.

[0062] In this embodiment of the invention, after determining the target shard index instance, the index information corresponding to the data to be written is written into the target shard index instance. The index information typically includes key information such as data identifiers and indicator tags, which are used for subsequent rapid data location and retrieval. The write operation can be completed by calling the add interface provided by the target shard index instance, transmitting the index information to the target shard index instance for storage according to a specific format and protocol. Establishing an association between the data to be written and the shard index instance enables the shard index instance and specific storage location of the data to be quickly found based on the index information when querying or accessing the data later.

[0063] It is understood that the embodiments of the present invention do not restrict the format and rules for writing index information into the target shard index instance.

[0064] Step 604: Close the mode switching lock.

[0065] In this embodiment of the invention, after completing the index information writing operation for the data to be written, the operation of closing the mode switching lock is performed. For example, a previously set global flag variable can be set to a closed state to notify other blocked or paused threads or processes that they can continue to perform related operations.

[0066] In this embodiment of the invention, when the shard identifier is the first identifier, enabling the mode switching lock can prevent data writing from being interfered with by other operations, thus ensuring data consistency. Determining the target shard index instance based on the data identifier and the preset number of shards enables reasonable data sharding and storage, improving system concurrency processing and query efficiency.

[0067] Optionally, embodiments of the present invention may further include the following steps: Step 701: When the fragment identifier is the second identifier, for any of the data to be written corresponding to the acquisition task, activate the mode switching lock.

[0068] In this embodiment of the invention, when the fragment identifier is the second identifier, it indicates that the current indexing mode is in merged indexing mode. For the data to be written corresponding to any acquisition task, a mode switching lock is activated.

[0069] Step 702: Write the index information corresponding to the data to be written into the merged index instance.

[0070] In this embodiment of the invention, the index information corresponding to the data to be written is written to the merged index instance. The write operation can be completed by calling the add interface provided by the merged index instance, and the index information is transmitted to the merged index instance for storage according to a specific format and protocol.

[0071] Step 703: Close the mode switching lock.

[0072] In this embodiment of the invention, the mode switching lock is turned off.

[0073] In this embodiment of the invention, after completing the index information writing operation for the data to be written, the operation of closing the mode switching lock is performed. For example, a previously set global flag variable can be set to a closed state to notify other blocked or paused threads or processes that they can continue to perform related operations.

[0074] In this embodiment of the invention, when the shard identifier is the second identifier (merged index mode), enabling the mode switching lock can prevent data writing from being interfered with by other operations, ensuring data consistency. Writing index information to the merged index instance can simplify data management and improve query efficiency.

[0075] Optionally, embodiments of the present invention may further include the following steps: Step 801: If the target index mode is merged index mode, enable the delete lock.

[0076] In this embodiment of the invention, when the current index mode is switched to merged index mode, an operation to enable a delete lock is performed. A delete lock is a mechanism used to control data deletion permissions for sharded index instances and merged index instances. For example, a global flag variable can be set to represent the lock's state; when the lock is enabled, this flag variable is set to a specific value, such as a locked state. Other threads or processes that may affect data operations will be blocked or suspended upon detecting that this flag variable is in a locked state.

[0077] Step 802: Merge the sharded index instances corresponding to the current index mode being sharded index mode to obtain a temporary index instance.

[0078] In this embodiment of the invention, when the current index mode is a sharded index mode, a merging operation is performed on each sharded index instance. The merging operation iterates through the index information in each sharded index instance, integrating this data into a new index structure according to certain rules, thereby obtaining a temporary index instance. For example, the index information in the sharded index instances can be merged into a single temporary index instance according to a data tag-data identifier storage mapping structure.

[0079] Step 803: Close the deletion lock.

[0080] In this embodiment of the invention, after the creation of the temporary index instance is completed, the system closes the delete lock. For example, a previously set global flag variable can be set to an unlocked state to notify other blocked or paused threads or processes that they can continue performing related operations.

[0081] Step 804: After merging the temporary index instances into the merged index instance, clear each of the sharded index instances.

[0082] In this embodiment of the invention, after disabling the delete lock, the system merges the temporary index instance into the merged index instance. The merge operation integrates the data in the temporary index instance into the appropriate location in the merged index instance according to certain rules. After the merge is completed, the data in each sharded index instance is cleared to release the storage space occupied by the sharded index instances, preparing for possible subsequent data resharding or other operations.

[0083] In this embodiment of the invention, enabling the delete lock ensures that data is not interfered with by other operations during index merging, thus ensuring data consistency. Merging sharded index instances to obtain temporary index instances and integrating them into the merged index instance can optimize the index structure and improve query efficiency when query pressure is too high. Furthermore, clearing the sharded index instances can release storage space, which is beneficial for subsequent operations and enhances system flexibility and resource utilization.

[0084] Optionally, embodiments of the present invention may further include the following steps: Step 901: For any query tag indicated by a computing task, query the target data identifier that matches the query tag in each shard index instance and the merged index instance.

[0085] In this embodiment of the invention, upon receiving a query tag from any computing task, a parallel query mechanism can be initiated. Simultaneously, query requests are sent to each sharded index instance and merged index instance. Each instance, upon receiving a request, searches its own index structure for a data identifier that matches the query tag.

[0086] Furthermore, since the query does not distinguish between shard identifiers, all shard index instances and merged index instances will participate in the query, potentially resulting in multiple lists of target data identifiers that may be duplicated. Therefore, after obtaining the lists of target data identifiers returned by each shard index instance and merged index instance, the lists are merged to integrate all data identifiers into a single set. Then, the data identifiers are sorted; the sorting rules can be set according to actual needs, such as by numerical value, alphabetical order, etc. After sorting, the sorted list is deduplicated to remove duplicate data identifiers, ensuring that each data identifier appears only once in the final result.

[0087] Step 902: Determine the target query data indicated by the computing task in the target database based on the target data identifier.

[0088] In this embodiment of the invention, a data query is performed in the target database based on the target data identifier. The target database is a database that stores actual time-series data, and there is a correspondence between the data identifier and the specific data record in the database. The corresponding time-series data is searched in the target database based on the data identifier, and this time-series data is returned to the computing task as the target query data indicated by the computing task.

[0089] Furthermore, when switching from sharded index mode to merged index mode, all index information in the sharded index instances is merged into the merged index instance, and the index information in the sharded index instances is cleared. Under this premise, when the current index mode is merged index mode, since the sharded index instances are empty, the time consumed by traversing the sharded index instances during queries is minimal. Therefore, compared to sharded index mode, switching the index mode to merged index mode still improves data query performance. At the same time, considering that other parallel threads may switch index modes after the query task starts executing (which may cause index information to appear in the sharded index instances), to avoid missing data, when the index mode is merged index mode, both the sharded index instances and the merged index instances are traversed simultaneously. Similarly, when the index mode is switched from merged index mode to sharded index mode, since the merged index instance has already integrated all the previous index information in the merged index mode, traversing the sharded index instance and the merged index instance can also ensure the comprehensiveness of the query when the current index mode is sharded index mode.

[0090] In this embodiment of the invention, queries are performed using each shard index instance and the merged index instance to avoid missing data. Simultaneously, sorting and deduplication ensure accurate and unique results, enabling fast and precise retrieval of target data from the target database, thus improving query comprehensiveness, reliability, and efficiency.

[0091] Optionally, embodiments of the present invention may further include the following steps: Step 1001: For any tag to be deleted, enable the deletion lock.

[0092] In this embodiment of the invention, when a deletion instruction is received for any tag to be deleted, the deletion lock is first activated.

[0093] Step 1002: Delete the index information that matches the tag to be deleted in each shard index instance and merged index instance.

[0094] In this embodiment of the invention, after successfully unlocking the delete lock, delete operations are initiated in parallel on each shard index instance and the merged index instance. In each index instance, index information matching the tag to be deleted is searched; once a matching index is found, it is deleted from the corresponding index instance.

[0095] Step 1003: Close the deletion lock.

[0096] In this embodiment of the invention, after completing the operation of deleting the index information to be deleted in each index instance, the deletion lock is closed.

[0097] In this embodiment of the invention, by deleting matching index information in parallel across each sharded index instance and the merged index instance, data can be thoroughly and accurately cleaned. Simultaneously, enabling a deletion lock prevents interference from other concurrent operations during the deletion process, ensuring data consistency.

[0098] For example, suppose Prometheus is configured as follows: target number allocation: 500,000, task cycle 5s~15s; calculation tasks: 100, cycle 5s~15s; preset inverted index shard number: 512; preset decision cycle: 1 minute; first preset threshold: 0.4, second preset threshold: 0.6.

[0099] After starting Prometheus: Reviewing the collected data, in the first minute, over 70% of data writes timed out, resulting in data backlog. After one minute, the decision was made to switch to a sharded index mode, and data writes slowly recovered. After five minutes, data writes recovered, data collection stabilized, and only a small amount of new data required index creation. At this point, the query timeout rate increased to 0.7, while the write timeout rate was 0. The decision was made to switch to a merged index mode, and the sharded index instances were merged into merged index instances. After the inverted index merging was complete, query performance slowly recovered. Once query performance stabilized, the query timeout rate was less than 0.1, and the write timeout rate was 0. At this point, the collection target was changed. All indexes corresponding to the original collection target were no longer compatible, requiring index re-creation, and writes became slow again. The write timeout rate reached 0.7, and the decision was made to switch to a sharded index mode. After writes recovered and stabilized, the write timeout rate was 0, while the query timeout rate was greater than 0.6. The decision was made to switch to a merged index mode. Ultimately, the query timeout rate stabilized between 0.1 and 0.2, and the write timeout rate was 0. For example, Figure 2 This illustrates a system architecture diagram corresponding to a monitoring system, such as... Figure 2 As shown, a sharding control module and an index management module can be added to the monitoring system. The sharding control module monitors write and query performance through write and query queues, and makes index mode decisions based on write and query timeout ratios. The decision results are sent to the index management module, which switches shard identifiers according to the decided index mode. The shard identifiers indicate the write format and management structure of the inverted index. In this way, in the native monitoring system (such as Prometheus) architecture, only the sharding control module and the index management module are added. The inverted index logic still uses the native code of the monitoring system, without modifying the underlying time-series data format and pre-computation logic. This ensures compatibility with the existing monitoring ecosystem and achieves a low-overhead system compatibility design.

[0100] For example, Figure 3A flowchart illustrating the specific steps of an index optimization method is shown, such as... Figure 3 As shown, each data acquisition and computation task is executed periodically. When a data acquisition or computation task is added, it is first registered with the sharding control module, and the data acquisition task is added to the write queue, while the computation task is added to the query queue. The write start time and write end time of the data acquisition task are collected and recorded, as are the query start time and query end time of the computation task. If a data acquisition or computation task is canceled for any reason, it needs to be deregistered. When a data acquisition task is deregistered, it is deleted from the write queue; when a computation task is deregistered, it is deleted from the query queue. Upon reaching a preset decision cycle, the write queue and query queue are traversed, and the write timeout ratio and query timeout ratio are calculated. Based on these ratios, an index mode (including sharded index mode, merged index mode, and maintaining the status quo) is determined, and the decision result, i.e., the index mode, is communicated to the index management module to change the shard identifier or keep the shard identifier unchanged. When performing write or query operations, data acquisition and computation tasks need to determine the index mode based on the shard identifier in the index management module before performing the write or query operation.

[0101] For example, suppose we need to write three metrics: {__name__="cpu", ip="192.168.1.1"} 20, {__name__="cpu", ip="192.168.1.2"} 60, and {__name__="cpu", ip="192.168.1.3"} 50. The values ​​within the curly braces {} are labels, followed by the values. Their unique identifiers are 1, 2, and 3 respectively. The metrics are composed of the __name__ and ip labels. Initially, the index shards are 2. Two index instances are created, assuming 1 and 3 are in instance 1, and 2 is in instance 2. At this point, "Merge Index Instances" is empty and in shard mode. For example: Sharded Index Example 1: __name__ : CPU: [1 3] IP address: 192.168.1.1 : [1] 192.168.1.3 : [3] Sharded Index Example 2: __name__ : cpu : [2] IP address: 192.168.1.2 : [2] To add data `{__name__="mem", ip="192.168.1.2"} 100`, with a unique identifier of 4, instance 2 is selected for writing the index after modulo operation. First, a mode switch and locking are performed. Then, based on the shard identifier, instance 2 is selected as the shard index instance to write to (4 modulo 2). After writing, the index is updated, and the final index is as follows: __name__ : cpu : [2] mem : [4] IP address: 192.168.1.2 : [2 4] Finally, switch modes to unlock.

[0102] To query the metric data for IPs 192.168.1.1 and 192.168.1.2, first take instance 1 to get the id list [1], then take instance 2 to get [2 4]. Take the merged index instance as empty, merge the id list, remove duplicates and sort to get [1 2 4]. Based on this, the corresponding metric data can be found.

[0103] To delete {__name__="cpu", ip="192.168.1.3"}, first add a lock to the deletion, then iterate through instance 1, instance 2, and merge instances to perform the deletion. After deleting instance 1, you will get the result. __name__ : cpu : [1] IP address: 192.168.1.1 : [1] Example 2: Result after deletion __name__ : cpu : [2] mem : [4] IP address: 192.168.1.2 : [2 4] The merged instance is empty; finally, delete and unlock.

[0104] If the query is slow and a decision is made to merge shards, first switch the mode and acquire a lock, set the shard identifier to false and then unlock it, then delete and acquire the lock, and merge shard index instance 1 and shard index instance 2 to obtain a temporary index instance, __name__. CPU: [1 2] mem : [4] IP address: 192.168.1.1 : [1] 192.168.1.2 : [2 4] Delete unlock.

[0105] Assuming that after the shard identifier is switched, data {__name__="disk", ip="192.168.1.1"} 10 (unique identifier 5) is written, written to the "Merged Index Instance", and then the temporary index instance is merged into the "Merged Index Instance", the result is: __name__ : CPU: [1 2] mem : [4] disk: [5] IP address: 192.168.1.1 : [1 5] 192.168.1.2 : [2 4] Clear the temporary index instance.

[0106] If writing slows down again, the decision to switch to sharded index mode will switch the write instances corresponding to the data to be added back to instance 1 and instance 2.

[0107] It should be noted that the index optimization method provided in this application embodiment can be executed by an index optimization device, or a control module within the index optimization device for executing the loading index optimization method. This application embodiment uses the execution of the loading index optimization method by an index optimization device as an example to illustrate the index optimization device provided in this application embodiment.

[0108] Figure 4 This is a schematic diagram of the structure of an index optimization device provided in an embodiment of the present invention, as shown below. Figure 4 As shown, the device may specifically include: The first determining module 1101 is used to determine the write timeout ratio based on the write time corresponding to the time series data being written to the target database by each acquisition task, and to determine the query timeout ratio based on the query time corresponding to the time series data being queried from the target database by each computing task. The first switching module 1102 is used to switch the current index mode of the inverted index corresponding to the time series data to the sharded index mode when the write timeout ratio is greater than the first preset threshold. The second switching module 1103 is used to switch the current index mode of the inverted index corresponding to the time series data to the merged index mode when the write timeout ratio is less than or equal to the first preset threshold and the query timeout ratio is greater than the second preset threshold.

[0109] This invention provides an index optimization device that determines a write timeout ratio based on the write time of each acquisition task when writing time-series data to a target database, and a query timeout ratio based on the query time of each computing task when querying time-series data from the target database. If the write timeout ratio is greater than a first preset threshold, the current index mode of the inverted index corresponding to the time-series data is switched to a sharded index mode. If the write timeout ratio is less than or equal to the first preset threshold, and the query timeout ratio is greater than a second preset threshold, the current index mode of the inverted index corresponding to the time-series data is switched to a merged index mode. In this way, by adaptively switching the index mode according to the write and query timeout ratios, write and query performance can be dynamically balanced. Under high write pressure, the sharded index mode improves throughput; under high query pressure, the merged index mode optimizes response speed, thereby adapting to the load characteristics of different monitoring scenarios and achieving a balanced optimization of write and query performance.

[0110] Optionally, the first determining module 1101 includes: The first determining submodule is used to add the acquisition task to the write queue for any acquisition task, and determine the write time based on the write start time and write end time corresponding to the acquisition task. The second determining submodule is used to determine the write timeout ratio based on the first number of acquisition tasks in the write queue whose write time is greater than the first preset period within a preset decision period.

[0111] Optionally, the first determining module 1101 includes: The third determination submodule is used to add the computing task to the query queue for any computing task, and determine the query time based on the query start time and query end time corresponding to the computing task. The fourth determining submodule is used to determine the query timeout ratio based on the second number of computation tasks in the query queue whose query time is greater than the second preset period within a preset decision period.

[0112] Optionally, the first switching module 1102 includes: The first unlocking module is used to unlock the mode switching lock; The first switching submodule is used to switch the shard identifier to the first identifier corresponding to the shard index mode; the first identifier is used to indicate that the data to be written is written to the shard index instance. The first closing module is used to close the mode switching lock.

[0113] Optionally, the second switching module 1103 includes: The second unlocking module is used to unlock the mode switching lock; The second switching submodule is used to switch the shard identifier to the second identifier corresponding to the merged index mode; the second identifier is used to indicate that the data to be written is written to the merged index instance. The second closing module is used to close the mode switching lock.

[0114] Optionally, the device further includes: The third enabling module is used to enable a mode switching lock for any data to be written corresponding to any of the acquisition tasks when the segment identifier is the first identifier. The second determining module is used to determine the target shard index instance corresponding to the data to be written from at least two shard index instances based on the data identifier corresponding to the data to be written and the preset number of shards. The first write module is used to write the data to be written to the target shard index instance; The third closing module is used to close the mode switching lock.

[0115] Optionally, the device further includes: The fourth enabling module is used to enable a mode switching lock for any data to be written corresponding to any of the acquisition tasks when the segment identifier is the second identifier. The second writing module is used to write the index information corresponding to the data to be written into the merged index instance. The fourth closing module is used to close the mode switching lock.

[0116] Optionally, the device further includes: The fifth enabling module is used to enable the deletion lock when the current index mode is switched to merge index mode; The first merging module is used to merge the sharded index instances corresponding to the current index mode being the sharded index mode, to obtain a temporary index instance; The fifth closing module is used to close the deletion lock; The first clearing module is used to clear each of the sharded index instances after merging the temporary index instances into the merged index instance.

[0117] Optionally, the device further includes: The first query module is used to query the target data identifier that matches the query label in each shard index instance and the merged index instance for any query label indicated by any computing task. The third determining module is used to determine the target query data indicated by the computing task in the target database based on the target data identifier.

[0118] Optionally, the device further includes: The sixth module, the "Enable" module, is used to enable the deletion lock for any tag to be deleted. The first deletion module is used to delete the index information to be deleted that matches the tag to be deleted in each shard index instance and merged index instance; The sixth closing module is used to close the deletion lock.

[0119] The index optimization device in this application embodiment can be a device, or a component, integrated circuit, or chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. For example, mobile electronic devices can be mobile phones, tablets, laptops, PDAs, in-vehicle electronic devices, wearable devices, ultra-mobile personal computers (UMPCs), netbooks, or personal digital assistants (PDAs), etc., while non-mobile electronic devices can be servers, network-attached storage (NAS), personal computers (PCs), televisions (TVs), ATMs, or self-service machines, etc. This application embodiment does not impose specific limitations.

[0120] The index optimization device in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit the specific operating system used.

[0121] Optionally, this application embodiment also provides an electronic device, including a processor 1210, a memory 1209, and a program or instructions stored in the memory 1209 and executable on the processor 1210. When the program or instructions are executed by the processor 1210, they implement the various processes of the above-described index optimization method embodiment and achieve the same technical effect. To avoid repetition, they will not be described again here.

[0122] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.

[0123] Figure 5 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of this application. The electronic device 1200 includes, but is not limited to, components such as: radio frequency unit 1201, network module 1202, audio output unit 1203, input unit 1204, sensor 1205, display unit 1206, user input unit 1207, interface unit 1208, memory 1209, and processor 1210.

[0124] Those skilled in the art will understand that the electronic device 1200 may also include a power supply (such as a battery) for supplying power to various components. The power supply may be logically connected to the processor 1210 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system. Figure 5 The electronic device structure shown does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements, which will not be elaborated here. It should be understood that, in this embodiment, the input unit 1204 may include a graphics processing unit (GPU) 12041 and a microphone 12042. The GPU 12041 processes image data of still images or videos obtained by an image capture device (such as a camera) in video capture mode or image capture mode. The display unit 1206 may include a display panel 12061, which may be configured in the form of a liquid crystal display, an organic light-emitting diode, or the like. The user input unit 1207 includes a touch panel 12071 and at least one of other input devices 12072. The touch panel 12071 is also called a touch screen. The touch panel 12071 may include a touch detection device and a touch controller. Other input devices 12072 may include, but are not limited to, physical keyboards, function keys (such as volume control buttons, power buttons, etc.), trackballs, mice, and joysticks, which will not be described in detail here.

[0125] The memory 1209 can be used to store software programs and various data. The memory 1209 may primarily include a first storage area for storing programs or instructions and a second storage area for storing data. The first storage area may store the operating system, application programs or instructions required for at least one function (such as sound playback, image playback, etc.). Furthermore, the memory 1209 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct memory bus RAM (DRRAM). The memory 1209 in this embodiment includes, but is not limited to, these and any other suitable types of memory.

[0126] Processor 1210 may include one or more processing units; optionally, processor 1210 integrates an application processor and a modem processor, wherein the application processor mainly handles operations involving the operating system, user interface, and applications, and the modem processor mainly handles wireless communication signals, such as a baseband processor. It is understood that the aforementioned modem processor may also not be integrated into processor 1210.

[0127] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above-described index optimization method embodiments and achieve the same technical effect. To avoid repetition, they will not be described again here.

[0128] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0129] This application also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described index optimization method embodiments and achieve the same technical effect. To avoid repetition, it will not be described again here.

[0130] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.

[0131] This application provides a computer program product that is stored in a storage medium and executed by at least one processor to implement the various processes of the index optimization method embodiment described above, and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0132] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.

[0133] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0134] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.

Claims

1. An index optimization method, characterized in that, The method includes: Based on the write time corresponding to the time series data being written to the target database by each acquisition task, the write timeout ratio is determined; and based on the query time corresponding to the time series data being queried from the target database by each computing task, the query timeout ratio is determined. If the write timeout ratio is greater than a first preset threshold, the current index mode of the inverted index corresponding to the time series data will be switched to the sharded index mode. If the write timeout ratio is less than or equal to the first preset threshold and the query timeout ratio is greater than the second preset threshold, the current index mode of the inverted index corresponding to the time series data will be switched to the merged index mode.

2. The method according to claim 1, characterized in that, The step of determining the write timeout ratio based on the write time corresponding to the write time of each acquisition task when writing time series data to the target database includes: For any acquisition task, the acquisition task is added to the write queue, and the write time is determined based on the write start time and write end time corresponding to the acquisition task. The write timeout ratio is determined based on the first number of acquisition tasks in the write queue whose write time is greater than the first preset period within the preset decision period.

3. The method according to claim 1, characterized in that, The step of determining the query timeout ratio based on the query time corresponding to the time series data retrieved from the target database for each computing task includes: For any computing task, the computing task is added to the query queue, and the query time is determined based on the query start time and query end time corresponding to the computing task. The query timeout ratio is determined based on the second number of computation tasks in the query queue whose query time is greater than the second preset period within the preset decision period.

4. The method according to claim 1, characterized in that, Switching the current index mode of the inverted index corresponding to the time series data to the sharded index mode includes: Enable mode switching lock; Switch the shard identifier to the first identifier corresponding to the shard index mode; the first identifier is used to indicate that the data to be written is written to the shard index instance. Close the mode switching lock.

5. The method according to claim 1, characterized in that, Switching the current index mode of the inverted index corresponding to the time series data to the merged index mode includes: Enable mode switching lock; Switch the shard identifier to the second identifier corresponding to the merge index mode; the second identifier is used to indicate that the data to be written is written to the merge index instance. Close the mode switching lock.

6. The method according to claim 4, characterized in that, The method further includes: When the segment identifier is the first identifier, a mode switching lock is activated for the data to be written corresponding to any of the acquisition tasks. Based on the data identifier corresponding to the data to be written and the preset number of shards, determine the target shard index instance corresponding to the data to be written from at least two shard index instances; Write the data to be written to the target shard index instance; Close the mode switching lock.

7. The method according to claim 5, characterized in that, The method further includes: When the segment identifier is the second identifier, a mode switching lock is activated for the data to be written corresponding to any of the acquisition tasks. Write the index information corresponding to the data to be written into the merged index instance; Close the mode switching lock.

8. The method according to claim 1, characterized in that, The method further includes: Enable deletion lock when the current index mode is switched to merge index mode; Merge the sharded index instances corresponding to the current index mode of sharded index mode to obtain a temporary index instance; Close the deletion lock; After merging the temporary index instances into the merged index instance, clear each of the sharded index instances.

9. The method according to claim 1, characterized in that, The method further includes: For any query tag indicated by a computing task, query the target data identifier that matches the query tag in each shard index instance and the merged index instance; Based on the target data identifier, the target query data indicated by the computing task is determined in the target database.

10. The method according to claim 1, characterized in that, The method further includes: Enable deletion lock for any tag to be deleted; Delete the index information that matches the tag to be deleted in each sharded index instance and merged index instance; Close the delete lock.

11. An index optimization device, characterized in that, The device includes: The first determining module is used to determine the write timeout ratio based on the write time corresponding to each acquisition task writing time series data into the target database, and to determine the query timeout ratio based on the query time corresponding to each computing task querying time series data from the target database. The first switching module is used to switch the current index mode of the inverted index corresponding to the time series data to the sharded index mode when the write timeout ratio is greater than a first preset threshold. The second switching module is used to switch the current index mode of the inverted index corresponding to the time series data to the merged index mode when the write timeout ratio is less than or equal to the first preset threshold and the query timeout ratio is greater than the second preset threshold.

12. The apparatus according to claim 11, characterized in that, The first determining module includes: The first determining submodule is used to add the acquisition task to the write queue for any acquisition task, and determine the write time based on the write start time and write end time corresponding to the acquisition task. The second determining submodule is used to determine the write timeout ratio based on the first number of acquisition tasks in the write queue whose write time is greater than the first preset period within a preset decision period.

13. The apparatus according to claim 11, characterized in that, The first determining module includes: The third determination submodule is used to add the computing task to the query queue for any computing task, and determine the query time based on the query start time and query end time corresponding to the computing task. The fourth determining submodule is used to determine the query timeout ratio based on the second number of computation tasks in the query queue whose query time is greater than the second preset period within a preset decision period.

14. An electronic device, characterized in that, It includes a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the index optimization method as described in claims 1-10.

15. A readable storage medium, characterized in that, The readable storage medium stores a program or instructions that, when executed by a processor, implement the steps of the index optimization method as described in claims 1-10.