Information statistics method based on programming language golang and device thereof
By using custom coding and data structures in the Golang language, and leveraging sync.Map and consumer coroutines, we can achieve high-concurrency monitoring and aggregation statistics for API services. This solves the problem of third-party monitoring that requires professional talent and resources in existing technologies, and enables efficient and stable API call monitoring and statistics.
Patent Information
- Application Number
- CN202310232009.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-10
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2043-03-10
AI Technical Summary
Existing technologies for internet backend API services require the introduction of third-party monitoring products with specialized personnel and additional resources to monitor and aggregate statistics on API calls, which increases system complexity.
This paper adopts an information statistics method based on the Golang language. By custom coding and designing appropriate data structures and algorithms, and utilizing the Golang standard library, it obtains the calculation dimension information and metric information of API services. The data is then summarized and statistically analyzed through a global memory of type sync.Map and consumer coroutines, realizing simple traffic monitoring and aggregation statistics under high concurrency.
Without adding heavyweight third-party monitoring products, it can quickly and efficiently monitor and aggregate statistics of API calls, reducing system complexity and maintenance costs, and improving the stability and efficiency of monitoring.
Smart Images

Figure CN116360746B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of data processing technology, particularly to technologies such as cloud computing and artificial intelligence (AI), and especially to an information statistics method and apparatus based on the programming language Golang. Background Technology
[0002] In Internet (Web) backend Application Programming Interface (API) services, it is typically necessary to monitor and aggregate statistics on API calls across various dimensions. Common technologies used in this context include general-purpose monitoring products such as ELK (an open-source log collection software) log analysis system, Promethus monitoring system, and Grafana (an open-source data visualization tool). However, the deployment, maintenance, development, and testing of such monitoring products require specialized personnel and additional machine resources, increasing the overall system complexity. Summary of the Invention
[0003] This disclosure provides an information statistics method, apparatus, electronic device, and storage medium based on the Golang programming language.
[0004] According to a first aspect of this disclosure, an information statistics method based on the programming language Golang is provided, including:
[0005] Obtain the full-link data of the network request, and based on the full-link data, obtain the calculation dimension information and metric information of the application programming interface (API) service called by the network request;
[0006] The computational dimension information and metric information of the API service invoked by the network request are sent to the pipeline;
[0007] A consumer coroutine is started, and at least one data object to be statistically analyzed is determined through the consumer coroutine and the global memory; wherein, the data type of the global memory adopts the sync.Map type, the keys in the sync.Map type data indicate the calculated dimension information, the values in the sync.Map type data indicate the metric information, and the consumer coroutine iterates through the sync.Map type data to consume it.
[0008] Through the consumer coroutine, the computational dimension information and metric information in the pipeline are summarized and statistically analyzed based on the at least one statistical data object, and the summarized and statistically analyzed data is stored in the global memory.
[0009] According to a second aspect of this disclosure, an information statistics device based on the programming language Golang is provided, comprising:
[0010] The acquisition module is used to acquire the full-link data of the network request, and based on the full-link data, acquire the calculation dimension information and metric information of the application programming interface (API) service called by the network request.
[0011] The sending module is used to send the calculation dimension information and metric information of the API service invoked by the network request to the pipeline;
[0012] A determination module is used to initiate a consumer coroutine and, through the consumer coroutine and a global memory, determine at least one object to be statistically analyzed; wherein, the data type of the global memory adopts a sync.Map type, the keys in the sync.Map type data indicate the calculated dimension information, the values in the sync.Map type data indicate the metric information, and the consumer coroutine iterates through the sync.Map type data to consume it;
[0013] The statistics module is used to summarize and statistically analyze the computational dimension information and metric information in the pipeline based on the at least one statistical data object through the consumer coroutine, and store the summarized statistical data in the global memory.
[0014] According to a third aspect of this disclosure, an electronic device is provided, comprising:
[0015] At least one processor; and
[0016] A memory communicatively connected to the at least one processor; wherein,
[0017] The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method described in the first aspect above.
[0018] According to a fourth aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions, wherein the computer instructions are configured to cause the computer to perform the method described in the first aspect above.
[0019] According to a fifth aspect of this disclosure, a computer program product is provided, comprising a computer program, wherein the computer program, when executed by a processor, implements the steps of the method described in the first aspect above.
[0020] According to the technical solution disclosed herein, it is possible to quickly, efficiently and stably implement API interface call monitoring and aggregation statistics without adding heavyweight third-party monitoring products, thereby achieving the goal of cost reduction and efficiency improvement.
[0021] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description
[0022] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein:
[0023] Figure 1 A flowchart illustrating an information statistics method based on the Golang language provided in this embodiment of the disclosure;
[0024] Figure 2 A flowchart illustrating another information statistics method based on the Golang language provided in this disclosure embodiment;
[0025] Figure 3 This is a flowchart illustrating an information statistics method based on the Golang language according to an embodiment of this disclosure;
[0026] Figure 4 This is a schematic diagram of the overall implementation architecture of an embodiment of this disclosure;
[0027] Figure 5 This is a flowchart illustrating the information statistics method based on the Golang language according to an embodiment of this disclosure;
[0028] Figure 6 A structural block diagram of an information statistics device based on the Golang language provided in this disclosure embodiment;
[0029] Figure 7 A structural block diagram of another information statistics device based on the Golang language provided in this disclosure embodiment;
[0030] Figure 8 A structural block diagram of another information statistics device based on the Golang language provided in this disclosure embodiment;
[0031] Figure 9 This is a block diagram of an electronic device used to implement the information statistics method based on the Golang language in the embodiments of this disclosure. Detailed Implementation
[0032] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0033] In web backend application programming interface (API) services, it is typically necessary to monitor and aggregate statistics on API calls across various dimensions. Common technologies used in this context include general-purpose monitoring products such as ELK (an open-source log collection software) log analysis system, Promethus monitoring system, and Grafana (an open-source data visualization tool). However, the deployment, dimensioning, development, and testing of such monitoring products require specialized personnel and additional machine resources, increasing the overall system complexity.
[0034] Therefore, this disclosure provides an information statistics method, device, electronic device, and storage medium based on the Golang programming language. Developed using Golang, this disclosure does not rely on third-party monitoring products or services (such as ELK, Prometheus, etc.). It only requires the Golang standard library, and through custom coding, designs appropriate data structures and algorithms to quickly and efficiently implement simple traffic monitoring, aggregation statistics, and other functions under high concurrency. It should be noted that the Golang-based information statistics solution provided in this disclosure can be applied to gateway products or other customized projects where there are needs for simple monitoring, BI (Business Intelligence) reports, aggregation queries, dashboards, etc.
[0035] The following description, with reference to the accompanying drawings, outlines an information statistics method, apparatus, electronic device, and storage medium based on the Golang programming language, representing embodiments of this disclosure.
[0036] Figure 1 A flowchart illustrating an information statistics method based on the Golang language provided in this embodiment of the disclosure. Figure 1 As shown, the method may include, but is not limited to, the following steps.
[0037] In step 101, the full-link data of the network request is obtained, and based on the full-link data, the calculation dimension information and metric information of the application programming interface (API) service called by the network request are obtained.
[0038] Optionally, in embodiments of this disclosure, a collector can be created to acquire end-to-end data of network requests, and based on the end-to-end data, to acquire computational dimension information and metric information of the application programming interface (API) services called by the network requests.
[0039] In one possible implementation, network requests can be intercepted using a global middleware (such as an interceptor) of the API interface, and the intercepted network requests can be provided to the collector. The collector acquires the end-to-end data for each network request and performs classification and analysis on this end-to-end data to obtain the computational dimension information and metric information of the API service invoked by the network request.
[0040] In embodiments of this disclosure, the computational dimension information may include, but is not limited to, at least one of the following: interface path, name, date, caller, etc.
[0041] In embodiments of this disclosure, the metric information may include, but is not limited to, at least one of the following: number of calls, number of successes, number of failures, and time consumed.
[0042] In step 102, the calculation dimension information and metric information of the API service invoked by the network request are sent to the pipeline.
[0043] The channel is one of the most important structures in the Go language, a key feature that distinguishes it from other high-level languages, and an essential element for goroutine communication. A Go channel is an implementation of a circular queue (ringbuffer). A channel can be considered a management structure; it can hold objects of any type, which can be called elements.
[0044] In the embodiments of this disclosure, the computational dimension information and metric information of the API service invoked by the network request can be sent to the pipeline so that the data in the pipeline can be consumed subsequently to realize the data summary and statistics of API service invocation.
[0045] In step 103, a consumer coroutine is started, and at least one data object to be statistically analyzed is determined through the consumer coroutine and the global memory.
[0046] In this embodiment of the disclosure, the data type of the global memory can be a synchronous map type (sync.Map). The keys in the sync.Map data can indicate calculated dimension information, and the values in the sync.Map data can indicate metric information. The consumer coroutine iterates through the sync.Map data to consume it.
[0047] In one implementation, a global memory can be created. This global memory can be used to store summarized statistics of traffic dimensions and metrics. The data type of this global memory can be of type `sync.Map`, which is a concurrency-safe map, coroutine-safe, and maintains constant-time complexity for reading, inserting, and deleting. Using the `sync.Map` type can greatly reduce lock contention. Calculated dimension information and metric information are stored in the global memory's `sync.Map` in a key-value format. The keys and values of `sync.Map` are both `interface{}`, where the keys indicate calculated dimension information and the values indicate metric information.
[0048] In embodiments of this disclosure, a consumer coroutine (such as goroutine_a) can be started, and the consumer coroutine uses a for loop to traverse the data in the global memory sync.Map to determine the object to be statistically analyzed in each loop. In one possible implementation, the consumer coroutine can traverse the key-value data in the global memory sync.Map and identify at least one key encountered in sync.Map as the at least one object to be statistically analyzed. For example, all keys encountered in sync.Map can be identified as objects to be statistically analyzed.
[0049] For example, the consumer coroutine iterates through the data in the global memory `sync.Map` every time interval `t0` to determine the objects to be statistically analyzed at each iteration. For instance, if the data in the global memory `sync.Map` includes the call counts of API a and API b, iterating through the data in `sync.Map` can determine the call counts of API a and API b as the objects to be statistically analyzed.
[0050] In step 104, the consumer coroutine summarizes and statistically analyzes the computational dimension information and metric information in the pipeline based on at least one object to be statistically analyzed, and stores the summarized and statistically analyzed data in the global memory.
[0051] In the embodiments of this disclosure, an asynchronous consumer coroutine can be started for each data object to be statistically analyzed. Each asynchronous consumer coroutine summarizes and statistically analyzes the corresponding computational dimension information and metric information in the pipeline, and stores the summarized and statistically analyzed data in the global memory.
[0052] In the embodiments disclosed herein, communication between goroutines is achieved through a channel (chan). A producer-consumer model is employed to collect, classify, and statistically analyze network requests, storing the results in a global memory using a `sync.Map` type. The entire solution is developed using the Golang language, does not rely on third-party monitoring products or services, and only depends on the Golang standard library. Through custom coding and the design of appropriate data structures and algorithms, it can quickly and efficiently implement simple traffic monitoring and aggregation statistics under high concurrency conditions.
[0053] It is worth noting that by using the ideas and methods provided in this disclosure in the backend HTTP server code, it is possible to quickly, efficiently and stably implement the functions of monitoring and aggregating statistics of calls to the API interfaces exposed by the HTTP server without adding heavyweight third-party monitoring products, thereby achieving the goal of reducing costs and increasing efficiency.
[0054] Figure 2 A flowchart illustrating another information statistics method based on the Golang language provided in this embodiment of the disclosure. Figure 2 As shown, the method may include, but is not limited to, the following steps.
[0055] In step 201, the full-link data of the network request is obtained, and based on the full-link data, the calculation dimension information and metric information of the application programming interface (API) service called by the network request are obtained.
[0056] In the embodiments of this disclosure, step 201 can be implemented in any of the embodiments of this disclosure, and no limitation is made here, nor will it be described in detail.
[0057] In step 202, the calculation dimension information and metric information of the API service invoked by the network request are sent to the pipeline.
[0058] In the embodiments of this disclosure, step 202 can be implemented in any of the embodiments of this disclosure, and no limitation is made here, nor will it be described in detail.
[0059] In step 203, a consumer coroutine is started, and at least one object to be statistically analyzed is determined through the consumer coroutine and the global memory.
[0060] In the embodiments of this disclosure, the data type of the global memory adopts the sync.Map type. The keys in the sync.Map type data indicate the calculation dimension information, the values in the sync.Map type data indicate the metric information, and the consumer coroutine traverses the sync.Map type data in a loop to consume it.
[0061] In the embodiments of this disclosure, step 203 can be implemented in any of the embodiments of this disclosure, and no limitation is made here, nor will it be described in detail.
[0062] In step 204, an asynchronous consumer coroutine is started for each data object to be statistically analyzed using consumer coroutines.
[0063] In one implementation, each data object to be analyzed corresponds to a key-value pair in a `sync.Map` type data structure. An asynchronous consumption coroutine (such as `goroutine_b`) is started for each key-value pair to asynchronously consume data from the pipeline (chan). For example, assuming there are 5 data objects to be analyzed, 5 asynchronous consumption coroutines are started through this consumer coroutine, each corresponding to one data object, so that the corresponding data objects can be aggregated and analyzed later using these asynchronous consumption coroutines.
[0064] In step 205, the state machine variables and summary data object for each asynchronous consumer coroutine are initialized.
[0065] Optionally, before consuming the data in the pipeline through each asynchronous consumption coroutine to complete the summary statistics of dimensional information and metric information, each asynchronous consumption coroutine needs to be initialized, such as initializing the state machine variables and summary data objects of each asynchronous consumption coroutine.
[0066] The state machine variable indicates whether the asynchronous consumption coroutine stops consuming data from the pipeline channel. In one possible implementation, the state machine variable of each asynchronous consumption coroutine can be assigned the value of a second variable. For example, setting the state machine variable `stop = false` indicates that the asynchronous consumption coroutine does not stop consuming (i.e., continues consuming data from the pipeline), thus completing the initialization of the state machine variable for that asynchronous consumption coroutine. The value of the summary data object for each asynchronous consumption coroutine can be initialized based on the data in the global memory `sync.Map`. For instance, if the value of the data object corresponding to the asynchronous consumption coroutine in `sync.Map` is 10, then the initialization data of the summary data object for that asynchronous consumption coroutine is 10. Similarly, if the value of the data object corresponding to the asynchronous consumption coroutine in `sync.Map` is 0, then the initialization data of the summary data object for that asynchronous consumption coroutine is 0, thus completing the initialization of the summary data object for that asynchronous consumption coroutine.
[0067] In step 206, the corresponding computational dimension information and metric information are read from the pipeline in a loop through each asynchronous consumption coroutine and the state machine variable of each asynchronous consumption coroutine. The read corresponding computational dimension information and metric information are summarized and statistically analyzed until the state machine variable of each asynchronous consumption coroutine becomes the first variable, at which point the summary and statistics end.
[0068] In the embodiments of this disclosure, for each asynchronous consumer coroutine, the state machine variables of the asynchronous consumer coroutine can be used to read chan data in a for loop, and the read data can be summarized and statistically analyzed until the state machine variables of the asynchronous consumer coroutine are the first variables, at which point the summary and statistics end.
[0069] In step 207, the summarized statistics are stored in the global memory.
[0070] In embodiments of this disclosure, the summarized and statistically analyzed data can be stored in the global memory in a key-value (KV) format.
[0071] Optionally, in some embodiments of this disclosure, such as Figure 3 As shown, step 206 may include, but is not limited to, the following steps.
[0072] In step 2061, for each asynchronous consumer coroutine, the corresponding state machine variables are determined through the asynchronous consumer coroutine.
[0073] In step 2062, when the corresponding state machine variable is the second variable, the corresponding calculation dimension information and metric information are read from the pipeline.
[0074] In step 2063, when the corresponding computational dimension information and metric information are read from the pipeline, the read corresponding computational dimension information and metric information are summarized and statistically analyzed, and the step of determining the corresponding state machine variables through asynchronous consumption coroutine is returned to execute, that is, the step of returning to execute step 2061 is executed.
[0075] In step 2064, if the corresponding computational dimension information and metric information are not read from the pipeline, a waiting time is set, and the corresponding computational dimension information and metric information are read from the pipeline within the waiting time. The read corresponding computational dimension information and metric information are summarized and statistically analyzed, and the step of determining the corresponding state machine variables through asynchronous consumption coroutine is returned to be executed, that is, the execution of step 2061 is returned.
[0076] In step 2065, if the corresponding computational dimension information and metric information cannot be read from the pipeline within the waiting time, the state machine variable of the asynchronous consumption coroutine is changed to the first variable, and the next for loop continues, returning to step 2061, until the summary statistics end when the state machine variable of each asynchronous consumption coroutine is the first variable.
[0077] Optionally, in embodiments of this disclosure, a consumption timer can be set via an asynchronous consumption coroutine. When the consumption timer reaches a consumption time threshold, the state machine variable of the asynchronous consumption coroutine is changed to the first variable. In one possible implementation, a timer (or timer function) can be used to set a time window (t1). The asynchronous consumption coroutine can only read and summarize data in the pipeline during the time window period. After the time window closes, the asynchronous consumption coroutine stops reading and stores the summarized data in the database.
[0078] Optionally, in some embodiments of this disclosure, after storing the aggregated statistical data in a global storage device, the sync.Map type data in the global storage device can be persisted to a database. This database can be a MySQL database. In one implementation, in response to an HTTP (Hypertext Transfer Protocol) query request, the database can be queried for sync.Map type data corresponding to the query request, and the retrieved sync.Map type data can be provided to a front-end webpage and / or application. For example, the front-end webpage can display the retrieved data; the application can use the retrieved data for downstream tasks, etc. Thus, this disclosure allows querying pre-statistical table data in a database table via an HTTP server API interface and providing it to a front-end webpage or app.
[0079] To facilitate a clearer understanding of this disclosure by those skilled in the art, the following will be combined with... Figure 4 and Figure 5 This disclosure is described in detail.
[0080] For example, such as Figure 4 and Figure 5 As shown, this disclosure allows the creation of a global storage. The data type is sync.Map (coroutine-safe), which uses a key-value pair to store data. The key indicates the calculated dimension information, and the value indicates the metric information. Both the key and value of this sync.Map are interface{}, used to store traffic dimensions and metrics.
[0081] like Figure 4 and Figure 5 As shown, this disclosure allows for the creation of a metrics collector. Within the global middleware of the API service (such as an interceptor), the entire request's data is acquired, categorized, and statistical dimensions and metrics are constructed based on the categorization results. The metric information is then sent to the channel pipeline and stored in a key-value (KV) manner in the global storage `sync.Map`.
[0082] like Figure 4 and Figure 5 As shown, a consumer goroutine (goroutine_a) is started. Every t0 time interval, the data in the global memory sync.Map is traversed, and for each key-value pair, an asynchronous consumer goroutine (goroutine_b) is started to asynchronously consume the data in chan.
[0083] In this embodiment, each goroutine_b first initializes its state machine and summary data object. For example, the state machine variable (used to indicate whether goroutine_b stops consuming data from the channel) `stop` is set to `false`; the summary data object is initialized. Then, goroutine_b starts the consumption time control goroutine (referred to as goroutine_c). goroutine_c sets a timer `t1` (used to indicate the consumption time window). If timer `t1` expires, the state machine variable `stop` of goroutine_b is changed to `true`.
[0084] If the timer t1 has not expired, goroutine_b continues its infinite for loop, reading and summarizing data from the chan pipe. For example, goroutine_b first checks the state of its state machine, stop. If it is true (as in the first variable above), it stores the summarized data in global memory, interrupts the loop, and ends the current consumption. If it is false (as in the second variable above), goroutine_b attempts to read data from the chan pipe using a select-case pattern. If it can read a piece of data, it summarizes and calculates the data, continuing to the next for loop. If there is no data in the chan pipe, goroutine_b sets a waiting time t2. If the chan pipe remains empty (no new data arrives) during t2, goroutine_b sets its state machine variable stop = true and continues to the next for loop; otherwise, it reads a new piece of data, summarizes and calculates it, and continues to the next for loop.
[0085] It is worth noting that the core logic of the consumer in this disclosure is to read data from the chan pipeline, summarize and calculate it, store it in the global storage, and then input it into the database. If the chan is read continuously or blocked indefinitely (e.g., the goroutine will block when the chan is empty), the summarized data will not be stored in the database in a timely manner. Therefore, a timer is used to set a time window (t1). Data in the chan pipeline can only be read and summarized within the time window. After the time window closes, reading stops, and the summarized data is input into the database. If there is no data in the chan pipeline during the time window, the goroutine will be blocked indefinitely. To solve this problem, this disclosure uses the chan's select timeout mechanism. That is, if no data is retrieved from the chan pipeline within a certain period (t2), the select statement will exit instead of blocking indefinitely on reading from the chan pipeline. In this way, the summarized data can be written to the database in batches with a small delay (t0+t1 or t0+t2), which can meet the timeliness of monitoring statistics and effectively reduce the pressure on the database.
[0086] Optionally, in some embodiments of this disclosure, if an external abnormal signal is received causing the program to restart or stop, the reception of upstream data can be stopped first, and the remaining data in the channel can continue to be aggregated. After the remaining data in the channel is processed and written to the database, the program can be restarted or stopped. This avoids the situation where the aggregated data in memory is not written to the database in a timely manner when the program stops. This disclosure can use Golang's graceful shutdown technology to ensure that all indicator data in the memory channel can be aggregated and written to the database when the program restarts or stops, ensuring the accuracy of the statistical results.
[0087] In summary, this disclosure utilizes the basic syntax of Golang and employs well-designed data structures and algorithms to lightweightly and quickly implement traffic monitoring and aggregation statistics in high-concurrency scenarios. Compared to related solutions, this disclosure achieves high-concurrency traffic monitoring and aggregation statistics without relying on third-party components, increasing system complexity, or adding deployment and maintenance costs for third-party services. This disclosure enables web services, especially gateway-type products, to achieve fast, accurate, secure, and stable monitoring and statistics of request traffic, improving product competitiveness and stability while reducing costs and increasing efficiency.
[0088] Figure 6 This is a structural block diagram of an information statistics device based on the Golang language, provided as an embodiment of this disclosure. Figure 6 As shown, the information statistics device may include: an acquisition module 601, a sending module 602, a determination module 603, and a statistics module 604.
[0089] The acquisition module 601 is used to acquire the full-link data of the network request, and based on the full-link data, acquire the calculation dimension information and metric information of the application programming interface (API) service called by the network request.
[0090] The sending module 602 is used to send the calculation dimension information and metric information of the API service called by the network request to the pipeline.
[0091] The determination module 603 is used to start the consumer coroutine and determine at least one object to be statistically analyzed through the consumer coroutine and the global memory. The data type of the global memory adopts the sync.Map type. The keys in the sync.Map type data indicate the calculated dimension information, and the values in the sync.Map type data indicate the metric information. The consumer coroutine circumvents the sync.Map type data in a loop to consume it.
[0092] In one implementation, the determining module 603 traverses the key-value data in the global memory's sync.Map through a consumer coroutine, and determines at least one key encountered in the sync.Map as the at least one data object to be statistically analyzed.
[0093] The statistics module 604 is used to summarize and statistically analyze the computational dimension information and metric information in the pipeline based on at least one object to be statistically analyzed by a consumer coroutine, and then store the summarized and statistically analyzed data in the global memory.
[0094] In one implementation, the statistics module 604 is specifically used to: start an asynchronous consumption coroutine for each data object to be analyzed through a consumer coroutine; initialize the state machine variables and summary data object of each asynchronous consumption coroutine; and, through each asynchronous consumption coroutine and its state machine variables, cyclically read the corresponding computational dimension information and metric information from the pipeline, and perform summary statistics on the read corresponding computational dimension information and metric information until the state machine variable of each asynchronous consumption coroutine becomes the first variable, at which point the summary statistics end.
[0095] In one possible implementation, the statistics module 604 is specifically used for: determining the corresponding state machine variable for each asynchronous consumption coroutine; if the corresponding state machine variable is the second variable, reading the corresponding computational dimension information and metric information from the pipeline; when the corresponding computational dimension information and metric information are read from the pipeline, summarizing and statistically analyzing the read information, and returning to execute the step of determining the corresponding state machine variable through the asynchronous consumption coroutine; if the corresponding computational dimension information and metric information are not read from the pipeline, setting a waiting time, and when the corresponding computational dimension information and metric information are read from the pipeline within the waiting time, summarizing and statistically analyzing the read information, and returning to execute the step of determining the corresponding state machine variable through the asynchronous consumption coroutine; if the corresponding computational dimension information and metric information are not read from the pipeline within the waiting time, changing the state machine variable of the asynchronous consumption coroutine to the first variable; and ending the summary statistics when the state machine variable of each asynchronous consumption coroutine is the first variable.
[0096] In one implementation, the statistics module 604 is also used to: set a consumption timer through an asynchronous consumption coroutine; and when the consumption timer reaches the consumption time threshold, change the state machine variable of the asynchronous consumption coroutine to the first variable.
[0097] Optionally, in some embodiments of this disclosure, such as Figure 7As shown, the device may further include a data persistence module 705. This data persistence module 705 is used to persist the sync.Map type data in the global storage to the database after storing the summarized and statistical data in the global storage. Figure 7 701-704 and Figure 6 The 601-604 series have the same function and structure.
[0098] Optionally, in some embodiments of this disclosure, such as Figure 8 As shown, the device may further include a query module 806 and a feedback module 807. The query module 806 is used to query data of type sync.Map corresponding to the query request from the database in response to a Hypertext Transfer Protocol (HTTP) query request; the feedback module 807 is used to provide the retrieved sync.Map data to the front-end web page and / or application. Figure 8 801-805 and Figure 7 The Chinese 701-705 have the same function and structure.
[0099] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0100] According to embodiments of this disclosure, this disclosure also provides an electronic device and a readable storage medium.
[0101] like Figure 9 The diagram shown is a block diagram of an electronic device for implementing the information statistics method based on the Golang language according to embodiments of this disclosure. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the disclosure described and / or claimed herein.
[0102] like Figure 9As shown, the electronic device includes one or more processors 901, a memory 902, and interfaces for connecting the components, including high-speed interfaces and low-speed interfaces. The components are interconnected via different buses and can be mounted on a common motherboard or otherwise as required. The processors can process instructions executed within the electronic device, including instructions stored in or on memory to display graphical information of a GUI on an external input / output device (such as a display device coupled to the interface). In other embodiments, multiple processors and / or multiple buses can be used with multiple memories and multiple memory modules, if desired. Similarly, multiple electronic devices can be connected, each providing some of the necessary operations (e.g., as a server array, a group of blade servers, or a multiprocessor system). Figure 9 Take the 901 processor as an example.
[0103] The memory 902 is the non-transitory computer-readable storage medium provided in this disclosure. The memory stores instructions executable by at least one processor to cause the at least one processor to perform the information statistics method based on the Golang language provided in this disclosure. The non-transitory computer-readable storage medium of this disclosure stores computer instructions for causing a computer to perform the information statistics method based on the Golang language provided in this disclosure.
[0104] The memory 902, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs, non-transitory computer-executable programs, and modules, such as the program instructions / modules corresponding to the information statistics method based on the Golang language in the embodiments of this disclosure. The processor 901 executes various functional applications and data processing of the server by running the non-transitory software programs, instructions, and modules stored in the memory 902, thereby implementing the information statistics method based on the Golang language in the above method embodiments.
[0105] The memory 902 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created based on the use of the electronic device. Furthermore, the memory 902 may include high-speed random access memory and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, the memory 902 may optionally include memory remotely located relative to the processor 901, and these remote memories can be connected to the electronic device via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0106] The electronic device may also include an input device 903 and an output device 904. The processor 901, memory 902, input device 903, and output device 904 can be connected via a bus or other means. Figure 9 Taking the example of a connection between China and Israel via a bus.
[0107] Input device 903 can receive input numerical or character information, and generate key signal inputs related to user settings and function control of the electronic device, such as touch screens, keypads, mice, trackpads, touchpads, joysticks, one or more mouse buttons, trackballs, joysticks, etc. Output device 904 may include display devices, auxiliary lighting devices (e.g., LEDs), and haptic feedback devices (e.g., vibration motors). The display device may include, but is not limited to, liquid crystal displays (LCDs), light-emitting diode (LED) displays, and plasma displays. In some embodiments, the display device may be a touch screen.
[0108] Various implementations of the systems and techniques described herein can be implemented in digital electronic circuit systems, integrated circuit systems, application-specific integrated circuits (ASICs), computer hardware, firmware, software, and / or combinations thereof. These various implementations may include: implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transferring data and instructions to the storage system, the at least one input device, and the at least one output device.
[0109] These computational programs (also referred to as programs, software, software applications, or code) include machine instructions for a programmable processor and can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. As used herein, the terms “machine-readable medium” and “computer-readable medium” refer to any computer program product, device, and / or apparatus (e.g., disk, optical disk, memory, programmable logic device (PLD)) used to provide machine instructions and / or data to a programmable processor, including machine-readable media that receive machine instructions as machine-readable signals. The term “machine-readable signal” refers to any signal used to provide machine instructions and / or data to a programmable processor.
[0110] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0111] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), the Internet, and blockchain networks.
[0112] Computer systems can include clients and servers. Clients and servers are generally geographically separated and typically interact via communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. A server can be a cloud server, also known as a cloud computing server or cloud host, a hosting product within the cloud computing service ecosystem, addressing the shortcomings of traditional physical hosts and VPS (Virtual Private Server, or simply "VPS") services, such as high management difficulty and weak business scalability. Servers can also be servers for distributed systems or servers incorporating blockchain technology.
[0113] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.
[0114] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.
Claims
1. An information statistics method based on the Golang programming language, comprising: Obtain the full-link data of the network request, and based on the full-link data, obtain the calculation dimension information and metric information of the application programming interface (API) service called by the network request; The computational dimension information and metric information of the API service invoked by the network request are sent to the pipeline; A consumer coroutine is started, and at least one data object to be statistically analyzed is determined through the consumer coroutine and the global memory; wherein, the data type of the global memory adopts the sync.Map type, the keys in the sync.Map type data indicate the calculated dimension information, the values in the sync.Map type data indicate the metric information, and the consumer coroutine iterates through the sync.Map type data to consume it. The process of summarizing and statistically analyzing computational dimension information and metric information in the pipeline based on at least one data object to be analyzed, through the consumer coroutine, includes: starting an asynchronous consumer coroutine for each data object to be analyzed; initializing the state machine variables and summary data object of each asynchronous consumer coroutine; and cyclically reading the corresponding computational dimension information and metric information from the pipeline through each asynchronous consumer coroutine and its state machine variables, and summarizing and statistically analyzing the read computational dimension information and metric information until the state machine variable of each asynchronous consumer coroutine is the first variable, at which point the summarization and statistical analysis ends. The aggregated and statistically analyzed data is stored in the global memory.
2. The method as described in claim 1, wherein, The step of determining at least one object to be statistically analyzed through the consumer coroutine and global memory includes: The consumer coroutine traverses the key-value data in the sync.Map of the global memory and identifies at least one key encountered in the sync.Map as the at least one data object to be analyzed.
3. The method as described in claim 1, wherein, The process involves iteratively reading corresponding computational dimension information and metric information from the pipeline using each asynchronous consumption coroutine and its state machine variables, and summarizing and statistically analyzing the read computational dimension information and metric information until the state machine variable of each asynchronous consumption coroutine reaches the first variable, thus ending the summary and statistical analysis. For each of the asynchronous consumption coroutines, the corresponding state machine variables are determined through the asynchronous consumption coroutine; When the corresponding state machine variable is the second variable, the corresponding computational dimension information and metric information are read from the pipeline; When the corresponding computational dimension information and metric information are read from the pipeline, the read corresponding computational dimension information and metric information are summarized and statistically analyzed, and the step of determining the corresponding state machine variables through the asynchronous consumption coroutine is returned to be executed. If the corresponding computational dimension information and metric information are not read from the pipeline, a waiting time is set, and the corresponding computational dimension information and metric information are read from the pipeline within the waiting time. The read corresponding computational dimension information and metric information are summarized and statistically analyzed, and the step of determining the corresponding state machine variables through the asynchronous consumption coroutine is returned to be executed. If the corresponding computational dimension information and metric information cannot be read from the pipeline within the waiting time, the state machine variable of the asynchronous consumption coroutine will be changed to the first variable; The summary statistics will end when the state machine variable of each asynchronous consumer coroutine is the first variable.
4. The method of claim 3, further comprising: Set the consumption timer through the asynchronous consumption coroutine; When the consumption timer reaches the consumption time threshold, the state machine variable of the asynchronous consumption coroutine is changed to the first variable.
5. The method according to any one of claims 1 to 4, further comprising: After storing the aggregated and statistical data in the global storage, the sync.Map type data in the global storage is persisted to the database.
6. The method of claim 5, further comprising: In response to an HTTP query request, retrieve data of type sync.Map from the database corresponding to the query request; Provide the retrieved sync.Map type data to the front-end web page and / or application.
7. An information statistics device based on the programming language Golang, comprising: The acquisition module is used to acquire the full-link data of the network request, and based on the full-link data, acquire the calculation dimension information and metric information of the application programming interface (API) service called by the network request. The sending module is used to send the calculation dimension information and metric information of the API service invoked by the network request to the pipeline; A determination module is used to initiate a consumer coroutine and, through the consumer coroutine and a global memory, determine at least one object to be statistically analyzed; wherein, the data type of the global memory adopts a sync.Map type, the keys in the sync.Map type data indicate the calculated dimension information, the values in the sync.Map type data indicate the metric information, and the consumer coroutine iterates through the sync.Map type data to consume it; The statistics module is used to summarize and statistically analyze the computational dimension information and metric information in the pipeline based on at least one data object to be analyzed, through the consumer coroutine, and store the summarized and statistically analyzed data in the global memory; specifically, the statistics module is used to: start an asynchronous consumer coroutine for each data object to be analyzed through the consumer coroutine; initialize the state machine variables and summary data object of each asynchronous consumer coroutine; and cyclically read the corresponding computational dimension information and metric information from the pipeline through each asynchronous consumer coroutine and its state machine variables, and summarize and statistically analyze the read corresponding computational dimension information and metric information until the state machine variable of each asynchronous consumer coroutine is the first variable, at which point the summary and statistical analysis ends.
8. The apparatus of claim 7, wherein, The determining module is specifically used for: The consumer coroutine traverses the key-value data in the sync.Map of the global memory and identifies at least one key encountered in the sync.Map as the at least one data object to be analyzed.
9. The apparatus of claim 7, wherein, The statistics module is specifically used for: For each of the asynchronous consumption coroutines, the corresponding state machine variables are determined through the asynchronous consumption coroutine; When the corresponding state machine variable is the second variable, the corresponding computational dimension information and metric information are read from the pipeline; When the corresponding computational dimension information and metric information are read from the pipeline, the read corresponding computational dimension information and metric information are summarized and statistically analyzed, and the step of determining the corresponding state machine variables through the asynchronous consumption coroutine is returned to be executed. If the corresponding computational dimension information and metric information are not read from the pipeline, a waiting time is set, and the corresponding computational dimension information and metric information are read from the pipeline within the waiting time. The read corresponding computational dimension information and metric information are summarized and statistically analyzed, and the step of determining the corresponding state machine variables through the asynchronous consumption coroutine is returned to be executed. If the corresponding computational dimension information and metric information cannot be read from the pipeline within the waiting time, the state machine variable of the asynchronous consumption coroutine will be changed to the first variable; The summary statistics will end when the state machine variable of each asynchronous consumer coroutine is the first variable.
10. The apparatus of claim 9, wherein, The statistics module is also used for: Set the consumption timer through the asynchronous consumption coroutine; When the consumption timer reaches the consumption time threshold, the state machine variable of the asynchronous consumption coroutine is changed to the first variable.
11. The apparatus of any one of claims 7 to 10, further comprising: The data persistence module is used to persist the sync.Map type data in the global storage to the database after storing the summarized and statistical data in the global storage.
12. The apparatus of claim 11, further comprising: The query module is used to respond to a Hypertext Transfer Protocol (HTTP) query request and retrieve data of type sync.Map from the database corresponding to the query request. The feedback module is used to provide the retrieved sync.Map type data to the front-end web page and / or application.
13. An electronic device, comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1 to 6.
14. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method according to any one of claims 1 to 6.
15. A computer program product comprising a computer program, wherein, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Method, system and device for developing game system based on Golang development framework and medium
CN114153625A
System for aggregating statistics associated with interfaces
US20160191361A1
