Method, device, computing equipment and medium for writing to database

By obtaining and dividing user data in the server system, writing to the database synchronously or asynchronously, and monitoring the writing speed under high concurrency conditions, the problem of existing system crashes is solved and the stability of the system under high concurrency conditions is achieved. run.

CN113553372BActive Publication Date: 2024-10-18BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010341339.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-04-26
Publication Date
2024-10-18
Estimated Expiration
2040-04-26

AI Technical Summary

Technical Problem

Existing server systems are prone to crashing when processing highly concurrent data and cannot perform normal write operations to the database. Existing solutions such as updating the system are time-consuming and laborious.

Method used

By obtaining user data within a preset time window, the amount of data is determined and divided into first data and second data, and is written to the database in a synchronous or asynchronous manner. The asynchronous data is cached after a preset delay and the writing speed is monitored. If the threshold is exceeded, Sleep threads to adjust speed.

Benefits of technology

It realizes automatic switching of writing methods according to the amount of data, avoids excessive pressure on the database, and ensures that the system can run normally under high concurrency conditions without rewriting the original system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113553372B_ABST
    Figure CN113553372B_ABST
Patent Text Reader

Abstract

The present disclosure provides a method for writing to a database, comprising: obtaining user data generated within a preset time window; determining the data volume of the user data; determining first data and / or second data from the user data according to the determined data volume; and performing a preset write operation on the database for the first data and / or the second data, wherein the preset write operation includes: writing the first data to the database in a synchronous manner; and / or writing the second data to the database in an asynchronous manner. The present disclosure also provides a writing device, a computing device, and a medium for a database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and more specifically, to a method, apparatus, computing device and medium for writing into a database. Background Art

[0002] Existing server systems are designed with a flow limit. When the flow limit is exceeded, the database write operation cannot be performed normally. For example, for a system with a designed flow limit of 100,000 transactions per second, when it needs to process concurrent data of 5 million transactions per second, the system will crash and the database write operation cannot be performed normally.

[0003] The related technology adopts a method of rewriting a new version system that can adapt to higher traffic and updating the old version of the server system to the new version system to solve the above problem, but this method is time-consuming and labor-intensive. Summary of the invention

[0004] In view of this, the present disclosure provides a method, apparatus, computing device and medium for writing to a database.

[0005] One aspect of the present disclosure provides a method for writing to a database, comprising: acquiring user data generated within a preset time window; determining the amount of user data; determining first data and / or second data from the user data based on the determined amount of data; and performing a preset write operation on the database for the first data and / or the second data, wherein the preset write operation comprises: writing the first data to the database in a synchronous manner; and / or writing the second data to the database in an asynchronous manner.

[0006] According to an embodiment of the present disclosure, first data and / or second data are determined from user data based on a determined data amount, including at least one of the following: when the determined data amount is less than or equal to a first threshold, all user data is taken as first data; when the determined data amount is greater than the first threshold and less than or equal to a second threshold, the user data is divided into first data and second data according to a preset ratio; and when the determined data amount is greater than the second threshold, all user data is taken as second data.

[0007] According to an embodiment of the present disclosure, writing the first data into the database in a synchronous manner includes: after obtaining the first data from the user data, directly writing the first data into the database.

[0008] According to an embodiment of the present disclosure, the second data is written to the database in an asynchronous manner, including: after obtaining the second data from the user data, the second data is first cached in a message queue, and after a preset delay time, the second data cached in the message queue is written to the database.

[0009] According to an embodiment of the present disclosure, the above method also includes: in the process of writing the second data cached in the message queue into the database, determining the data writing speed of writing the second data into the database; and when the data writing speed exceeds the speed threshold, configuring at least one write thread corresponding to the preset write operation to a sleep state.

[0010] Another aspect of the present disclosure provides a writing device for a database, comprising: an acquisition module, used to acquire user data generated within a preset time window; a data amount determination module, used to determine the data amount of the user data; a data judgment module, used to determine first data and / or second data from the user data according to the determined data amount; and a writing module, used to perform a preset write operation on the database for the first data and / or the second data, wherein the writing module comprises: a synchronous writing submodule, used to write the first data to the database in a synchronous manner; and / or an asynchronous writing submodule, used to write the second data to the database in an asynchronous manner.

