Method and system for optimizing storage and concurrent access of e-mails
By optimizing concurrent access to email using atomic operation counters and lock segmentation mechanisms, the problem of excessively long response times caused by concurrent access is solved, and multi-threaded safety and performance are improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- FOSHAN FUNGUO NETWORK TECH CO LTD
- Filing Date
- 2023-07-24
- Publication Date
- 2026-05-15
AI Technical Summary
In existing technologies, concurrent access to email results in excessively long request response times and is prone to failure when multiple requests are made.
It employs atomic operation counters and lock segmentation mechanisms, and uses Atomic technology to achieve concurrent access to email storage and folders, avoiding serialized operations, ensuring multi-threaded safety, and reducing server response time.
It improves security and performance for concurrent email access in a multi-threaded environment, reduces server response time, and optimizes access requirements for multiple domains.
Smart Images

Figure CN116915737B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the technical field of email storage, and in particular to a method and system for optimizing concurrent access to email storage. Background Technology
[0002] When retrieving emails on a webpage, front-end developers often need to access email storage in parallel to retrieve various types of content, such as email content, email tags, and folder lists from the user's main email address. However, email access operations are typically performed on a single email storage instance, and the operating procedures strictly adhere to the principle of "connecting to the email storage, retrieving the folder, opening the folder, and closing the folder and storage after use." Therefore, when multiple requests access the emails, concurrency issues can arise, and some requests may fail to retrieve emails.
[0003] Even though backend developers can modify the code to merge the content of multiple requests into one request, the email access process will inevitably still have to be executed serially. Although the request can be successfully responded to, the response time will be significantly longer. Summary of the Invention
[0004] To address the aforementioned shortcomings, this invention proposes an optimization method and system for concurrent access to email storage. The purpose is to solve the problem that existing email access operations are usually performed on a single email storage, and that concurrency issues arise when multiple requests are made to access the email, as well as the problem of excessively long request response times after resolving the concurrency issues.
[0005] To achieve this objective, the present invention adopts the following technical solution:
[0006] An optimization method for concurrent access to email storage includes the following steps:
[0007] Step S1: Obtain email storage;
[0008] Step S2: Determine the connection status of the email storage. If the email storage is disconnected, determine the initialization status of the atomic operation counter of the email storage. If the email storage is connected, directly increment the connection count of the atoms.
[0009] Step S3: Retrieve the folder from the email storage;
[0010] Step S4: Determine the open status of the folder. If the folder is not open, determine the initialization status of the atomic operation counter of the folder. If the folder is open, directly increment the open count of the atomic operation counter.
[0011] Step S5: Receive the request and perform corresponding logical processing according to the type of the request;
[0012] Step S6: Close the folder and determine the folder's open status. If the folder is not open, subtract the number of open items from the atom. If the folder is open, subtract the number of open items from the atom and determine whether the result of the subtraction is less than or equal to 0. If so, close the folder.
[0013] Step S7: Close the email storage and determine if there is a request to connect to the email storage. If not, directly subtract the connection count from the atom, i.e., the request ends. If there is, subtract the connection count from the atom and determine if the result of the subtraction is less than or equal to 0. If so, disconnect the request from the email storage, i.e., the request ends.
[0014] Preferably, in step S2, if the email storage is in an unconnected state, the initialization state of the atomic operation counter of the email storage is determined, specifically including the following sub-steps:
[0015] If the atomic operation counter for email storage is uninitialized, then lock and initialize it.
[0016] In this process, requests that perform initialization atomically increment the value of the atomic operation counter to 1 and then execute the connection. Requests that do not perform initialization wait for the previous request to release the lock. When the next request acquires the lock, the value of the atomic operation counter has already been initialized, so the connection count is directly incremented atomically without executing any more connections.
[0017] Preferably, in step S4, if the folder is not open, the initialization state of the atomic operation counter of the folder is determined, specifically including the following sub-steps:
[0018] If the atomic operation counter of the folder is uninitialized, then lock and initialize it;
[0019] In this process, the request that performs initialization atomically increments the value of the atomic operation counter to 1 and performs the opening operation. Requests that do not perform initialization wait for the previous request to release the lock. When the next request acquires the lock, the value of the atomic operation counter has already been initialized, so the opening count is directly incremented and the opening operation is not performed again.
[0020] Another aspect of this application provides a system for optimizing concurrent access to email storage, the system comprising:
[0021] The first acquisition module is used to acquire email storage;
[0022] The first judgment module is used to determine the connection status of the email storage. If the email storage is not connected, the initialization status of the atomic operation counter of the email storage is determined; if the email storage is connected, the connection count is directly incremented on the atomic operation counter.
[0023] The second acquisition module is used to acquire a folder from the email storage;
[0024] The second judgment module is used to determine the open status of the folder. If the folder is not open, the initialization status of the atomic operation counter of the folder is determined; if the folder is open, the open count is directly incremented.
[0025] The receiving module is used to receive requests;
[0026] The logic processing module is used to perform corresponding logic processing according to the type of the request;
[0027] The third judgment module is used to close the folder and determine the open status of the folder. If the folder is not open, the number of open folders is directly subtracted from the number of open folders. If the folder is open, the number of open folders is subtracted from the number of open folders, and it is determined whether the result of the subtraction is less than or equal to 0. If so, the folder is closed.
[0028] The fourth judgment module is used to close the email storage and determine whether there is a request to connect to the email storage. If there is no request, the connection count is directly subtracted from the atom, i.e., the request ends. If there is a request, the connection count is subtracted from the atom, and it is determined whether the result of the subtraction is less than or equal to 0. If so, the request is disconnected from the email storage, i.e., the request ends.
[0029] Preferably, the first judgment module includes a first locking and initialization submodule, which is used to lock and initialize the atomic operation counter stored in the email if the atomic operation counter stored in the email is in an uninitialized state when judging the initialization state of the atomic operation counter stored in the email.
[0030] In this process, requests that perform initialization atomically increment the value of the atomic operation counter to 1 and then execute the connection. Requests that do not perform initialization wait for the previous request to release the lock. When the next request acquires the lock, the value of the atomic operation counter has already been initialized, so the connection count is directly incremented atomically without executing any more connections.
[0031] Preferably, the second judgment module includes a second locking and initialization submodule, which is used to lock and initialize the folder if the atomic operation counter of the folder is in an uninitialized state when judging the initialization state of the atomic operation counter of the folder.
[0032] In this process, the request that performs initialization atomically increments the value of the atomic operation counter to 1 and performs the opening operation. Requests that do not perform initialization wait for the previous request to release the lock. When the next request acquires the lock, the value of the atomic operation counter has already been initialized, so the opening count is directly incremented and the opening operation is not performed again.
[0033] The technical solutions provided in this application embodiment may include the following beneficial effects:
[0034] This solution utilizes atomic operation variables implemented with Atomic technology, ensuring secure concurrent email access under multi-threading without relying on the strict mechanism of serialization, while also reducing server response time dragged down by serialization. Furthermore, for the use of multiple domains, a lock segmentation mechanism is used to reduce frequent access to email storage, distributing access traffic across several resources and thereby improving concurrent access performance. Attached Figure Description
[0035] Figure 1 This is a flowchart illustrating the steps involved in optimizing concurrent access to email storage. Detailed Implementation
[0036] Embodiments of the present invention are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.
[0037] An optimization method for concurrent access to email storage includes the following steps:
[0038] Step S1: Obtain email storage;
[0039] Step S2: Determine the connection status of the email storage. If the email storage is disconnected, determine the initialization status of the atomic operation counter of the email storage. If the email storage is connected, directly increment the connection count of the atoms.
[0040] Step S3: Retrieve the folder from the email storage;
[0041] Step S4: Determine the open status of the folder. If the folder is not open, determine the initialization status of the atomic operation counter of the folder. If the folder is open, directly increment the open count of the atomic operation counter.
[0042] Step S5: Receive the request and perform corresponding logical processing according to the type of the request;
[0043] Step S6: Close the folder and determine the folder's open status. If the folder is not open, subtract the number of open items from the atom. If the folder is open, subtract the number of open items from the atom and determine whether the result of the subtraction is less than or equal to 0. If so, close the folder.
[0044] Step S7: Close the email storage and determine if there is a request to connect to the email storage. If not, directly subtract the connection count from the atom, i.e., the request ends. If there is, subtract the connection count from the atom and determine if the result of the subtraction is less than or equal to 0. If so, disconnect the request from the email storage, i.e., the request ends.
[0045] This solution offers one method for optimizing concurrent access to email storage, such as... Figure 1As shown, the first step is to obtain the email storage. Specifically, obtaining the email storage facilitates the subsequent retrieval of a specified folder from it. The second step is to determine the connection status of the email storage. If the email storage is not connected, the initialization status of its atomic operation counter is checked. If the email storage is connected, the connection count is directly incremented. Specifically, the email storage maintains its own shared state. If the email storage is not connected at this time, the atomic operation counter is checked to see if it has been initialized. The atomic operation counter is implemented based on Atomic technology and records how many requests are currently connecting to the email storage. Further explanation: the atomic operation class implemented by Atomic technology can control concurrent access to shared variables at the operating system level. Based on the CAS (Compare and Set) mechanism, it first obtains the current value, compares it with the value stored in physical memory, and if they are the same, atomically replaces the value; otherwise, it retryes. If the email storage connection is currently active, it means there's already a request connecting to and operating on the email. If another connection attempt is made, the email storage will throw an exception because it's already connected, causing the request to fail. Therefore, we can directly increment the connection count atomically. The connection count is an atomic operation counter based on Atomic technology, recording how many requests are currently connecting. The third step is to retrieve folders from the email storage, specifically folders such as Inbox, Drafts, and Deleted Items. The fourth step is to determine the folder's open status. If the folder is closed, the initialization status of the folder's atomic operation counter is checked; if the folder is open, the open count is directly incremented atomically. Specifically, each folder maintains its own shared state. If the folder is closed, the atomic operation counter is checked for initialization, recording how many requests are currently opening the folder. If the folder is open, the open count is directly incremented atomically. To further clarify, the open count is an atomic operation counter based on Atomic technology, recording how many requests are currently opening the folder. The fifth step is to receive the request and perform corresponding logical processing according to the type of the request. Specifically, since the folder is already open at this time, if the request type is to retrieve emails, then the operation of retrieving emails is performed; if the request type is to mark emails, then the operation of marking emails is performed; if the request type is to copy emails, then the operation of copying emails is performed.The sixth step is to close the folder and determine its open status. If the folder is not open, the open count is subtracted directly from the atomic count. If the folder is open, the open count is subtracted from the atomic count, and the result of the subtraction is checked to see if it is less than or equal to 0. If so, the folder is closed. Specifically, after the logic processing is completed, the folder needs to be closed, and its status needs to be checked. If the folder is closed, the open count is subtracted directly from the atomic count because it is accumulated with each request to open the folder. Even if the folder is closed, the consistency of the variable result still needs to be ensured, so the subtraction is necessary. If the folder is open, the open count is subtracted from the atomic count first, and then the result of the subtraction is checked to see if it is less than or equal to 0. If it is less than or equal to 0, it means that other requests have been completed, and the request with a slightly later completion time will perform the folder closing operation. The seventh step is to close the email storage and determine if there are any requests to connect to it. If not, the connection count is directly subtracted from the atomic value, indicating the request ends. If there are requests, the connection count is subtracted from the atomic value, and the result is checked to see if it is less than or equal to 0. If it is, the request is disconnected from the email storage, indicating the request ends. Specifically, when the folder is closed, the email storage needs to be closed to further terminate the request. To further explain, when there is a request to connect to the email storage, the connection count is first subtracted from the atomic value, and then the result is checked to see if it is less than or equal to 0. If it is less than or equal to 0, it means that other requests have already completed, and the request with the slightly later completion time will perform the disconnection operation.
[0046] This solution utilizes atomic operation variables implemented with Atomic technology, ensuring secure concurrent email access under multi-threading without relying on the strict mechanism of serialization, while also reducing server response time dragged down by serialization. Furthermore, for the use of multiple domains, a lock segmentation mechanism is used to reduce frequent access to email storage, distributing access traffic across several resources and thereby improving concurrent access performance.
[0047] Preferably, in step S2, if the email storage is in an unconnected state, the initialization state of the atomic operation counter of the email storage is determined, specifically including the following sub-steps:
[0048] If the atomic operation counter for email storage is uninitialized, then lock and initialize it.
[0049] In this process, requests that perform initialization atomically increment the value of the atomic operation counter to 1 and then execute the connection. Requests that do not perform initialization wait for the previous request to release the lock. When the next request acquires the lock, the value of the atomic operation counter has already been initialized, so the connection count is directly incremented atomically without executing any more connections.
[0050] In this embodiment, the reason for locking the atomic operation counter of the email storage in an uninitialized state is that the variable value of the atomic operation counter of the email storage is not initialized. If it is initialized concurrently, the atomic operation counter will be continuously initialized and overwritten, and atomicity cannot be guaranteed. Requests that have not undergone initialization will not attempt to connect. If a connection is attempted again, the email storage will already be connected, and the email storage will throw an exception, causing the request to fail.
[0051] Preferably, in step S4, if the folder is not open, the initialization state of the atomic operation counter of the folder is determined, specifically including the following sub-steps:
[0052] If the atomic operation counter of the folder is uninitialized, then lock and initialize it;
[0053] In this process, the request that performs initialization atomically increments the value of the atomic operation counter to 1 and performs the opening operation. Requests that do not perform initialization wait for the previous request to release the lock. When the next request acquires the lock, the value of the atomic operation counter has already been initialized, so the opening count is directly incremented and the opening operation is not performed again.
[0054] The reason for locking the atomic operation counters of uninitialized folders is that the variable values of these counters are not initialized. If they are initialized concurrently, the atomic operation counters will be continuously initialized and overwritten, compromising atomicity. Requests that haven't undergone initialization will not be opened. If the folder is opened again, it will already be open, causing an exception to be thrown and resulting in the request failing.
[0055] This application, in another aspect, provides an email storage concurrent access optimization system, the system comprising:
[0056] The first acquisition module is used to acquire email storage;
[0057] The first judgment module is used to determine the connection status of the email storage. If the email storage is not connected, the initialization status of the atomic operation counter of the email storage is determined; if the email storage is connected, the connection count is directly incremented on the atomic operation counter.
[0058] The second acquisition module is used to acquire a folder from the email storage;
[0059] The second judgment module is used to determine the open status of the folder. If the folder is not open, the initialization status of the atomic operation counter of the folder is determined; if the folder is open, the open count is directly incremented.
[0060] The receiving module is used to receive requests;
[0061] The logic processing module is used to perform corresponding logic processing according to the type of the request;
[0062] The third judgment module is used to close the folder and determine the open status of the folder. If the folder is not open, the number of open folders is directly subtracted from the number of open folders. If the folder is open, the number of open folders is subtracted from the number of open folders, and it is determined whether the result of the subtraction is less than or equal to 0. If so, the folder is closed.
[0063] The fourth judgment module is used to close the email storage and determine whether there is a request to connect to the email storage. If there is no request, the connection count is directly subtracted from the atom, i.e., the request ends. If there is a request, the connection count is subtracted from the atom, and it is determined whether the result of the subtraction is less than or equal to 0. If so, the request is disconnected from the email storage, i.e., the request ends.
[0064] This solution is an optimized system for concurrent access to email storage. Through the cooperation of a first acquisition module, a first judgment module, a second acquisition module, a second judgment module, a receiving module, a logic processing module, a third judgment module, and a fourth judgment module, it achieves the goal of ensuring safe concurrent email access under multi-threading without using a strict serialization mechanism. At the same time, it reduces the server response time that is lengthened due to serialization. Furthermore, for the use of multiple domains, it reduces the frequency of access to email storage based on a lock segmentation mechanism, distributing the access volume across several resources, thereby improving the performance of concurrent access.
[0065] Preferably, the first judgment module includes a first locking and initialization submodule. The first locking and initialization submodule is used to lock and initialize the atomic operation counter stored in the email if the atomic operation counter stored in the email is in an uninitialized state when judging the initialization state of the atomic operation counter stored in the email.
[0066] In this process, requests that perform initialization atomically increment the value of the atomic operation counter to 1 and then execute the connection. Requests that do not perform initialization wait for the previous request to release the lock. When the next request acquires the lock, the value of the atomic operation counter has already been initialized, so the connection count is directly incremented atomically without executing any more connections.
[0067] In this embodiment, the reason for locking the atomic operation counter of the email storage in an uninitialized state is that the variable value of the atomic operation counter of the email storage is not initialized. If it is initialized concurrently, the atomic operation counter will be continuously initialized and overwritten, and atomicity cannot be guaranteed. Requests that have not undergone initialization will not attempt to connect. If a connection is attempted again, the email storage will already be connected, and the email storage will throw an exception, causing the request to fail.
[0068] Preferably, the second judgment module includes a second locking and initialization submodule, which is used to lock and initialize the folder if the atomic operation counter of the folder is in an uninitialized state when judging the initialization state of the atomic operation counter of the folder.
[0069] In this process, the request that performs initialization atomically increments the value of the atomic operation counter to 1 and performs the opening operation. Requests that do not perform initialization wait for the previous request to release the lock. When the next request acquires the lock, the value of the atomic operation counter has already been initialized, so the opening count is directly incremented and the opening operation is not performed again.
[0070] The reason for locking the atomic operation counters of uninitialized folders is that the variable values of these counters are not initialized. If they are initialized concurrently, the atomic operation counters will be continuously initialized and overwritten, compromising atomicity. Requests that haven't undergone initialization will not be opened. If the folder is opened again, it will already be open, causing an exception to be thrown and resulting in the request failing.
[0071] Furthermore, the functional units in the various embodiments of the present invention can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.
[0072] Although embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present invention. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of the present invention.
Claims
1. A method for optimizing concurrent access to email storage, characterized in that: Includes the following steps: Step S1: Retrieve email storage; Step S2: Determine the connection status of the email storage. If the email storage is disconnected, determine the initialization status of the atomic operation counter of the email storage. If the email storage is connected, directly increment the connection count of the atoms. Step S3: Retrieve the folder from the email storage; Step S4: Determine the open status of the folder. If the folder is not open, determine the initialization status of the atomic operation counter of the folder. If the folder is open, directly increment the open count of the atomic operation counter. Step S5: Receive the request and perform corresponding logical processing according to the type of the request; Step S6: Close the folder and determine the folder's open status. If the folder is not open, subtract the number of open items from the atom. If the folder is open, subtract the number of open items from the atom and determine whether the result of the subtraction is less than or equal to 0. If so, close the folder. Step S7: Close the email storage and determine if there is a request to connect to the email storage. If not, directly subtract the connection count from the atom, i.e., the request ends. If there is, subtract the connection count from the atom and determine if the result of the subtraction is less than or equal to 0. If so, disconnect the request from the email storage, i.e., the request ends.
2. The method for optimizing concurrent access to email storage according to claim 1, characterized in that: In step S2, if the email storage is in an unconnected state, the initialization state of the atomic operation counter of the email storage is determined, specifically including the following sub-steps: If the atomic operation counter for email storage is uninitialized, then lock and initialize it. In this process, requests that perform initialization atomically increment the value of the atomic operation counter to 1 and then execute the connection. Requests that do not perform initialization wait for the previous request to release the lock. When the next request acquires the lock, the value of the atomic operation counter has already been initialized, so the connection count is directly incremented atomically without executing any more connections.
3. The method for optimizing concurrent access to email storage according to claim 1, characterized in that: In step S4, if the folder is not open, the initialization state of the atomic operation counter of the folder is determined, specifically including the following sub-steps: If the atomic operation counter of the folder is uninitialized, then lock and initialize it; In this process, the request that performs initialization atomically increments the value of the atomic operation counter to 1 and performs the opening operation. Requests that do not perform initialization wait for the previous request to release the lock. When the next request acquires the lock, the value of the atomic operation counter has already been initialized, so the opening count is directly incremented and the opening operation is not performed again.
4. A system for optimizing concurrent access to email storage, characterized in that: The system, using the email storage concurrency access optimization method as described in any one of claims 1-3, comprises: The first acquisition module is used to acquire email storage; The first judgment module is used to determine the connection status of the email storage. If the email storage is not connected, the initialization status of the atomic operation counter of the email storage is determined; if the email storage is connected, the connection count is directly incremented on the atomic operation counter. The second acquisition module is used to acquire a folder from the email storage; The second judgment module is used to determine the open status of the folder. If the folder is not open, the initialization status of the atomic operation counter of the folder is determined; if the folder is open, the open count is directly incremented. The receiving module is used to receive requests; The logic processing module is used to perform corresponding logic processing according to the type of the request; The third judgment module is used to close the folder and determine the open status of the folder. If the folder is not open, the number of open folders is directly subtracted from the number of open folders. If the folder is open, the number of open folders is subtracted from the number of open folders, and it is determined whether the result of the subtraction is less than or equal to 0. If so, the folder is closed. The fourth judgment module is used to close the email storage and determine whether there is a request to connect to the email storage. If there is no request, the connection count is directly subtracted from the atom, i.e., the request ends. If there is a request, the connection count is subtracted from the atom, and it is determined whether the result of the subtraction is less than or equal to 0. If so, the request is disconnected from the email storage, i.e., the request ends.
5. The email storage and concurrent access optimization system according to claim 4, characterized in that: The first judgment module includes a first locking and initialization submodule. The first locking and initialization submodule is used to lock and initialize the atomic operation counter stored in the email if the atomic operation counter stored in the email is in an uninitialized state when judging the initialization state of the atomic operation counter stored in the email. In this process, requests that perform initialization atomically increment the value of the atomic operation counter to 1 and then execute the connection. Requests that do not perform initialization wait for the previous request to release the lock. When the next request acquires the lock, the value of the atomic operation counter has already been initialized, so the connection count is directly incremented atomically without executing any more connections.
6. The email storage concurrent access optimization system according to claim 4, characterized in that: The second judgment module includes a second locking and initialization submodule. The second locking and initialization submodule is used to lock and initialize the folder if the atomic operation counter of the folder is in an uninitialized state when judging the initialization state of the atomic operation counter of the folder. In this process, the request that performs initialization atomically increments the value of the atomic operation counter to 1 and performs the opening operation. Requests that do not perform initialization wait for the previous request to release the lock. When the next request acquires the lock, the value of the atomic operation counter has already been initialized, so the opening count is directly incremented and the opening operation is not performed again.