CN111367666A - Data reading and writing method and system - Google Patents

Data reading and writing method and system Download PDF

Info

Publication number
CN111367666A
CN111367666A CN202010127800.5A CN202010127800A CN111367666A CN 111367666 A CN111367666 A CN 111367666A CN 202010127800 A CN202010127800 A CN 202010127800A CN 111367666 A CN111367666 A CN 111367666A
Authority
CN
China
Prior art keywords
read
write
data
write request
data interface
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010127800.5A
Other languages
Chinese (zh)
Inventor
刘宏亚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
OneConnect Smart Technology Co Ltd
OneConnect Financial Technology Co Ltd Shanghai
Original Assignee
OneConnect Financial Technology Co Ltd Shanghai
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by OneConnect Financial Technology Co Ltd Shanghai filed Critical OneConnect Financial Technology Co Ltd Shanghai
Priority to CN202010127800.5A priority Critical patent/CN111367666A/en
Publication of CN111367666A publication Critical patent/CN111367666A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • G06F9/524Deadlock detection or avoidance
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues

Abstract

The invention provides a data reading and writing method, which comprises the following steps: receiving a read-write request message sent by an access user to cache data through a data interface, and generating a read-write request thread according to the read-write request message; dividing the access users into read access users and write access users according to the read-write request thread; when the user is a read access user, calling a data interface to read the read-write request thread; when the user is a write access user, calling a data interface to obtain cache data, and writing the cache data into the read-write request thread; and returning the read-write result of the cached data to an access user through the data interface. The data reading and writing method, the data reading and writing system, the computer equipment and the computer readable storage medium fully consider various request scenes, perform different processing under different scenes, solve the problem of inconsistent reading and writing, effectively control power and the like, and improve the system performance.

Description