[0011] According to an embodiment of the present disclosure, the data judgment module includes at least one of the following: a first determination submodule, used to treat all user data as first data when the determined data amount is less than or equal to a first threshold; a second determination submodule, used to divide the user data into first data and second data according to a preset ratio when the determined data amount is greater than the first threshold and less than or equal to a second threshold; and a third determination submodule, used to treat all user data as second data when the determined data amount is greater than the second threshold.

[0012] According to an embodiment of the present disclosure, the synchronous writing submodule is specifically used to: after obtaining the first data from the user data, directly write the first data into the database.

[0013] According to an embodiment of the present disclosure, the asynchronous writing submodule is specifically used to: after obtaining the second data from the user data, first cache the second data in the message queue, and then write the second data cached in the message queue into the database after a preset delay time.

[0014] According to an embodiment of the present disclosure, the above-mentioned device, during the process of writing the second data cached in the message queue into the database, further includes: a write speed determination module, used to determine the data writing speed of writing the second data into the database; and a sleep module, used to configure at least one write thread corresponding to a preset write operation to a sleep state when the data writing speed exceeds a speed threshold.

[0015] Another aspect of the present disclosure provides a computing device, including: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method as described above.

[0016] Another aspect of the present disclosure provides a computer-readable storage medium storing computer-executable instructions, which are used to implement the above method when executed.

[0017] Another aspect of the present disclosure provides a computer program, which includes computer executable instructions, and the instructions are used to implement the method described above when executed.

[0018] According to an embodiment of the present disclosure, by monitoring the data volume of user data, determining first data and / or second data from the user data according to the data volume of the user data, writing the first data to the database in a synchronous manner, and / or writing the second data to the database in an asynchronous manner, when writing user data to the database, it is achieved that the corresponding writing mode is automatically switched according to the data volume, so that the system can still operate normally when the writing data volume is large without rewriting the original system. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The above and other objects, features and advantages of the present disclosure will become more apparent through the following description of the embodiments of the present disclosure with reference to the accompanying drawings, in which:

[0020] Figure 1 An exemplary system architecture to which a method and apparatus for writing to a database according to an embodiment of the present disclosure can be applied is schematically shown;

[0021] Figure 2A A flowchart of a method for writing to a database according to an embodiment of the present disclosure is schematically shown;

[0022] Figure 2B A flowchart of determining first data and / or second data from user data according to a determined data amount according to an embodiment of the present disclosure is schematically shown;

[0023] Figure 2C A flowchart of a method for writing to a database according to another embodiment of the present disclosure is schematically shown;

[0024] Figure 3 A flowchart of a method for writing into a database according to an embodiment of the present disclosure is schematically shown;

[0025] Figure 4A A block diagram of a writing device for a database according to an embodiment of the present disclosure is schematically shown;

[0026] Figure 4B The block diagram of the data judgment module according to the embodiment of the present disclosure is schematically shown;

[0027] Figure 5 A block diagram schematically shows a device for writing to a database according to another embodiment of the present disclosure; and

[0028] Figure 6 A block diagram of a computer system suitable for implementing the above-described method for writing to a database according to an embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION

[0029] Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present disclosure. In the following detailed description, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of the embodiments of the present disclosure. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessary confusion of the concepts of the present disclosure.

[0030] The terms used herein are only for describing specific embodiments and are not intended to limit the present disclosure. The terms "comprise", "include", etc. used herein indicate the existence of the features, steps, operations and / or components, but do not exclude the existence or addition of one or more other features, steps, operations or components.

[0031] All terms (including technical and scientific terms) used herein have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification, and should not be interpreted in an idealized or overly rigid manner.

[0032] In the case of using expressions such as "at least one of A, B, and C, etc.", it should generally be interpreted in accordance with the meaning of the expression generally understood by those skilled in the art (for example, "a system having at least one of A, B, and C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.). In the case of using expressions such as "at least one of A, B, or C, etc.", it should generally be interpreted in accordance with the meaning of the expression generally understood by those skilled in the art (for example, "a system having at least one of A, B, or C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.).

