Page view statistical method and device, equipment, medium and product
By automatically triggering index archiving and accurately matching query conditions in high-concurrency scenarios, the problem of low accuracy in access statistics and heavy database burden caused by cache invalidation is solved, achieving an efficient, accurate and flexible solution for access statistics.
Patent Information
- Application Number
- CN202411332626.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-24
- Publication Date
- 2025-01-10
AI Technical Summary
In high-concurrency scenarios, existing technologies frequently encounter cache failure issues, resulting in low accuracy of access statistics, increased database burden, and deep coupling between statistical functions and business logic, making it difficult to scale flexibly.
When the number of indexes stored in the database reaches a threshold or a preset time, the index archiving process is automatically triggered, and the first index is archived as the second index, reducing the risk of cache invalidation. By accurately matching query conditions, the accessed data can be quickly located and counted from the archived second index, avoiding frequent rollback of database queries.
It effectively reduces the risk of cache invalidation, lowers data synchronization latency and omissions, improves the accuracy and real-time performance of access statistics, decouples statistical functions from business logic, and enhances system stability and scalability.
Smart Images

Figure CN119293079A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of big data processing technology, and in particular relates to a method, device, equipment, medium and product for counting visit volume. Background Art
[0002] Usually, a website contains multiple pages, and website operators can publish the information they want to make public on the website pages. Users can access the website to obtain the information they need. In current Internet applications, visit statistics are an important basis for evaluating the activity of websites or applications, optimizing user experience, and guiding operation strategies.
[0003] In the prior art, the access statistics method generally uses the cache mechanism for efficient tracking and records user access information through the cache. However, this cache statistics method frequently suffers from cache failure problems in high-concurrency scenarios, including cache penetration, avalanche and breakdown, forcing frequent fallback to the database for verification and statistics, which not only increases the burden on the database, but also leads to low accuracy of access statistics due to data synchronization delays or omissions. Summary of the invention
[0004] The embodiments of the present application provide a method, device, equipment, medium and product for counting visit volume, which can improve the accuracy of visit volume statistics.
[0005] In a first aspect, an embodiment of the present application provides a method for counting page views, which is applied to a server side. The method includes:
[0006] In the case where the client initiates a first access request, if the number of indexes of the indexes stored in the database is greater than a preset threshold, or when a preset time is reached, all first indexes currently stored in the database are archived to obtain at least one second index, wherein a second index includes at least one access request stored in the first index, and the first access request includes an access identifier and an access time, and the access identifier is used to identify the information accessed by the client;
[0007] When the access time of the first access request is within the time range corresponding to the at least one second index, the first access request is stored in a third index, where the third index is a second index in the at least one second index corresponding to the access identifier and the access time of the first access request;
[0008] Receive a query request sent by a client, the query request includes query conditions, and the query conditions include target statistical information and statistical time range;
[0009] In response to the query request, obtaining a target access identifier that matches the target statistical information;
[0010] Acquire at least one target index matching the target access identifier and the statistical time range from the database;
[0011] Collect statistics on access requests stored in all target indexes, obtain statistical results that meet the query conditions, and send the statistical results to the client.
[0012] In a second aspect, an embodiment of the present application provides a device for counting page views, which is applied to a server side, and the device includes:
[0013] An archiving module is used to archive all first indexes currently stored in the database to obtain at least one second index when the client initiates a first access request, if the number of indexes of the indexes stored in the database is greater than a preset threshold or reaches a preset time, wherein the second index includes at least one access request stored in the first index, the first access request includes an access identifier and an access time, and the access identifier is used to identify the information accessed by the client;
[0014] a storage module, configured to store the first access request in a third index when the access time of the first access request is within a time range corresponding to the at least one second index, the third index being a second index in the at least one second index corresponding to the access identifier and the access time of the first access request;
[0015] A receiving module, configured to receive a query request sent by the client, wherein the query request includes query conditions, and the query conditions include target statistical information and a statistical time range;
[0016] A first acquisition module, configured to acquire a target access identifier matching the target statistical information in response to the query request;
[0017] A second acquisition module, configured to acquire from the database at least one target index that matches the target access identifier and the statistical time range;
[0018] The statistics module is used to count the access requests stored in all target indexes, obtain the statistical results that meet the query conditions, and send the statistical results to the client.
[0019] In a third aspect, an embodiment of the present application provides an electronic device, the device comprising: a processor and a memory storing computer program instructions;
[0020] When the processor executes the computer program instructions, the processor implements any possible implementation method of the first aspect described above.
[0021] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having computer program instructions stored thereon, which, when executed by a processor, implements a method in any possible implementation method of the first aspect described above.
[0022] In a fifth aspect, an embodiment of the present application provides a computer program product. When instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes a method as any possible implementation method in the first aspect above.
[0023] In the access volume statistics method, device, equipment, medium and product provided in the embodiments of the present application, when the client access volume surges and faces high concurrency challenges, the client's access requests are stored, and when these access requests need to be stored, if the preset time is reached or the number of indexes stored in the database reaches the preset threshold, the index archiving process can be automatically triggered to archive the accumulated first index as the second index. This effectively reduces the risk of cache failure, such as cache penetration, avalanche and breakdown, avoids frequent fallback queries to the database, thereby reducing the database burden and reducing the risk of data synchronization delays and omissions. When receiving a client query request, by accurately matching the target statistical information and statistical time range in the query conditions, the relevant access data can be quickly located and counted directly from the archived second index, rather than relying on easily failed caches or high-latency database queries. This refined processing method ensures the real-time and integrity of the statistical data, greatly improving the accuracy of access volume statistics. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solution of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0025] Figure 1 This is one of the flow charts of a method for counting page views provided in an embodiment of the present application;
[0026] Figure 2 This is the second flow chart of a method for counting page views provided in an embodiment of the present application;
[0027] Figure 3 This is a third flow chart of a method for counting page views provided in an embodiment of the present application;
[0028] Figure 4 This is a schematic diagram of interaction between a client and a server provided in an embodiment of the present application;
[0029] Figure 5It is a structural diagram of a device for counting visits provided by an embodiment of the present application;
[0030] Figure 6 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0031] The features and exemplary embodiments of various aspects of the present application will be described in detail below. In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, rather than to limit the present application. For those skilled in the art, the present application can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present application by illustrating the examples of the present application.
[0032] It should 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 statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0033] In addition, the acquisition, storage, use, and processing of data in the technical solution of this application comply with the relevant provisions of national laws and regulations.
[0034] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.
[0035] In current Internet applications, visit statistics are an important basis for evaluating the activity of websites or applications, optimizing user experience, and guiding operational strategies. Traditional methods rely on cache mechanisms to track visit volumes, and achieve statistics by recording the correspondence between client identifiers and page identifiers. However, this method is inadequate in a high-concurrency environment, and cache failures occur frequently, resulting in a sudden increase in database pressure and impaired statistical accuracy. In addition, although cache technology can alleviate some of the pressure, its space-for-time strategy requires additional storage resources, and is prone to cache penetration, avalanche, and breakdown under high-concurrency impacts, further exacerbating system instability.
[0036] On the other hand, traditional statistical methods often embed statistical codes tightly into business logic, resulting in deep coupling between statistical functions and business functions. This design not only increases development complexity and easily introduces errors, but also limits the flexibility and scalability of statistical functions, making it difficult to adapt to rapidly changing needs. With the growth of application scale and the diversification of statistical needs, how to efficiently, accurately and flexibly count visits has become an urgent problem to be solved.
[0037] Thus, in order to solve the problems of the prior art, the embodiments of the present application provide a method, device, equipment, medium and product for counting visit volume.
[0038] The following first introduces the pageview statistics method provided by the embodiment of the present application.
[0039] Figure 1 A flow chart of a method for counting page views provided in an embodiment of the present application is shown.
[0040] like Figure 1 As shown, the method for counting visits provided by the embodiment of the present application includes the following steps:
[0041] S100, when the client initiates a first access request, if the number of indexes stored in the database is greater than a preset threshold, or reaches a preset time, all first indexes currently stored in the database are archived to obtain at least one second index, and a second index includes at least one access request stored in the first index, and the first access request includes an access identifier and an access time, and the access identifier is used to identify the information accessed by the client.
[0042] Optionally, an access request refers to a request sent by a client to a server, and the access request is to obtain the content of a specific information (such as an article, video, picture, etc.).
[0043] The server is a program or service running on a network server that processes requests from clients and returns corresponding responses. The client is the device or software that users use to interact with the server, such as a browser or application on a personal computer, smartphone, or tablet.
[0044] The access identifier is used to identify which information (such as articles, videos, product details, etc.) the client is accessing. The access time refers to the time point when the access request occurs, which can be recorded in the form of a timestamp. The access time is crucial for counting the number of visits within a specific time period, because it allows the system to filter out access records that meet the query conditions (such as the statistical time range).
[0045] Optionally, an index is a data structure used to quickly access data stored on a storage device. In an embodiment of the present application, an index is used to associate access requests with target information (access identifier and access time), thereby allowing the system to efficiently retrieve and count accesses under specific conditions. Through the index, the system can quickly locate access request records that match a certain target statistical information and statistical time range without traversing all stored access data.
[0046] Optionally, in a specific implementation of the present application, each time the client initiates a first access request, the system will first check the index status stored in the current database. The index mentioned here mainly refers to the data structure that records the user's access behavior. Each first index contains a series of access requests, and each request specifically contains an access identifier (used to uniquely identify the specific information accessed by the client) and the access time. If it is detected that the number of indexes in the database exceeds a preset threshold (this threshold can be set according to the processing power of the server and the needs of data management, aiming to avoid inefficient queries or management complexity caused by too many indexes), or the system reaches a preset time point (for example, every Monday, or a certain time on the first day of each month, automatic archiving is performed to facilitate weekly or monthly statistics, etc.), the system will trigger the archiving process.
[0047] The core goal of archiving is to merge and optimize all currently stored first indexes to generate at least one second index. Each second index contains data from multiple first indexes, that is, it integrates access requests under multiple time periods or request identifiers. This integration is not a simple data stacking, but is based on certain rules or strategies. For example, it can be clustered according to dimensions such as access type and user behavior characteristics for subsequent data analysis and mining.
[0048] During the archiving process, you first need to scan all the first indexes in the database and evaluate their data volume and content. Then, according to the preset archiving strategy (such as time range, data importance, etc.), select the first index to be merged. Next, perform the actual merge operation to migrate the data in the selected first index to the new second index. In order to maintain the consistency and integrity of the data, this specifically involves steps such as data cleaning, conversion, and deduplication.
[0049] After the archiving process is completed, the index information in the database needs to be updated, including deleting the reference to the archived first index and establishing an access path to the newly generated second index. At the same time, in order to ensure the traceability and security of the data, the first index data before archiving can also be backed up to an external storage medium.
[0050] Through regular or index number threshold-based archiving, the number and size of database indexes can be effectively managed, the complexity of database queries can be reduced, and data retrieval efficiency can be improved. At the same time, archiving can also optimize the data storage structure, facilitate long-term preservation and in-depth analysis of access request data, and provide strong support for business decision-making and data analysis.
[0051] S200, when the access time of the first access request is within the time range corresponding to the at least one second index, the first access request is stored in a third index, and the third index is a second index in the at least one second index corresponding to the access identifier and access time of the first access request.
[0052] Optionally, in a feasible implementation of the present application, when a new first access request arrives, the access identifier and access time information in the request are first parsed. Subsequently, the server checks the second index set generated by the previous archiving process, each of which corresponds to a certain time range and contains all the access requests of the first index within the time period. The system traverses these second indexes and uses efficient algorithms such as binary search, hash table or range query to quickly determine whether the access time of the first access request falls within the time range of one or more second indexes.
[0053] Once the second index with a matching access time is determined, the server will further verify whether the access identifier also matches the data in the second index. Since each second index may contain access requests for multiple different information, the precise comparison of the access identifiers can ensure that the first access request is stored in an index that matches both its information content and timestamp. Here, this index that completely matches the first access request is called the "third index". Although in actual operation, it may only be a subset or specific part of a second index, it is abstracted as the concept of the "third index" for ease of understanding.
[0054] When implementing this step, the server can use some optimization strategies to improve processing efficiency. For example, an auxiliary data structure, such as an index tree, hash table, or time wheel, can be maintained for each second index to quickly locate the index interval corresponding to the access time. At the same time, for the matching of access identifiers, multiple strategies such as prefix matching, complete matching, or fuzzy matching can be used, depending on business needs and data characteristics.
[0055] In addition, to ensure the consistency and integrity of the data, the server may perform a series of checks and verifications before adding the first access request to the third index, such as checking the uniqueness of the access identifier, the rationality of the access time, etc. After completing these preparations, the data of the first access request may be added to the third index, including updating the counter of the index, appending the access record to the index list, or performing corresponding insert operations in the database.
[0056] This processing flow ensures that each first access request can be accurately classified into its corresponding index, providing a solid foundation for subsequent query and statistical operations. At the same time, this storage strategy based on dual matching of time and information content also effectively improves the accuracy and efficiency of access statistics.
[0057] S300, receiving a query request sent by the client, wherein the query request includes query conditions, and the query conditions include target statistical information and a statistical time range.
[0058] Optionally, a query request is a request sent by a client to a server to obtain the visit statistics of a specific information within a specified time period. It contains the specific content and conditions that the client wants to query and is the starting point for triggering the statistical process.
[0059] Query conditions are the specific requirements that a query request must meet, including two core elements: target statistical information and statistical time range. These conditions help the server locate the access records that need to be counted, ensuring the accuracy and pertinence of the statistical results.
[0060] Target statistics are specific information specified in the query request that the client wants to know the number of visits. It can be a unique identifier of the information (such as ID), title, or other attributes that can uniquely identify the content of the information. The setting of target statistics allows the statistical process to focus on specific information objects.
[0061] The statistical time range is a parameter defined in the query request to limit the time span of access record statistics. It usually includes the start time and the end time to ensure that the statistical results only include access records that occurred during this period. Setting the statistical time range helps the client obtain more accurate and meaningful access statistics.
[0062] Optionally, in a feasible implementation of the present application, in step S300, when the client needs to know the number of visits to a certain information in a specific time period, the client sends a query request to the server. The query request includes two key query conditions: target statistical information and statistical time range.
[0063] S400, in response to the query request, obtaining a target access identifier that matches the target statistical information.
[0064] Optionally, in a feasible implementation of the present application, when the server receives the query request sent by the client and successfully parses the query conditions (including the target statistical information and the statistical time range), the server will first search for the target statistical information. Specifically, the server can maintain a mapping relationship between an information identifier and an access identifier. This mapping relationship can be implemented through a database table or a hash table, which allows the server to quickly locate the access identifier related to the information based on the unique identifier of the information.
[0065] In S400, the server traverses the mapping relationship to find the access identifier that matches the target statistical information. This process may specifically involve algorithms such as string matching and hash search, depending on the implementation method of the mapping relationship.
[0066] S500: Acquire from the database at least one target index that matches the target access identifier and the statistical time range.
[0067] Optionally, in an embodiment of the present application, the server side may include an Elasticsearch database, which is a distributed, highly scalable, and highly real-time search and data analysis engine. It can easily enable large amounts of data to have the ability to search, analyze, and explore. Each index can be stored in the Elasticsearch database.
[0068] Optionally, in a feasible implementation of the present application, the target statistical information and statistical time range in the query request received from the client can be parsed first, and then the search capability of Elasticsearch, especially the fuzzy matching function based on the index name, can be used to quickly locate all indexes containing records related to the target access identifier and the statistical time range.
[0069] To achieve this process, you can first build an Elasticsearch query statement that combines keyword fuzzy matching of index names (used to find indexes related to the target statistical information) and exact matching of time ranges (used to filter out access requests that occurred within a specified time). After executing this query statement, Elasticsearch will return a list of all eligible indexes, which store the client's access request records for the target statistical information within the specified time.
[0070] It should be noted that since Elasticsearch can be used to process fast retrieval of large-scale data, this process can be completed in a relatively short time and can maintain high performance even in the face of large amounts of data.
[0071] S600: Count the access requests stored in all target indexes to obtain statistical results that meet the query conditions, and send the statistical results to the client.
[0072] Optionally, in a feasible implementation of the present application, the access requests stored in all target indexes acquired in S500 may be traversed and counted. These target indexes are directly associated with the target statistical information and statistical time range specified by the client in the query request, so the access request records contained in the target index are the basis of the statistical results.
[0073] The system will first read the access request records in each target index. Next, the system will check each access request record one by one to verify whether its access identifier matches the access identifier of the target statistical information and whether the access time falls within the statistical time range. Only access request records that meet both conditions will be included in the final statistical results.
[0074] During the verification and screening process, the system will count the access request records that meet the conditions to calculate the total number of visits. According to actual needs, the statistical results can also include other indicators, such as access frequency distribution, access time analysis, client type statistics, etc.
[0075] After the statistics are completed, the system will encapsulate the statistical results into a format that is easy for the client to understand and process (such as JSON, XML, etc.), and send it to the client through the network protocol. The statistical results can directly present the total number of visits in numerical form, or can include more detailed statistical data tables or charts for further analysis and display by the client.
[0076] It should be noted that, in order to ensure the accuracy and timeliness of the statistical results, the execution of step S500 can also consider the issues of concurrent access and data consistency. Especially in high-concurrency access scenarios, appropriate concurrency control strategies (such as lock mechanisms, transaction processing, etc.) can be adopted to ensure the atomicity and consistency of the statistical process. In addition, in order to cope with possible system failures or data loss, a data backup and recovery mechanism can also be implemented to ensure the reliability and recoverability of the statistical results.
[0077] In the access volume statistics method provided in the embodiment of the present application, when the client access volume surges and faces high concurrency challenges, the client's access requests are stored, and when these access requests need to be stored, if the preset time is reached or the number of indexes stored in the database reaches the preset threshold, the index archiving process can be automatically triggered to archive the accumulated first index as the second index. This effectively reduces the risk of cache failure, such as cache penetration, avalanche and breakdown, avoids frequent fallback queries to the database, thereby reducing the database burden and reducing the risk of data synchronization delays and omissions. When receiving a client query request, by accurately matching the target statistical information and statistical time range in the query conditions, the relevant access data can be quickly located and counted directly from the archived second index, rather than relying on easily failed caches or high-latency database queries. This refined processing method ensures the real-time and integrity of the statistical data, greatly improving the accuracy of access volume statistics.
[0078] In one embodiment, if Figure 2 As shown, the method can specifically perform the following steps:
[0079] S110, when the access time of the first access request is not within the time range corresponding to at least one second index, create a new index, where the new index corresponds to the access identifier and the access time of the first access request;
[0080] S120: Create shards of a new index according to a preset number of shards, and store the first access request in any shard of the new index.
[0081] Optionally, in a feasible implementation of the present application, the server will immediately trigger the creation process of a new index for a newly arrived first access request when its access time does not fall within the time range covered by the existing second index. This new index is not only closely associated with the access identifier of the current first access request (i.e., the specific information accessed by the client), but also accurately records the access time of the request, thereby ensuring the timeliness and accuracy of the index.
[0082] Next, in order to optimize the storage and query efficiency of the index, shards of the new index can be created according to the preset number of shards. Sharding is a technology that divides a database into multiple smaller, more manageable parts, which can help improve the read and write performance and scalability of the database. In this application, the sharding strategy can be allocated based on a certain hash function result of the access identifier or a certain rule of access time to ensure that data can be evenly distributed in different shards.
[0083] Finally, the first access request is stored in a shard of the new index. This storage process involves writing the access request data (including access ID, access time, client information, etc.) into the selected shard. In specific implementation, the application programming interface (API) or command provided by the database can be used to perform data insertion operations and ensure data consistency and integrity.
[0084] In these optional embodiments, by dynamically creating indexes and applying sharding technology, the client's access request data is effectively managed to ensure the timeliness and accuracy of the data. At the same time, the sharding strategy improves the scalability and query efficiency of the database, so that the stability and performance of the system can be maintained even in high-concurrency scenarios, providing reliable data support for subsequent access statistics and data analysis.
[0085] In one embodiment, if Figure 3 As shown, the above step 110 can specifically perform the following steps:
[0086] S111, when the access time of the first access request is not within the time range corresponding to at least one second index, creating a new index according to a first date and an access identifier of the first access request, wherein the first date corresponds to the access time of the first access request;
[0087] After creating a new index according to the first date and the access identifier of the first access request, the method further includes:
[0088] S130, each time the client receives an access request, the access request that is on the first date and matches the access identifier of the first access request is stored in a new index.
[0089] Optionally, in a specific implementation of the present application, as Figure 4 As shown, the present application can provide a visit statistics platform, including a client and a server, and the client and the server adopt a microservice architecture with front-end and back-end separation for distributed deployment. Among them, the server can include an application server and a load balancing server.
[0090] The application server provides services through the API interface, and each interface has its own interface identifier. For example, it can be identified by a 6-digit transaction code, such as the transaction code of the A information interface is "300001", and the transaction code of the query B information interface is "700001". Among them, LogStash is an open source data transmission engine similar to a real-time pipeline. It is like a data transmission pipeline that connects different data sources at both ends, transmitting data from one data source to another in real time. During the data transmission process, LogStash can also clean, process and organize the data, so that the data is directly available or nearly available when it arrives at the destination, preparing for more complex data analysis, processing and visualization.
[0091] Optionally, in a feasible implementation of the present application, a combination of Logstash and Elasticsearch is used to optimize the collection and storage process of access requests. Specifically, when the client initiates the first access request, and the access identifier (such as "contentid:001") and access time (i.e., the first date) of the first access request do not have a corresponding index in Elasticsearch, the access statistics platform can trigger the index creation process. As a data collection tool, Logstash will monitor and collect client access logs recorded on nginx (i.e., load balancing server) in real time. Since nginx logs are cut by day, Logstash will dynamically generate an index name in the format of "keyword + date" based on the date of the log file (i.e., the first date) and the request identifier in the first access request (such as "msgtype:700001" and "contentid:001"). Next, configure the appropriate number of shards and copies for this new index to ensure data availability and performance. After the index is created, Logstash will batch write all the access request data (log entries stored in JSON format) that match the request identifier under the current date into the newly created index. In this way, Elasticsearch can efficiently store and manage these access data, support subsequent data query, analysis and report generation, and provide strong support for access analysis of charity projects or information.
[0092] In these optional embodiments, by dynamically creating indexes, the real-time and pertinence of data is ensured, which facilitates subsequent rapid retrieval and analysis. At the same time, access requests with the same date and matching request identifiers are uniformly stored, which improves data consistency and query efficiency, and provides a solid foundation for data analysis and access statistics.
[0093] In one embodiment, the time interval between access requests stored in the first index is a first time interval;
[0094] The archiving process of all first indexes currently stored in the database to obtain at least one second index includes:
[0095] creating the second index according to a second time interval and a second date, wherein the second time interval is greater than the first time interval;
[0096] Obtaining a fourth index in the first index that meets a first preset condition, where the first preset condition is that the fourth index is on the second date;
[0097] The access request in the fourth index is synchronized to the second index, and the fourth index is deleted.
[0098] In these optional embodiments, by increasing the time interval of access requests in the index (from the first time interval to the second time interval), effective archiving of the first index in the database is achieved to form a more streamlined second index. This process not only reduces the storage requirements of the index and improves the efficiency of database management, but also ensures the continuity and timeliness of data access by synchronizing qualified access requests to the new index and deleting the old index, thereby optimizing the maintenance strategy and query performance of the database.
[0099] In one embodiment, the server side includes a plurality of interfaces, one interface being used to access a type of information;
[0100] The archiving process of all first indexes currently stored in the database to obtain at least one second index includes:
[0101] For an interface identifier of any interface, create the second index according to the second time interval, the second date and the interface identifier of the interface;
[0102] Acquire a fifth index in the first index that meets a second preset condition, wherein the preset condition includes being on the second date and matching the interface identifier of the interface;
[0103] The access request in the fifth index is synchronized to the second index, and the fifth index is deleted.
[0104] Optionally, in a feasible implementation of the present application, first, the archiving task is started regularly (such as at the beginning of each month). At the beginning of the task, a new second index is created according to the current month and the second time interval (such as the entire month), and the names of these indexes will contain month information for easy distinction and management. At the same time, the target mapping, shard count, and number of copies of the new index are set to ensure that it can efficiently store and query data.
[0105] Next, all first indexes stored in the current database are traversed, which record access request data in different time periods. For each first index, the module checks whether it contains data within the current archive month (i.e., the second date). This step can be determined by comparing the timestamp recorded in the index with the archive month.
[0106] To further improve the accuracy of archiving, if the platform supports multiple interfaces and each interface corresponds to a different data set, the first index can also be filtered according to the interface identifier of the interface. Only those indexes that are both in the archiving month and match the specific interface identifier (i.e., the fifth index) will be selected for the next step of processing.
[0107] Once the indices that need to be archived are determined, the module will use the reindex method provided by Elasticsearch to synchronize the data in these indices that meet the archiving criteria to the new second index. The reindex method allows efficient copying of data from one index to another, while supporting data filtering and transformation to ensure that only valid and necessary data is migrated.
[0108] After data synchronization is completed, the original source index (i.e., the fourth index or the fifth index) is deleted to free up storage space and avoid data redundancy. This step is the key to archiving processing, which ensures the effective use of resources and the optimization of query performance.
[0109] Through the above steps, monthly archiving of Elasticsearch index data is achieved, effectively solving the problem of insufficient resources and degraded query performance caused by excessive index volume. At the same time, through filtering of interface identifiers, the accuracy and flexibility of archiving are further improved, meeting the data management needs in different business scenarios.
[0110] In these optional embodiments, by expanding the time interval and interface identification to archive the index, the number of indexes is effectively reduced, the query efficiency is improved, and the integrity of the data classified by interface is retained. By accurately matching the date and interface identification, the accuracy and pertinence of the archived data are ensured, providing strong support for subsequent data analysis and business decision-making.
[0111] Optionally, in the embodiment of the present application, Elasticsearch and Logstash are used to implement the real-time statistics query function of the access volume, which can realize the decoupling of the statistics and query functions from the business functions, improve the system concurrency performance, and support the rapid expansion of the statistics function. When new statistical elements need to be added, on the news information aggregation platform, when the news editing team wants to track the reading volume of news information in a specific category (such as technology, sports or entertainment), there is no need to modify the original business function code logic of news release and content management. It only needs to develop a query interface for the reading volume of news in this category, and the statistics and analysis functions can be quickly realized, so as to timely grasp the trend of readers' interests and optimize the content recommendation strategy.
[0112] In one embodiment, the acquiring from the database at least one target index matching the target access identifier and the statistical time range includes:
[0113] Using the target access identifier and the statistical time range as keywords, obtaining at least one target index name matching the keywords from the database according to a fuzzy matching algorithm;
[0114] The at least one target index corresponding to each of the at least one target index name is obtained from the database.
[0115] Optionally, in a feasible implementation of the present application, the target access identifier and the statistical time range are first received as query keywords. These keywords are provided by the user when he wants to query specific access data, and are used to accurately or roughly locate relevant index information in the database.
[0116] Next, the query operation is performed using a fuzzy matching algorithm. A fuzzy matching algorithm is a technique that can find similar results without a complete match, allowing for certain differences or similarities between keywords and entries in a database. In this application, a fuzzy matching algorithm is designed to identify index names that contain some or all of the characters of the target access identifier and fall within (or close to) a statistical time range. This algorithm takes into account a variety of factors, such as the similarity of keywords, the creation time of the index name, the timestamp range of the data in the index, etc., to ensure the accuracy and relevance of the retrieval results.
[0117] Through the fuzzy matching algorithm, at least one target index name that matches the target access identifier and the statistical time range can be screened out from the database. These index names are the access identifiers of the indexes that are actually stored in the database and match the query conditions. It is worth noting that due to the use of fuzzy matching, the retrieval results may contain multiple index names, which may not completely meet the user's precise query conditions, but they are related to the keywords provided by the user to some extent.
[0118] Finally, according to the retrieved target index names, the actual target indexes corresponding to these index names are further obtained from the database. This step involves reading the detailed information and related data of the index from the index storage area of the database. Each target index contains a series of access request data collected within the time range of its creation. These data are associated with a specific access identifier and can be used for subsequent statistical analysis or data query.
[0119] In summary, by using the target access identifier and statistical time range as keywords for fuzzy matching, and retrieving and obtaining the matching target index name and its corresponding index from the database, the system can flexibly and efficiently respond to user query needs and provide accurate and useful access data statistical analysis results. This method not only improves the flexibility of queries, but also can deal with the problem of irregular index naming or uneven data distribution in the database to a certain extent.
[0120] Based on the visit volume statistics method provided in the above embodiment, the present application also provides a specific implementation of the visit volume statistics device. Please refer to the following embodiment.
[0121] like Figure 5 As shown, the access statistics device provided in the embodiment of the present application is applied to the server side, and the access statistics device includes the following modules:
[0122] The archiving module 501 is used to archive all first indexes currently stored in the database to obtain at least one second index when the client initiates a first access request, if the number of indexes of the indexes stored in the database is greater than a preset threshold or reaches a preset time, and a second index includes at least one access request stored in the first index, and the first access request includes an access identifier and an access time, and the access identifier is used to identify the information accessed by the client;
[0123] A storage module 502 is configured to store the first access request in a third index when the access time of the first access request is within a time range corresponding to the at least one second index, wherein the third index is a second index in the at least one second index corresponding to the access identifier and the access time of the first access request;
[0124] The receiving module 503 is used to receive a query request sent by the client, wherein the query request includes a query condition, and the query condition includes target statistical information and a statistical time range;
[0125] A first acquisition module 504, configured to acquire a target access identifier matching the target statistical information in response to the query request;
[0126] A second acquisition module 505 is used to acquire at least one target index that matches the target access identifier and the statistical time range;
[0127] The statistics module 506 is used to count the access requests stored in all target indexes, obtain the statistics results that meet the query conditions, and send the statistics results to the client.
[0128] In one embodiment, the access statistics device may further include:
[0129] a first creation module, configured to create a new index if the access time of the first access request is not within the time range corresponding to the at least one second index, the new index corresponding to the access identifier and the access time of the first access request;
[0130] The second creation module is used to create slices of the new index according to a preset number of slices, and store the first access request in any one of the slices of the new index.
[0131] In one embodiment, the first creation module may include:
[0132] a first creation submodule, configured to create the new index according to a first date and an access identifier of the first access request when the access time of the first access request is not within a time range corresponding to the at least one second index, wherein the first date corresponds to the access time of the first access request;
[0133] In one embodiment, the access statistics device may further include:
[0134] The second storage module is used for storing the access request on the first date and matching the access identifier of the first access request in the new index each time the client receives an access request.
[0135] In one embodiment, the time interval between the access requests stored in the first index is a first time interval; the archiving module 501 may include:
[0136] A first creation submodule, configured to create the second index according to a second time interval and a second date, wherein the second time interval is greater than the first time interval;
[0137] A first acquisition submodule is used to acquire a fourth index in the first index that meets a first preset condition, where the first preset condition is that the fourth index is on the second date;
[0138] The first synchronization submodule is used to synchronize the access request in the fourth index to the second index and delete the fourth index.
[0139] In one embodiment, the server includes multiple interfaces, one interface is used to access a type of information; the archiving module may include:
[0140] A second creation submodule, configured to create, for an interface identifier of any interface, the second index according to the second time interval, the second date and the interface identifier of the interface;
[0141] A second acquisition submodule, configured to acquire a fifth index in the first index that meets a second preset condition, wherein the preset condition includes being on the second date and matching an interface identifier of the interface;
[0142] The second synchronization submodule is used to synchronize the access request in the fifth index to the second index and delete the fifth index.
[0143] In one embodiment, the second acquisition module 505 may include:
[0144] A third acquisition submodule is used to use the target access identifier and the statistical time range as keywords and acquire at least one target index name matching the keywords from the database according to a fuzzy matching algorithm;
[0145] The fourth acquisition submodule is used to acquire from the database the at least one target index corresponding to each of the at least one target index names.
[0146] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application, and are devices corresponding to the above-mentioned battery thermal runaway warning method. All implementation methods in the above-mentioned method embodiment are applicable to the embodiments of the device. Its specific functions and technical effects can be found in the method embodiment part, which will not be repeated here.
[0147] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0148] Figure 6 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application is shown.
[0149] The device may include a processor 601 and a memory 602 storing program instructions.
[0150] When the processor 601 executes the program, the steps in any of the above method embodiments are implemented.
[0151] Exemplarily, the program may be divided into one or more modules / units, one or more modules / units are stored in the memory 602 and executed by the processor 601 to complete the present application. One or more modules / units may be a series of program instruction segments capable of completing a specific function, and the instruction segments are used to describe the execution process of the program in the device.
[0152] Specifically, the processor 601 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0153] The memory 602 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 602 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. In appropriate cases, the memory 602 may include a removable or non-removable (or fixed) medium. In appropriate cases, the memory 602 may be inside or outside the integrated gateway disaster recovery device. In a specific embodiment, the memory 602 is a non-volatile solid-state memory.
[0154] The memory may include read-only memory (ROM), random access memory (RAM), magnetic disk storage media devices, optical storage media devices, flash memory devices, electrical, optical or other physical / tangible memory storage devices. Thus, typically, the memory includes one or more tangible (non-transitory) readable storage media (e.g., memory devices) encoded with software including computer executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the method according to an aspect of the present disclosure.
[0155] The processor 601 implements any one of the methods in the above embodiments by reading and executing program instructions stored in the memory 602 .
[0156] In one example, the electronic device may further include a communication interface 603 and a bus 610. The processor 601, the memory 602, and the communication interface 603 are connected via the bus 610 and communicate with each other.
[0157] The communication interface 603 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.
[0158] Bus 610 includes hardware, software or both, and the parts of online data flow billing equipment are coupled to each other. For example, but not limitation, bus may include accelerated graphics port (AGP) or other graphics bus, enhanced industrial standard architecture (EISA) bus, front-end bus (FSB), hypertransport (HT) interconnection, industrial standard architecture (ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnection (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations. In appropriate cases, bus 610 may include one or more buses. Although the present application embodiment describes and shows a specific bus, the present application considers any suitable bus or interconnection.
[0159] In addition, in combination with the method in the above embodiment, the embodiment of the present application can provide a storage medium for implementation. The storage medium stores program instructions; when the program instructions are executed by a processor, any one of the methods in the above embodiment is implemented.
[0160] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface and the processor are coupled, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0161] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.
[0162] An embodiment of the present application provides a computer program product, which is stored in a storage medium. The program product is executed by at least one processor to implement the various processes of the above-mentioned method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0163] It should be clear that the present application is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present application is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present application.
[0164] The functional modules shown in the above block diagram can be implemented as hardware, software, firmware or their combination. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), suitable firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present application are programs or code segments that are used to perform the required tasks. Programs or code segments can be stored in machine-readable media, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable media" can include any medium that can store or transmit information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. Code segments can be downloaded via computer grids such as the Internet, intranets, etc.
[0165] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiment, or in a different order from the embodiment, or several steps can be performed simultaneously.
[0166] Aspects of the present disclosure are described above with reference to the flowchart and / or block diagram of the method, device (system) and program product according to the embodiment of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer program instructions. These program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the implementation of the function / action specified in one or more boxes of the flowchart and / or block diagram. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor or a field programmable logic circuit. It can also be understood that each box in the block diagram and / or flowchart and the combination of boxes in the block diagram and / or flowchart can also be implemented by dedicated hardware that performs a specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.
[0167] The above are only specific implementation methods of the present application. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the protection scope of the present application is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in this application, and these modifications or replacements should be included in the protection scope of this application.
Claims
1. A method for counting visits, characterized in that: Applied to the server side, the method includes: In the case where the client initiates a first access request, if the number of indexes of the indexes stored in the database is greater than a preset threshold, or when a preset time is reached, all first indexes currently stored in the database are archived to obtain at least one second index, and a second index includes at least one access request stored in the first index, and the first access request includes an access identifier and an access time, and the access identifier is used to identify the information accessed by the client; If the access time of the first access request is within the time range corresponding to the at least one second index, storing the first access request in a third index, where the third index is a second index in the at least one second index corresponding to the access identifier and the access time of the first access request; Receiving a query request sent by the client, the query request including query conditions, the query conditions including target statistical information and statistical time range; In response to the query request, obtaining a target access identifier that matches the target statistical information; Acquire at least one target index matching the target access identifier and the statistical time range from the database; Statistics are collected on the access requests stored in all target indexes to obtain statistical results that meet the query conditions, and the statistical results are sent to the client.
2. The method according to claim 1, characterized in that The method further comprises: In a case where the access time of the first access request is not within the time range corresponding to the at least one second index, creating a new index, wherein the new index corresponds to the access identifier and the access time of the first access request; According to the preset number of shards, shards of the new index are created, and the first access request is stored in any shard of the new index.
3. The method according to claim 2, characterized in that The creating a new index when the access time of the first access request is not within the time range corresponding to the at least one second index comprises: In a case where the access time of the first access request is not within the time range corresponding to the at least one second index, creating the new index according to a first date and the access identifier of the first access request, wherein the first date corresponds to the access time of the first access request; After creating the new index according to the first date and the access identifier of the first access request, the method further includes: Each time the client receives an access request, the access request that is on the first date and matches the access identifier of the first access request is stored in the new index.
4. The method according to claim 1, characterized in that: The time interval between the access requests stored in the first index is a first time interval; The archiving process of all first indexes currently stored in the database to obtain at least one second index includes: creating the second index according to a second time interval and a second date, wherein the second time interval is greater than the first time interval; Obtaining a fourth index in the first index that meets a first preset condition, where the first preset condition is that the fourth index is on the second date; The access request in the fourth index is synchronized to the second index, and the fourth index is deleted.
5. The method according to claim 4, characterized in that The server side includes multiple interfaces, one interface is used to access a type of information; The archiving process of all first indexes currently stored in the database to obtain at least one second index includes: For an interface identifier of any interface, create the second index according to the second time interval, the second date and the interface identifier of the interface; Acquire a fifth index in the first index that meets a second preset condition, wherein the preset condition includes being on the second date and matching the interface identifier of the interface; The access request in the fifth index is synchronized to the second index, and the fifth index is deleted.
6. The method according to claim 1, characterized in that The acquiring, from the database, at least one target index that matches the target access identifier and the statistical time range comprises: Using the target access identifier and the statistical time range as keywords, obtaining at least one target index name matching the keywords from the database according to a fuzzy matching algorithm; The at least one target index corresponding to each of the at least one target index name is obtained from the database.
7. A device for counting visits, characterized in that: Applied to the server side, the device comprises: An archiving module is used to archive all first indexes currently stored in the database to obtain at least one second index when the client initiates a first access request, if the number of indexes of the indexes stored in the database is greater than a preset threshold or reaches a preset time, wherein the second index includes at least one access request stored in the first index, the first access request includes an access identifier and an access time, and the access identifier is used to identify the information accessed by the client; a storage module, configured to store the first access request in a third index when the access time of the first access request is within a time range corresponding to the at least one second index, the third index being a second index in the at least one second index corresponding to the access identifier and the access time of the first access request; A receiving module, configured to receive a query request sent by the client, wherein the query request includes query conditions, and the query conditions include target statistical information and a statistical time range; A first acquisition module, configured to acquire a target access identifier matching the target statistical information in response to the query request; A second acquisition module, configured to acquire from the database at least one target index that matches the target access identifier and the statistical time range; The statistics module is used to count the access requests stored in all target indexes, obtain the statistical results that meet the query conditions, and send the statistical results to the client.
8. An electronic device, characterized in that: The electronic device comprises: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, the access volume statistics method as described in any one of claims 1-6 is implemented.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, the method for counting visits according to any one of claims 1 to 6 is implemented.
10. A computer program product, characterized in that When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the visit volume statistics method as described in any one of claims 1 to 6.
Citation Information
Cited By
Data table processing method and device, storage medium and electronic equipment
CN119961265A