Data reading and writing method and system
Technical Field
The invention relates to the technical field of computers, in particular to a data reading and writing method and a data reading and writing system.
Background
At present, many systems need to call an external system to acquire data or write data, many requests are gushed at the same time under the distributed deployment environment or high concurrency condition, and the data with low reading timeliness requirement can be read by multiple requests, so that system resources are wasted; for simultaneous data writing requests, idempotent cannot be guaranteed, that is, when data is written, data is read simultaneously, and a data reading error occurs.
Disclosure of Invention
In view of this, the present invention provides a data reading and writing method, system, computer device and computer readable storage medium, which are used to solve the problem that power is difficult to guarantee in a high concurrency state.
The embodiment of the invention solves the technical problems through the following technical scheme:
a method for reading and writing data, comprising:
receiving a read-write request message sent by an access user to cache data through a data interface, and generating a read-write request thread according to the read-write request message;
dividing the access users into read access users and write access users according to the read-write request thread;
when the user is a read access user, calling a data interface to read the read-write request thread; and
when the user is a write access user, calling a data interface to obtain cache data, and writing the cache data into the read-write request thread;
and returning the read-write result of the cached data to an access user through the data interface.
Further, the dividing the access users into the read access users and the write access users according to the read-write request thread includes:
judging whether the read-write request thread has cache data or not;
and when cache data exist in the read-write request thread, the access user is a read access user, and when cache data do not exist in the read-write request thread, the access user is a write access user.
Further, the data interface is divided into a first time efficiency data interface and a second time efficiency data interface according to the time efficiency of the interface, and when the user is a read access user, calling the data interface to read the read-write request thread includes:
when the data interface is a first time-efficient data interface, matching first cache data read-write logic; and when the data interface is a second time-efficient data interface, matching second cache data read-write logic.
Further, the data interface is divided into a first time efficiency data interface and a second time efficiency data interface according to the time efficiency of the interface, and the data interface comprises:
monitoring the change frequency of request messages of the data interface; and
and if the data change frequency is greater than the preset frequency, the data interface is a first time efficiency data interface, and if the change frequency is less than the preset frequency, the data interface is a second time efficiency data interface.
Further, when the data interface is a first time-efficient data interface, matching the first cache data read-write logic includes:
acquiring the number of read locks on the read-write request thread, and judging whether the number of the read locks is smaller than a preset threshold value to obtain a first judgment result;
when the first judgment result is that the number of the read locks is less than or equal to a preset threshold value, adding the read locks on the read-write request thread, calling a first time-efficient data interface to read the contents of the read-write request thread, and removing the read locks after the reading is finished; and
and when the first judgment result is that the number of the read locks is greater than the preset threshold value, returning to the step of judging whether the number of the read locks is less than the preset threshold value.
Further, when the data interface is a second aging data interface, matching the second cache data read-write logic includes:
judging whether the read-write request thread has cache data or not to obtain a second judgment result;
when the second judgment result shows that cache data exists in the read-write request thread, adding a read lock on the read-write request thread, calling a second time-efficient data interface to read the content of the read-write request thread, and releasing the read lock after the reading is finished; and
and when the second judgment result is that no cache data exists in the read-write request thread, putting the cache data, and when the time for putting the cache data exceeds the overtime time, clearing the cache data.
Further, when the user is a write access user, a data interface is called to obtain cache data, and the writing into the read-write request thread includes:
judging whether a write lock exists on the read-write request thread to obtain a third judgment result;
when the third judgment result is that the read-write request thread has a write lock, returning to the step of judging whether the read-write request thread has the write lock; and
when the third judgment result indicates that no write lock exists on the read-write request thread, judging whether a read lock exists on the read-write request thread to obtain a fourth judgment result;
when the fourth judgment result shows that no read lock exists on the read-write request thread, calling a first time efficiency data interface or a second time efficiency data interface to write cache data in the read-write request thread, and releasing the write lock after the write is completed; and
and when the fourth judgment result shows that the read lock exists on the read-write request thread, returning to the step of judging whether the read lock exists on the read-write request thread.
In order to achieve the above object, an embodiment of the present invention further provides a data reading and writing system, including:
the read-write request thread generation module is used for receiving read-write request information sent by an access user to cache data through a data interface and generating a read-write request thread according to the read-write request information;
the user category judgment module is used for dividing the access users into read access users and write access users according to the read-write request thread;
a read-write module for calling a data interface to read the read-write request thread and the read-write module when the user is a read access user
When the user is a write access user, calling a data interface to obtain cache data, and writing the cache data into the read-write request thread;
and the read-write result sending module is used for returning the read-write result of the cache data to the access user through the data interface.
In order to achieve the above object, an embodiment of the present invention further provides a computer device, where the computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the steps of the data reading and writing method when executing the computer program.
In order to achieve the above object, an embodiment of the present invention further provides a computer-readable storage medium, where a computer program is stored, where the computer program is executable by at least one processor, so as to cause the at least one processor to execute the steps of the data reading and writing method described above.
The data reading and writing method, the data reading and writing system, the computer equipment and the computer readable storage medium provided by the invention fully consider various request scenes, perform different processing under different scenes, solve the problem of inconsistent reading and writing, effectively control power and the like, and improve the system performance.
The invention is described in detail below with reference to the drawings and specific examples, but the invention is not limited thereto.
Drawings
FIG. 1 is a flowchart illustrating steps of a data read/write method according to a first embodiment of the present invention;
fig. 2 is a flowchart illustrating a step of dividing an access user into a read access user and a write access user according to the read/write request thread in accordance with a first embodiment of the present invention;
FIG. 3 is a flowchart illustrating a step of matching a first cache data read/write logic when the data interface is a first clock data interface according to a first embodiment of the present invention;
FIG. 4 is a flowchart illustrating a step of matching a second cache data read/write logic when the data interface is a second aging data interface according to a first embodiment of the present invention;
fig. 5 is a flowchart illustrating a step of calling a data interface to obtain cache data and writing the cache data into the read-write request thread when a user is a write-access user according to a first embodiment of the present invention;
FIG. 6 is a block diagram of a second embodiment of a data read/write system according to the present invention;
FIG. 7 is a diagram of a hardware structure of a third embodiment of the computer apparatus according to the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Technical solutions between various embodiments may be combined with each other, but must be realized by those skilled in the art, and when the technical solutions are contradictory or cannot be realized, such a combination should not be considered to exist, and is not within the protection scope of the present invention.
Example one
Referring to fig. 1, a flowchart illustrating steps of a data reading/writing method according to an embodiment of the invention is shown. It is to be understood that the flow charts in the embodiments of the present method are not intended to limit the order in which the steps are performed. The following description is given by taking a computer device as an execution subject, specifically as follows:
step S100: receiving a read-write request message sent by an access user to cache data through a data interface, and generating a read-write request thread according to the read-write request message;
specifically, the read-write request refers to an operation of reading or writing the cache data by a user, and when an access user of the cache resource sends a read request or a write request for the shared resource to the background, a read-write request thread corresponding to the read-write request message is generated. The thread is the minimum unit that the operating system can perform operation scheduling, and is used for performing corresponding operation according to a user request.
S200: dividing the access users into read access users and write access users according to the read-write request thread; the read access user refers to an access user for performing read operation on the cache resource, and the write access user refers to an access user for performing write operation on the cache resource.
In an exemplary embodiment, referring to fig. 2, the step S200 further includes:
step S201: judging whether the read-write request thread has cache data or not;
step S202: and when cache data exist in the read-write request thread, the access user is a read access user, and when cache data do not exist in the read-write request thread, the access user is a write access user.
Specifically, after the background generates a read-write request thread based on the read-write request, a read lock is added to the thread to read whether cache data is acquired in the read-write request thread, when cache data is acquired in the read-write request thread, the access user is a read access user, and otherwise, the access user is a write access user.
S300: when the user is a read access user, calling a data interface to read the read-write request thread and
and when the user is a write access user, calling a data interface to obtain cache data, and writing the cache data into the read-write request thread.
The data interface is divided into a first time efficiency data interface and a second time efficiency data interface according to the time efficiency of the interface.
In an exemplary embodiment, the method further includes a method for determining timeliness of the data interface:
step S110: monitoring the change frequency of request messages of the data interface; and
and if the data change frequency is greater than the preset frequency, the data interface is a first time efficiency data interface, and if the change frequency is less than the preset frequency, the data interface is a second time efficiency data interface.
Specifically, the timeliness of the data interface refers to how fast the content of the data interface changes. Some data interfaces have fast content change, and each access request needs to acquire the latest data, which is called a data interface with strong timeliness, such as a data interface for acquiring time; some data interfaces have slow data change, and the requested data does not change within a certain time, such as data interfaces for people to carry out credit.
In another embodiment, the method for determining timeliness of a data interface further includes:
checking the historical use frequency of the interface, if the use frequency of the interface is greater than the preset frequency, judging that the interface is a reading external interface with low timeliness, and if the use frequency of the interface is less than the preset frequency, judging that the interface is an external reading interface with high timeliness;
or
Recording the number of requests of the data interface in a certain fixed time period, if the number of requests is greater than a preset number, determining that the data interface is a reading external interface with weak timeliness, and if the number of requests is less than the preset number, determining that the data interface is an external reading interface with strong timeliness, which is not described herein in detail in this embodiment.
In an exemplary embodiment, step S300 further includes:
step S301: when the data interface is a first time-efficient data interface, matching first cache data read-write logic; and when the data interface is a second time-efficient data interface, matching second cache data read-write logic.
In an exemplary embodiment, referring to fig. 3, step S301 further includes:
step S310a 1: acquiring the number of read locks on the read-write request thread, and judging whether the number of the read locks is smaller than a preset threshold value to obtain a first judgment result;
step S310a 2: when the first judgment result is that the number of the read locks is less than or equal to a preset threshold value, adding the read locks on the read-write request thread, calling a first time-efficient data interface to read the contents of the read-write request thread, and removing the read locks after the reading is finished; and
and when the first judgment result is that the number of the read locks is greater than the preset threshold value, returning to the step of judging whether the number of the read locks is less than the preset threshold value.
Specifically, the read lock refers to allowing multiple read-write request threads to perform read operation on the cache resource at the same time. The preset threshold value is determined by the interface concurrency amount allowed by a first timeliness data interface provider, and the interface concurrency amount is the number of online users interacting with the server at the same moment.
In an exemplary embodiment, referring to fig. 4, step S301 further includes:
step S310B 1: and judging whether the read-write request thread has cache data or not to obtain a second judgment result.
Step S310B 2: when the second judgment result shows that cache data exists in the read-write request thread, adding a read lock on the read-write request thread, calling a second time-efficient data interface to read the content of the read-write request thread, and releasing the read lock after the reading is finished; and
and when the second judgment result is that no cache data exists in the read-write request thread, putting the cache data, and when the time for putting the cache data exceeds the overtime time, clearing the cache data.
In an exemplary embodiment, the timeout time is further determined according to the high-low level of the timeliness of the second timeliness data interface, a first change frequency and a second change frequency are preset, the first change frequency is greater than the second change frequency, if the data change frequency of the interface is monitored to be greater than the first change frequency, the timeliness of the interface is determined to be high, and the timeout time is correspondingly set to be 5-10 minutes; if the data change frequency of the interface is between the first change frequency and the second change frequency, determining the timeliness of the interface to be a middle level, and correspondingly setting the timeout time to be 10-30 minutes; and if the data change frequency of the interface is less than a second change frequency, determining that the timeliness of the interface is low, and correspondingly setting the timeout time to be 30-60 minutes.
In an exemplary embodiment, referring to fig. 5, step S300 further includes:
step S320: judging whether a write lock exists on the read-write request thread to obtain a third judgment result;
step S321: when the third judgment result is that the read-write request thread has a write lock, returning to the step of judging whether the read-write request thread has the write lock; and
when the third judgment result indicates that no write lock exists on the read-write request thread, judging whether a read lock exists on the read-write request thread to obtain a fourth judgment result;
step S322: when the fourth judgment result shows that no read lock exists on the read-write request thread, calling a first time efficiency data interface or a second time efficiency data interface to write cache data in the read-write request thread, and releasing the write lock after the write is completed; and
and when the fourth judgment result shows that the read lock exists on the read-write request thread, returning to the step of judging whether the read lock exists on the read-write request thread.
Specifically, the write lock refers to that when the read-write request thread performs write operation on the cache resource, other read-write request threads are not allowed to perform read operation or write operation on the contributed resource. And adding a write lock to the read-write request thread, degrading the write lock into a read lock after the cache data is written, and reading the content of the read-write request thread by the written cache data through the first aging data interface or the second aging data interface.
The embodiment of the invention also comprises the following steps: before the data interface acquires the current read-write request thread, whether the interface is normal or not is judged, when the judgment result is normal, the read-write operation is continued, and specifically, when the judgment result is that the interface is abnormal, service fusing is performed. Service fusing refers to a protection measure adopted in a software system to prevent the whole system from being in failure due to the overload phenomenon of a service caused by some reasons.
The service fusing further comprises configuring fusing parameter threshold values, wherein the fusing parameters comprise but are not limited to error request rate and error request times in fixed time, and the error request rate refers to the percentage of the requests with problems in all requests.
Acquiring fusing parameters;
judging whether the interface is in an abnormal state;
specifically, if the acquired fusing parameter is greater than a preset threshold, it is determined that the interface is in an abnormal state, and service fusing is performed.
S400: and returning the read-write result of the cached data to an access user through the data interface.
Specifically, since the write lock is degraded to the read lock after writing the cache data, the corresponding read and write result is based on the cache data based on the read and write request of the access user.
The embodiment of the invention uses the read-write lock to perform request control, solves the problem of inconsistent read-write, can effectively control the idempotent and simultaneously judges the condition of the external interface for further refinement, improves the system performance, simultaneously fully considers various request scenes, and improves the disaster tolerance capability of the system by refining the judgment condition of the external interface.
Example two
Referring to fig. 6, a schematic diagram of program modules of the data read/write system of the present invention is shown. In this embodiment, the data reading/writing system 20 may include or be divided into one or more program modules, and the one or more program modules are stored in a storage medium and executed by one or more processors to implement the present invention and implement the data reading/writing method. The program module referred to in the embodiments of the present invention refers to a series of computer program instruction segments capable of performing specific functions, and is more suitable for describing the execution process of the data read/write system 20 in the storage medium than the program itself. The following description will specifically describe the functions of the program modules of the present embodiment:
a read-write request thread generation module 200, configured to receive a read-write request message sent by an access user to cache data through a data interface, and generate a read-write request thread according to the read-write request message;
and the user type judging module 202 is configured to divide the access user into a read access user and a write access user according to the read-write request thread.
Further, the user category determination module 202 is further configured to:
reading whether the read-write request thread has cache data or not;
and when cache data exist in the read-write request thread, the access user is a read access user, and when cache data do not exist in the read-write request thread, the access user is a write access user.
A read-write module 204, configured to, when the user is a read access user, invoke a data interface to read the read-write request thread and
and when the user is a write access user, calling a data interface to obtain cache data, and writing the cache data into the read-write request thread.
Further, the read-write module 204 is further configured to:
when the data interface is a first time-efficient data interface, matching first cache data read-write logic; and when the data interface is a second time-efficient data interface, matching second cache data read-write logic.
Further, the read-write module 204 is further configured to:
monitoring the change frequency of request messages of the data interface; and
and if the data change frequency is greater than the preset frequency, the data interface is a first time efficiency data interface, and if the change frequency is less than the preset frequency, the data interface is a second time efficiency data interface.
Further, the read-write module 204 is further configured to:
acquiring the number of read locks on the read-write request thread, and judging whether the number of the read locks is smaller than a preset threshold value to obtain a first judgment result;
when the first judgment result is that the number of the read locks is less than or equal to a preset threshold value, adding the read locks on the read-write request thread, calling a first time-efficient data interface to read the contents of the read-write request thread, and removing the read locks after the reading is finished; and
and when the first judgment result is that the number of the read locks is greater than the preset threshold value, returning to the step of judging whether the number of the read locks is less than the preset threshold value.
Further, the read-write module 204 is further configured to:
judging whether the read-write request thread has cache data or not to obtain a second judgment result;
when the second judgment result shows that cache data exists in the read-write request thread, adding a read lock on the read-write request thread, calling a second time-efficient data interface to read the content of the read-write request thread, and releasing the read lock after the reading is finished; and
and when the second judgment result is that no cache data exists in the read-write request thread, putting the cache data, and when the time for putting the cache data exceeds the overtime time, clearing the cache data.
Further, the read-write module 204 is further configured to:
judging whether a write lock exists on the read-write request thread to obtain a third judgment result;
when the third judgment result is that the read-write request thread has a write lock, returning to the step of judging whether the read-write request thread has the write lock; and
when the third judgment result indicates that no write lock exists on the read-write request thread, judging whether a read lock exists on the read-write request thread to obtain a fourth judgment result;
when the fourth judgment result shows that no read lock exists on the read-write request thread, calling a first time efficiency data interface or writing cache data into the read-write request thread for a second time efficiency data interface, and releasing the write lock after the writing is finished; and
and when the fourth judgment result shows that the read lock exists on the read-write request thread, returning to the step of judging whether the read lock exists on the read-write request thread.
A read-write result sending module 206, configured to return the read-write result of the cached data to the access user via the data interface.
EXAMPLE III
Fig. 7 is a schematic diagram of a hardware architecture of a computer device according to a third embodiment of the present invention. In the present embodiment, the computer device 2 is a device capable of automatically performing numerical calculation and/or information processing in accordance with a preset or stored instruction. The computer device 2 may be a rack server, a blade server, a tower server or a rack server (including an independent server or a server cluster composed of a plurality of servers), and the like. As shown in FIG. 7, the computer device 2 includes, but is not limited to, at least a memory 21, a processor 22, a network interface 23, and a data read/write system 20, which are communicatively connected to each other via a system bus. Wherein:
in this embodiment, the memory 21 includes at least one type of computer-readable storage medium including a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Read Only Memory (ROM), an Electrically Erasable Programmable Read Only Memory (EEPROM), a Programmable Read Only Memory (PROM), a magnetic memory, a magnetic disk, an optical disk, and the like. In some embodiments, the storage 21 may be an internal storage unit of the computer device 2, such as a hard disk or a memory of the computer device 2. In other embodiments, the memory 21 may also be an external storage device of the computer device 2, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), or the like provided on the computer device 2. Of course, the memory 21 may also comprise both internal and external memory units of the computer device 2. In this embodiment, the memory 21 is generally used for storing an operating system installed in the computer device 2 and various application software, such as the program codes of the data read/write system 20 described in the above embodiment. Further, the memory 21 may also be used to temporarily store various types of data that have been output or are to be output.
Processor 22 may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor, or other data Processing chip in some embodiments. The processor 22 is typically used to control the overall operation of the computer device 2. In this embodiment, the processor 22 is configured to run the program code stored in the memory 21 or process data, for example, run the data reading and writing system 20, so as to implement the data reading and writing method of the above-mentioned embodiment.
The network interface 23 may comprise a wireless network interface or a wired network interface, and the network interface 23 is generally used for establishing communication connection between the computer device 2 and other electronic apparatuses. For example, the network interface 23 is used to connect the computer device 2 to an external terminal through a network, establish a data transmission channel and a communication connection between the computer device 2 and the external terminal, and the like. The network may be a wireless or wired network such as an Intranet (Intranet), the Internet (Internet), a Global System of Mobile communication (GSM), Wideband Code Division Multiple Access (WCDMA), a 4G network, a 5G network, Bluetooth (Bluetooth), Wi-Fi, and the like.
It is noted that fig. 7 only shows the computer device 2 with components 20-23, but it is to be understood that not all shown components are required to be implemented, and that more or less components may be implemented instead.
In this embodiment, the data read/write system 20 stored in the memory 21 can be further divided into one or more program modules, and the one or more program modules are stored in the memory 21 and executed by one or more processors (in this embodiment, the processor 22) to complete the present invention.
For example, fig. 6 shows a schematic diagram of program modules of a second embodiment of the data read/write system 20, in this embodiment, the data read/write system 20 may be divided into a read/write request thread generating module 200, a user category determining module 202, a read/write module 204, and a read/write result sending module 206. The program module referred to in the present invention refers to a series of computer program instruction segments capable of performing specific functions, and is more suitable than a program for describing the execution process of the data read/write system 20 in the computer device 2. The specific functions of the program module read-write request thread generation module 200 and the read-write result sending module 206 have been described in detail in the above embodiments, and are not described herein again.
Example four
The present embodiment also provides a computer-readable storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, a server, an App application mall, etc., on which a computer program is stored, which when executed by a processor implements corresponding functions. The computer-readable storage medium of this embodiment is used for storing the data reading and writing system 20, and when being executed by a processor, the computer-readable storage medium implements the data reading and writing method of the above embodiment.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (10)