[0033] The embodiments of the present disclosure provide a method for writing to a database and a device capable of applying the method. The method includes acquiring user data generated within a preset time window; determining the amount of user data; determining first data and / or second data from the user data according to the determined amount of data; and performing a preset write operation on the database for the first data and / or the second data, wherein the preset write operation includes: writing the first data to the database in a synchronous manner; and / or writing the second data to the database in an asynchronous manner.

[0034] Figure 1 The exemplary system architecture 100 to which the method and apparatus for writing to a database according to an embodiment of the present disclosure can be applied is schematically shown. It should be noted that: Figure 1 What is shown is merely an example of a system architecture to which the embodiments of the present disclosure can be applied, in order to help those skilled in the art understand the technical content of the present disclosure, but it does not mean that the embodiments of the present disclosure cannot be used in other devices, systems, environments or scenarios.

[0035] like Figure 1 As shown, the system architecture 100 according to this embodiment may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0036] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).

[0037] The terminal devices 101 , 102 , and 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.

[0038] The server 105 may be a server that provides various services, such as a background management server (only as an example) that provides support for websites browsed by users using the terminal devices 101, 102, and 103. A database is provided in the background management server. The background management server may store the received user request and other data in the database, and then perform processing such as analysis on the data, and feed back the processing results (such as web pages, information, or data obtained or generated according to the user request, etc.) to the terminal device.

[0039] It should be noted that the writing method for the database provided in the embodiment of the present disclosure can generally be executed by the server 105. Accordingly, the writing device for the database provided in the embodiment of the present disclosure can generally be set in the server 105. The writing method for the database provided in the embodiment of the present disclosure can also be executed by a server or server cluster that is different from the server 105 and can communicate with the terminal devices 101, 102, 103 and / or the server 105. Correspondingly, the writing device for the database provided in the embodiment of the present disclosure can also be set in a server or server cluster that is different from the server 105 and can communicate with the terminal devices 101, 102, 103 and / or the server 105.

[0040] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to the implementation requirements.

[0041] Figure 2A The flowchart of the method for writing into a database according to an embodiment of the present disclosure is schematically shown.

[0042] like Figure 2A As shown, the method includes operations S210 to S240.

[0043] More specifically, in operation S210, user data generated within a preset time window is acquired.

[0044] According to the embodiments of the present disclosure, the size of the preset time window can be set according to actual needs. For example, the size of the preset time window can be set to 1 second. It should be noted that the present application does not make specific restrictions on the size of the preset time window. In the process of actual application, the size of the preset time window can be set arbitrarily.

[0045] According to an embodiment of the present disclosure, user data may be a request sent by a user through a terminal device, including, for example, a request to obtain data from a server, a request to submit data to a server for processing, and the like.

[0046] Then, in operation S220, the data amount of the user data is determined.

[0047] According to an embodiment of the present disclosure, the amount of user data can be determined by presetting a sliding window traffic counter. For example, the amount of user data can be characterized by parameters such as query per second (QPS) or throughput (TPS).

[0048] In operation S230, first data and / or second data are determined from the user data according to the determined data amount.

[0049] Figure 2B The flowchart of determining first data and / or second data from user data according to the determined data amount according to an embodiment of the present disclosure is schematically shown.

[0050] like Figure 2B As shown, operation S230 may include operations S231 to S233. More specifically, when the determined data amount is less than or equal to the first threshold, operation S231 is performed. When the determined data amount is greater than the second threshold, operation S232 is performed. When the determined data amount is greater than the first threshold and less than or equal to the second threshold, operation S233 is performed.

[0051] In operation S231, all user data is taken as first data.

[0052] In operation S232, all the user data is used as the second data.

[0053] In operation S233, the user data is divided into first data and second data at a preset ratio.

[0054] According to an embodiment of the present disclosure, the preset ratio can be pre-configured, for example, the preset ratio is configured as 1:1, that is, 50% of the user data is divided into the first data, and the other 50% of the user data is divided into the second data. It should be noted that for the configuration of the preset ratio, a fixed configuration method can be adopted so that it always maintains a certain specific ratio during a specific application process, and a dynamic configuration method can be adopted so that it can be changed accordingly as needed during a specific application process.

[0055] In operation S240 , a preset write operation is performed on the database with respect to the first data and / or the second data.

[0056] The preset write operation includes: writing the first data into the database in a synchronous manner; and / or writing the second data into the database in an asynchronous manner.

[0057] According to an embodiment of the present disclosure, if the user data includes first data, the first data in the user data is written into the database in a synchronous manner. If the user data includes second data, the second data in the user data is written into the database in an asynchronous manner.

[0058] Wherein, writing the first data in the user data into the database in a synchronous manner may include, for example, directly writing the first data into the database after obtaining the first data from the user data. Through this synchronous manner, each unit data in the first data can be synchronously written into the database, and the writing speed is faster.

[0059] In addition, writing the second data in the user data to the database in an asynchronous manner may include, for example, first caching the second data in a message queue after obtaining the second data from the user data, and then writing the second data cached in the message queue to the database after a preset delay time. Through this asynchronous manner, each unit data in the second data can be written to the database in batches to reduce the amount of data written at a time, so that the amount of data written at a time does not exceed the maximum amount of data that the database can bear, thereby avoiding excessive pressure on the database and ensuring stable data writing.

[0060] Figure 2C A flowchart of a method for writing to a database according to another embodiment of the present disclosure is schematically shown.

[0061] like Figure 2C As shown, in addition to operations S210 to S240, the method may further include operations S250 to S260 during the process of writing the second data cached in the message queue into the database.

[0062] In operation S250, a data writing speed of writing the second data into the database is determined.

[0063] According to an embodiment of the present disclosure, a speed monitoring program may be provided to monitor the speed of writing data into a database.

[0064] In operation S260, when the data writing speed exceeds the speed threshold, at least one writing thread corresponding to the preset writing operation is configured to be in a dormant state.

[0065] According to an embodiment of the present disclosure, the speed threshold can be determined according to the maximum write speed that the database can withstand. When the data write speed exceeds the speed threshold, the write speed is reduced to a safe value by configuring some write threads to be in a dormant state to avoid overwhelming the storage interface.

[0066] According to an embodiment of the present disclosure, by monitoring the data volume of user data, determining first data and / or second data from the user data according to the data volume of the user data, writing the first data to the database in a synchronous manner, and / or writing the second data to the database in an asynchronous manner, when writing user data to the database, it is achieved that the corresponding writing mode is automatically switched according to the data volume, so that the system can still operate normally when the writing data volume is large without rewriting the original system.

[0067] Reference below Figure 3 , combined with specific embodiments Figures 2A to 2C The method shown is further explained.

[0068] Figure 3A flowchart of a method for writing to a database according to an embodiment of the present disclosure is schematically shown.

[0069] like Figure 3 As shown in , the server obtains user data through user traffic storage. Then the window sliding traffic calculator in the core service is called to determine the traffic size of the user data, that is, the call volume per second. In this embodiment, the first threshold is configured as 10000 (number of transactions / second), and the second threshold is configured as 100000 (number of transactions / second). If 0<second-level call volume≤10000, all user data is used as the first data, and the storage interface is directly called to write the user data into the database. If 10000<second-level call volume≤100000, 50% of the user data is used as the first data, and the storage interface is directly called for storage, and the other 50% is used as the second data, which is pressed into the MQ (message queue) pipeline, and then consumed by the worker at the back end (i.e., the consumer end), where worker consumption refers to the operation of data storage through tasks set at a fixed time. If the call volume per second is greater than 100000, all user data is used as the second data, pressed into the MQ pipeline, and then consumed by the worker at the back end.

[0070] In the process of consumption through the backend worker, the consumption speed can also be monitored, that is, the speed of writing to the database. And by judging whether the current consumption speed is less than the speed threshold, it is determined whether the consumption speed matches. When the consumption speed is greater than the speed threshold, that is, the consumption speed does not match, the Thread.sleep() method is used to put some writing threads into a dormant state to adjust the consumption speed. When the consumption speed is less than or equal to the speed threshold, that is, the consumption speed matches, the downstream warehousing interface is called to write subsequent data to the database.

[0071] According to the embodiments of the present disclosure, the core service utilizes the peak-shaving and valley-filling characteristics of MQ to press instantaneous traffic into the MQ pipeline, which is then consumed by the worker. During the consumption process by the worker, the consumption speed is controlled to ensure the normal operation of the business.

[0072] Figure 4A A block diagram of a device for writing to a database according to an embodiment of the present disclosure is schematically shown.

[0073] like Figure 4A As shown, the device 400 includes an acquisition module 410 , a data amount determination module 420 , a data judgment module 430 and a writing module 440 .

[0074] The acquisition module 410, for example, executes the above reference Figure 2A The described operation S210 is used to obtain user data generated within a preset time window.

[0075] The data volume determination module 420, for example, executes the above reference Figure 2A The described operation S220 is used to determine the data amount of the user data.

[0076] The data determination module 430, for example, executes the above reference Figure 2A The described operation S230 is used to determine the first data and / or the second data from the user data according to the determined data amount.

[0077] Write module 440, for example, executes the above reference Figure 2A The described operation S240 is used to perform a preset write operation on the database with respect to the first data and / or the second data.

[0078] The writing module 440 includes: a synchronous writing submodule 441 for writing the first data into the database in a synchronous manner; and / or an asynchronous writing submodule 442 for writing the second data into the database in an asynchronous manner.

[0079] According to an embodiment of the present disclosure, by monitoring the data volume of user data, determining first data and / or second data from the user data according to the data volume of the user data, writing the first data to the database in a synchronous manner, and / or writing the second data to the database in an asynchronous manner, when writing user data to the database, it is achieved that the corresponding writing mode is automatically switched according to the data volume, so that the system can still operate normally when the writing data volume is large without rewriting the original system.

[0080] Figure 4B The block diagram of the data judgment module according to the embodiment of the present disclosure is schematically shown.

[0081] like Figure 4B As shown, according to an embodiment of the present disclosure, the data determination module 430 may include at least one submodule of a first determination submodule 431, a second determination submodule 432, and a third determination submodule 433:

[0082] The first determining submodule 431, for example, executes the above reference Figure 2B The described operation S231 is used to use all the user data as the first data when the determined data amount is less than or equal to the first threshold.

[0083] The second determination submodule 432, for example, executes the above reference Figure 2B The described operation S232 is used to divide the user data into first data and second data according to a preset ratio when the determined data amount is greater than the first threshold and less than or equal to the second threshold.

[0084] The third determination submodule 433, for example, executes the above reference Figure 2B The described operation S233 is used to use all the user data as the second data when the determined data amount is greater than the second threshold.

[0085] According to an embodiment of the present disclosure, the synchronous writing submodule 441 is specifically used to: after obtaining the first data from the user data, directly write the first data into the database.

[0086] According to an embodiment of the present disclosure, the asynchronous writing submodule 442 is specifically used to: after obtaining the second data from the user data, first cache the second data in the message queue, and then write the second data cached in the message queue into the database after a preset delay time.

[0087] Figure 5 A block diagram of a device for writing to a database according to another embodiment of the present disclosure is schematically shown.

[0088] like Figure 5 As shown, according to an embodiment of the present disclosure, the writing device 500 for the database, in the process of writing the second data cached in the message queue into the database, in addition to the acquisition module 410, the data amount determination module 420, the data judgment module 430 and the writing module 440, also includes a writing speed determination module 550 and a sleep module 560.

[0089] The write speed determination module 550, for example, executes the above reference Figure 2C The described operation S250 is used to determine a data writing speed for writing the second data into the database.

[0090] The sleep module 560, for example, executes the above reference Figure 2C The described operation S260 is used to configure at least one write thread corresponding to a preset write operation to a dormant state when the data write speed exceeds a speed threshold.

[0091] According to the embodiments of the present invention, any one or more of the modules, submodules, units, and subunits, or at least part of the functions of any one of them can be implemented in one module. According to the embodiments of the present invention, any one or more of the modules, submodules, units, and subunits can be split into multiple modules for implementation. According to the embodiments of the present invention, any one or more of the modules, submodules, units, and subunits can be at least partially implemented as hardware circuits, such as field programmable gate arrays (FPGAs), programmable logic arrays (PLAs), systems on chips, systems on substrates, systems on packages, application specific integrated circuits (ASICs), or can be implemented by hardware or firmware in any other reasonable way of integrating or packaging the circuit, or implemented in any one of the three implementation methods of software, hardware, and firmware, or in any appropriate combination of any of them. Alternatively, according to the embodiments of the present invention, one or more of the modules, submodules, units, and subunits can be at least partially implemented as computer program modules, and when the computer program modules are run, the corresponding functions can be performed.

[0092] For example, acquisition module 410, data volume determination module 420, data judgment module 430, write module 440, write speed determination module 550 and sleep module 560. Any multiple of them can be combined in one module for implementation, or any one of them can be split into multiple modules. Alternatively, at least part of the functions of one or more of these modules can be combined with at least part of the functions of other modules and implemented in one module. According to an embodiment of the present disclosure, at least one of acquisition module 410, data volume determination module 420, data judgment module 430, write module 440, write speed determination module 550 and sleep module 560 can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application specific integrated circuit (ASIC), or can be implemented by hardware or firmware such as any other reasonable way of integrating or packaging the circuit, or implemented in any one of the three implementation methods of software, hardware and firmware or in an appropriate combination of any of them. Alternatively, at least one of the acquisition module 410, the data amount determination module 420, the data judgment module 430, the writing module 440, the writing speed determination module 550 and the sleep module 560 can be at least partially implemented as a computer program module, and when the computer program module is executed, the corresponding function can be executed.

[0093] Figure 6 A block diagram of a computer system suitable for implementing the above-described method for writing to a database according to an embodiment of the present disclosure is schematically shown. Figure 6The computer system shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0094] like Figure 6 As shown, the computer system 600 according to the embodiment of the present disclosure includes a processor 601, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 602 or the program loaded from the storage part 608 to the random access memory (RAM) 603. The processor 601 may include, for example, a general-purpose microprocessor (such as a CPU), an instruction set processor and / or a related chipset and / or a special-purpose microprocessor (for example, an application-specific integrated circuit (ASIC)), etc. The processor 601 may also include an onboard memory for caching purposes. The processor 601 may include a single processing unit or multiple processing units for performing different actions of the method flow according to the embodiment of the present disclosure.

[0095] In RAM 603, various programs and data required for the operation of system 600 are stored. Processor 601, ROM 602 and RAM 603 are connected to each other through bus 604. Processor 601 performs various operations of the method flow according to the embodiment of the present disclosure by executing the program in ROM 602 and / or RAM 603. It should be noted that the program can also be stored in one or more memories other than ROM 602 and RAM 603. Processor 601 can also perform various operations of the method flow according to the embodiment of the present disclosure by executing the program stored in the one or more memories.

[0096] According to an embodiment of the present disclosure, the system 600 may further include an input / output (I / O) interface 605, which is also connected to the bus 604. The system 600 may further include one or more of the following components connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage section 608 as needed.

[0097] According to an embodiment of the present disclosure, the method flow according to an embodiment of the present disclosure can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable storage medium, and the computer program contains a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 609, and / or installed from the removable medium 611. When the computer program is executed by the processor 601, the above-mentioned functions defined in the system of the embodiment of the present disclosure are executed. According to an embodiment of the present disclosure, the system, equipment, device, module, unit, etc. described above can be implemented by a computer program module.

[0098] The present disclosure also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or may exist independently without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the method for writing to a database according to the embodiment of the present disclosure is implemented.

[0099] According to an embodiment of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, for example, may include but is not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, an apparatus or a device. For example, according to an embodiment of the present disclosure, a computer-readable storage medium may include the ROM 602 and / or RAM 603 described above and / or one or more memories other than ROM 602 and RAM 603.

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

[0101] It will be appreciated by those skilled in the art that the features described in the various embodiments and / or claims of the present disclosure may be combined and / or combined in a variety of ways, even if such combinations and / or combinations are not explicitly described in the present disclosure. In particular, the features described in the various embodiments and / or claims of the present disclosure may be combined and / or combined in a variety of ways without departing from the spirit and teachings of the present disclosure. All of these combinations and / or combinations fall within the scope of the present disclosure.

[0102] The embodiments of the present disclosure are described above. However, these embodiments are only for illustrative purposes and are not intended to limit the scope of the present disclosure. Although the embodiments are described above separately, this does not mean that the measures in the various embodiments cannot be used in combination to advantage. The scope of the present disclosure is defined by the attached claims and their equivalents. Without departing from the scope of the present disclosure, those skilled in the art may make a variety of substitutions and modifications, which should all fall within the scope of the present disclosure.

Claims

1. A method for writing to a database. include: Obtain user data generated within a preset time window; Determining the amount of the user data; determining first data and / or second data from the user data according to the determined data amount; as well as performing a preset write operation on the database for the first data and / or the second data, Wherein, the preset write operation includes: Writing the first data to the database in a synchronous manner; and / or Writing the second data into the database in an asynchronous manner; Writing the second data into the database in an asynchronous manner includes: after obtaining the second data from the user data, first caching the second data in a message queue, and then writing the second data cached in the message queue into the database after a preset delay time; In which, in the process of writing the second data cached in the message queue into the database, a data writing speed of writing the second data into the database is determined; and when the data writing speed exceeds a speed threshold, at least one write thread corresponding to the preset write operation is configured to be in a sleep state.

2. The method according to claim 1, in, Determining the first data and / or the second data from the user data according to the determined data amount includes at least one of the following: When the determined data amount is less than or equal to a first threshold, taking all of the user data as first data; When the determined data amount is greater than the first threshold and less than or equal to a second threshold, dividing the user data into first data and second data according to a preset ratio; as well as When the determined data amount is greater than the second threshold, all of the user data is used as second data.

3. The method according to claim 1, in, Writing the first data into the database in a synchronous manner includes: After obtaining the first data from the user data, the first data is directly written into the database.

4. A writing device for a database, include: An acquisition module is used to acquire user data generated within a preset time window; A data volume determination module, used to determine the data volume of the user data; A data determination module, configured to determine first data and / or second data from the user data according to the determined data amount; as well as a writing module, configured to perform a preset writing operation on the database with respect to the first data and / or the second data, Wherein, the writing module includes: a synchronous writing submodule, used for writing the first data into the database in a synchronous manner; and / or an asynchronous writing submodule, used for writing the second data into the database in an asynchronous manner; The asynchronous writing submodule is further used to: after obtaining the second data from the user data, first cache the second data in the message queue, and then write the second data cached in the message queue into the database after a preset delay time; In the process of writing the second data cached in the message queue into the database, a writing speed determining module, configured to determine a data writing speed for writing the second data into the database; and The sleep module is used to configure at least one write thread corresponding to the preset write operation to a sleep state when the data write speed exceeds a speed threshold.

5. The device according to claim 4, in, The data judgment module includes at least one of the following: A first determining submodule, configured to use all of the user data as first data when the determined data amount is less than or equal to a first threshold; a second determining submodule, configured to divide the user data into first data and second data according to a preset ratio when the determined data amount is greater than the first threshold and less than or equal to a second threshold; as well as The third determining submodule is configured to use, when the determined data amount is greater than the second threshold, all of the user data as second data.

6. The device according to claim 4, in, The synchronous writing submodule is specifically used for: After obtaining the first data from the user data, the first data is directly written into the database.

7. A computing device, include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method of any one of claims 1 to 3.

8. A computer-readable storage medium having executable instructions stored thereon, which, when executed by a processor, causes the processor to implement the method of any one of claims 1 to 3.

Citation Information

Patent Citations

  • A data writing method and apparatus

    CN109359118A