1. A method for reading and writing data, comprising:
receiving a read-write request message sent by an access user to cache data through a data interface, and generating a read-write request thread according to the read-write request message;
dividing the access users into read access users and write access users according to the read-write request thread;
when the user is a read access user, calling a data interface to read the read-write request thread; and
when the user is a write access user, calling a data interface to obtain cache data, and writing the cache data into the read-write request thread;
and returning the read-write result of the cached data to an access user through the data interface.
2. The data reading and writing method according to claim 1, wherein the dividing of the access users into the read access users and the write access users according to the read and write request thread includes:
judging whether the read-write request thread has cache data or not;
and when cache data exist in the read-write request thread, the access user is a read access user, and when cache data do not exist in the read-write request thread, the access user is a write access user.
3. The data reading and writing method according to claim 2, wherein the data interface is divided into a first time-efficient data interface and a second time-efficient data interface according to the timeliness of the interface, and the invoking the data interface to read the read-write request thread when the user is a read access user comprises:
when the data interface is a first time-efficient data interface, matching first cache data read-write logic; and when the data interface is a second time-efficient data interface, matching second cache data read-write logic.
4. The data reading and writing method according to claim 3, wherein the data interface is divided into a first time-efficient data interface and a second time-efficient data interface according to the time efficiency of the interfaces, and the method comprises:
monitoring the change frequency of request messages of the data interface; and
and if the data change frequency is greater than the preset frequency, the data interface is a first time efficiency data interface, and if the change frequency is less than the preset frequency, the data interface is a second time efficiency data interface.
5. The method according to claim 3, wherein the matching the first cache data read/write logic when the data interface is the first time-efficient data interface comprises:
acquiring the number of read locks on the read-write request thread, and judging whether the number of the read locks is smaller than a preset threshold value to obtain a first judgment result;
when the first judgment result is that the number of the read locks is less than or equal to a preset threshold value, adding the read locks on the read-write request thread, calling a first time-efficient data interface to read the contents of the read-write request thread, and removing the read locks after the reading is finished; and
and when the first judgment result is that the number of the read locks is greater than the preset threshold value, returning to the step of judging whether the number of the read locks is less than the preset threshold value.
6. The method according to claim 3, wherein the matching the second cache data read-write logic when the data interface is a second aging data interface comprises:
judging whether the read-write request thread has cache data or not to obtain a second judgment result;
when the second judgment result shows that cache data exists in the read-write request thread, adding a read lock on the read-write request thread, calling a second time-efficient data interface to read the content of the read-write request thread, and releasing the read lock after the reading is finished; and
and when the second judgment result shows that no cache data exists in the read-write request thread, cache data is put in, and when the time for putting the cache data exceeds the overtime time, the cache data is cleared.
7. The data reading and writing method according to claim 6, wherein when the user is a write access user, the data interface is called to obtain the cache data, and the writing into the read-write request thread includes:
judging whether a write lock exists on the read-write request thread to obtain a third judgment result;
when the third judgment result is that the read-write request thread has a write lock, returning to the step of judging whether the read-write request thread has the write lock; and
when the third judgment result indicates that no write lock exists on the read-write request thread, judging whether a read lock exists on the read-write request thread to obtain a fourth judgment result;
when the fourth judgment result shows that no read lock exists on the read-write request thread, calling a first time efficiency data interface or a second time efficiency data interface to write cache data in the read-write request thread, and releasing the write lock after the write is completed; and
and when the fourth judgment result shows that the read lock exists on the read-write request thread, returning to the step of judging whether the read lock exists on the read-write request thread.
8. A data reading and writing system, comprising:
the read-write request thread generation module is used for receiving read-write request information sent by an access user to cache data through a data interface and generating a read-write request thread according to the read-write request information;
the user category judgment module is used for dividing the access users into read access users and write access users according to the read-write request thread;
the read-write module is used for calling a data interface to read the read-write request thread when a user is a read access user; and
when the user is a write access user, calling a data interface to obtain cache data, and writing the cache data into the read-write request thread;
and the read-write result sending module is used for returning the read-write result of the cache data to the access user through the data interface.
9. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the steps of the data reading and writing method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, in which a computer program is stored, which computer program is executable by at least one processor to cause the at least one processor to perform the steps of the data reading and writing method according to any one of claims 1 to 7.
CN202010127800.5A 2020-02-28 2020-02-28 Data reading and writing method and system Pending CN111367666A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010127800.5A CN111367666A (en) 2020-02-28 2020-02-28 Data reading and writing method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010127800.5A CN111367666A (en) 2020-02-28 2020-02-28 Data reading and writing method and system

Publications (1)

Publication Number Publication Date
CN111367666A true CN111367666A (en) 2020-07-03

Family

ID=71206312

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010127800.5A Pending CN111367666A (en) 2020-02-28 2020-02-28 Data reading and writing method and system

Country Status (1)

Country Link
CN (1) CN111367666A (en)

Similar Documents

Publication Publication Date Title
CN108462760B (en) Electronic device, automatic cluster access domain name generation method and storage medium
US10785320B2 (en) Managing operation of instances
CN108874624B (en) Server, method for monitoring Java process and storage medium
CN111723079A (en) Data migration method and device, computer equipment and storage medium
CN111064626B (en) Configuration updating method, device, server and readable storage medium
CN104239156A (en) External service call method and system
CN114257551A (en) Distributed current limiting method and system and storage medium
CN111414391A (en) Method and system for accessing multiple data sources
CN111723057A (en) File pre-reading method, device, equipment and storage medium
CN108563774B (en) GPS data processing method and device
CN114189559A (en) Interface repeat request processing method and system based on Axios
CN113590285A (en) Method, system and equipment for dynamically setting thread pool parameters
CN112001707A (en) Business workflow generation method and system based on business data
CN116450165A (en) Method, system, terminal and storage medium for quickly building environment and deploying program
CN111367666A (en) Data reading and writing method and system
CN109962941B (en) Communication method, device and server
CN111400087A (en) Control method of operating system, terminal and storage medium
CN115756309A (en) Battery management equipment parameter storage method, battery management equipment and energy storage system
CN110058866B (en) Cluster component installation method and device
CN114513469A (en) Traffic shaping method and device for distributed system and storage medium
CN114553859A (en) BMC configuration management method and device, electronic equipment and storage medium
CN115314258B (en) Method and device for detecting weak password, electronic equipment and storage medium
CN117992305A (en) Virtual machine monitoring method and device, electronic equipment and storage medium
CN114356610A (en) Control method, device and equipment for interface calling and storage medium
CN116795531A (en) Resource scheduling method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination