Method and system for optimizing throughput of an electronic mailbox
By optimizing email throughput through a multi-threaded processing model and event queues, the problem of single-threaded models being unable to support high throughput is solved, enabling efficient automatic replies and automatic forwarding, and reducing useless requests and network overhead.
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-07-21
Smart Images

Figure CN116723168B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the technical field of email reply and forwarding, and in particular to a method and system for optimizing email throughput. Background Technology
[0002] Auto-reply and auto-forwarding have extremely high real-time requirements. For example, in auto-reply and auto-forwarding scenarios, once a new email is placed in a user's main mailbox, it needs to be replied to and forwarded quickly. However, most existing implementations use a single-threaded model to scan emails in the user's main mailbox and reply to or forward them. A single thread cannot support the high throughput of auto-reply and auto-forwarding emails. Moreover, in obtaining the list of users who have enabled auto-reply and auto-forwarding settings, an active request to update the user list is required after each processing session. If the number of users with these settings enabled does not change frequently, then some requests waste performance. Summary of the Invention
[0003] To address the aforementioned shortcomings, this invention proposes a method and system for optimizing email throughput. The purpose is to solve the problems of existing single-threaded models being unable to support automatic replies and forwarding of emails with high throughput, as well as the excessive number of useless requests generated when retrieving the list of users who have enabled automatic replies and forwarding settings.
[0004] To achieve this objective, the present invention adopts the following technical solution:
[0005] An email throughput optimization method includes the following steps:
[0006] Step S1: Create an event queue, a puller thread, an event listener set containing multiple producer threads, a queue set containing multiple queues, and multiple consumer threads, and initialize each of them.
[0007] Step S2: Set up new events and add them to the event queue. New events include automatic replies and automatic forwarding.
[0008] Step S3: Start the Puller thread;
[0009] Step S4: Scan multiple producer threads in the event listener set and notify multiple producer threads to pull the corresponding user list;
[0010] Step S5: Based on the corresponding user list, obtain the corresponding user information and other information;
[0011] Step S6: Construct the corresponding request based on the corresponding user information and other information;
[0012] Step S7: Calculate the hash value for each producer thread using the user's unique identifier and a hash algorithm;
[0013] Step S8: Perform a bitwise AND operation between the hash value of each producer thread and the length of the queue set minus 1 to obtain multiple result values;
[0014] Step S9: Based on each result value, retrieve the corresponding queue from the queue set and place the corresponding request into the corresponding queue;
[0015] Step S10: Perform corresponding logical processing based on the type of each request.
[0016] Preferably, in step S1, the initialization settings specifically include the following sub-steps:
[0017] Step S11: Initialize the event queue;
[0018] Step S12: Initialize the Puller thread, bind the event queue, and listen for events;
[0019] Step S13: Initialize the event listener set, which is used to store threads that subscribe to user setting change events;
[0020] Step S14: Initialize a specific number of producer threads and put the event listener set into the producer threads;
[0021] Step S15: Retrieve the list of users who have set the enable option from the database and put the user list into the user list collection, where each producer thread has one user list;
[0022] Step S16: Initialize a specific number of queues and a corresponding number of consumer threads. Each consumer thread binds to a queue and puts the queue into the queue set.
[0023] Preferably, in step S16, the size of the queue is 2. n , where n is a positive integer.
[0024] Another aspect of this application provides an email throughput optimization system, the system comprising:
[0025] The creation module is used to create event queues, puller threads, a collection of event listeners containing multiple producer threads, a collection of queues containing multiple queues, and multiple consumer threads.
[0026] The initialization settings module is used to initialize the event queue, the Puller thread, the event listener set containing multiple producer threads, the queue set containing multiple queues, and the multiple consumer threads.
[0027] The settings module is used to set new events;
[0028] The first storage module is used to put new events into the event queue. New events include automatic replies and automatic forwarding.
[0029] The startup module is used to start the Puller thread;
[0030] The scanning module is used to scan multiple producer threads in the event listener set;
[0031] The notification module is used to notify multiple producer threads to retrieve the corresponding user list;
[0032] The first acquisition module is used to acquire corresponding user information and other information based on the corresponding user list;
[0033] The construction module is used to build the corresponding request based on the corresponding user information and other information;
[0034] The first calculation module is used to calculate the hash value of each producer thread using the user's unique identifier and a hash algorithm;
[0035] The second calculation module is used to perform a bitwise AND operation between the hash value of each producer thread and the length of the queue set minus 1, to obtain multiple result values;
[0036] The second acquisition module is used to retrieve the corresponding queue from the queue set based on each result value.
[0037] The second storage module is used to put the corresponding request into the corresponding queue;
[0038] The logic processing module is used to perform corresponding logical processing based on the type of each request.
[0039] Preferably, the initialization setting module includes:
[0040] The first initialization submodule is used to initialize the event queue;
[0041] The second initialization submodule is used to initialize the Puller thread, bind the event queue, and listen for events.
[0042] The third initialization submodule is used to initialize the event listener set, which is used to store the threads that subscribe to user setting change events;
[0043] The fourth initialization submodule is used to initialize a specific number of producer threads and put the event listener set into the producer threads;
[0044] The pull submodule is used to pull a list of users who have the enabled option set from the database and put the user list into a user list collection, where each producer thread has its own user list;
[0045] The fifth initialization submodule is used to initialize a specific number of queues and the corresponding number of consumer threads. Each consumer thread is bound to a queue and puts the queue into the queue set.
[0046] Preferably, in the fifth initialization submodule, the size of the queue is 2. n , where n is a positive integer.
[0047] The technical solutions provided in this application embodiment may include the following beneficial effects:
[0048] This solution replaces the traditional single-threaded processing model with a multi-producer, multi-consumer multi-threaded processing model. The multi-threaded processing model can support automatic reply and automatic forwarding of high-throughput emails. Furthermore, in the execution of logic, the asynchronous event-driven model reduces useless requests, thereby reducing excessive network overhead. Attached Figure Description
[0049] Figure 1 This is a flowchart illustrating the steps involved in optimizing email throughput. Detailed Implementation
[0050] 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.
[0051] An email throughput optimization method includes the following steps:
[0052] Step S1: Create an event queue, a puller thread, an event listener set containing multiple producer threads, a queue set containing multiple queues, and multiple consumer threads, and initialize each of them.
[0053] Step S2: Set up new events and add them to the event queue. New events include automatic replies and automatic forwarding.
[0054] Step S3: Start the Puller thread;
[0055] Step S4: Scan multiple producer threads in the event listener set and notify multiple producer threads to pull the corresponding user list;
[0056] Step S5: Based on the corresponding user list, obtain the corresponding user information and other information;
[0057] Step S6: Construct the corresponding request based on the corresponding user information and other information;
[0058] Step S7: Calculate the hash value for each producer thread using the user's unique identifier and a hash algorithm;
[0059] Step S8: Perform a bitwise AND operation between the hash value of each producer thread and the length of the queue set minus 1 to obtain multiple result values;
[0060] Step S9: Based on each result value, retrieve the corresponding queue from the queue set and place the corresponding request into the corresponding queue;
[0061] Step S10: Perform corresponding logical processing based on the type of each request.
[0062] This solution offers a method for optimizing email throughput, such as... Figure 1As shown, the first step is to create an event queue, a Puller thread, an event listener set containing multiple producer threads, a queue set containing multiple queues, and multiple consumer threads, and perform initialization on each of them. Specifically, initializing the event queue, Puller thread, event listener set containing multiple producer threads, queue set containing multiple queues, and consumer threads helps avoid data corruption and program vulnerabilities, preparing for the execution of subsequent steps. The second step is to set new events and add them to the event queue. New events include automatic replies and automatic forwarding. Specifically, adding automatic reply and automatic forwarding requests to the event queue allows for priority processing of requests at the front of the queue. The third step is to start the Puller thread. Specifically, the Puller thread is used to receive user setting change events and distribute these events to the subscribers who have subscribed to the event. When the event queue is empty, the Puller thread is blocked; when the event queue has events, the Puller thread starts and listens. The fourth step is to scan the multiple producer threads in the event listener set and notify the multiple producer threads to pull the corresponding user lists. In this embodiment, multiple producer threads are used to support high-throughput emails. Specifically, each producer thread retrieves a list of users who have set options from the database, and each producer thread has its own user list. When a new user setting operation is triggered, such as user A disabling auto-reply, the Puller thread retrieves the change event for user A's settings from the event queue, i.e., user A disabling auto-reply, and loops through the producer threads in the listener set, sending the event. When a producer thread receives this event, it updates its user list, removing user A from the list. Therefore, the producer will not execute user A's auto-reply task; this process is asynchronous. The fifth step is to obtain the corresponding user information and other information based on the corresponding user list. Specifically, obtaining the corresponding user information and other information is beneficial for constructing subsequent requests. The sixth step is to construct the corresponding request based on the corresponding user information and other information. Specifically, each user has a corresponding request; for example, if user B intends to automatically forward emails, they will submit an auto-forwarding request. The seventh step is to use the user's unique identifier and a hash algorithm to calculate the hash value of each producer thread. Specifically, the user's unique identifier is usually the user number. Hash algorithms generally refer to the SHA family, which are algorithms that can calculate a fixed-length string corresponding to a numerical message. In this embodiment, the character value at each position of the user ID is multiplied by 29 (if the user ID contains letters or other special characters, the decimal value of the corresponding character can be obtained by referring to the ASCII encoding table), and finally the values at each position are added together to obtain the result value, which is the hash value. The eighth step is to perform a bitwise AND operation between the hash value of each producer thread and the length of the queue set minus 1, to obtain multiple result values.In one embodiment, when the user ID `userld` is 16 and the queue size `queues.size` is 16, the hash value of the producer thread `h` = `hash(userld)` = 1 * 29 + 6 * 29 = 203. Then, a bitwise AND operation is performed between the hash value `h` of the producer thread and the queue size `queues.size` minus 1, i.e., `h&(queues.size-1) = 203&(16-1) = 11`, resulting in a value of 11. By performing a bitwise AND operation between the hash value of each producer thread and the queue size `queues.size` minus 1, different result values can be obtained, reducing the possibility of result collisions. The ninth step is to retrieve the corresponding queue from the queue set based on each result value and place the corresponding request into the corresponding queue. Specifically, since each result value is different, this not only reduces result collisions but also allows requests to be distributed across multiple queues, achieving a distribution effect and supporting high-throughput emails. The tenth step is to perform corresponding logical processing based on the type of each request. Specifically, multiple consumer threads retrieve requests from their respective queues and perform corresponding logical processing based on the request type. For example, automatic reply will be processed according to the logic of automatic reply, and automatic forwarding will be processed according to the logic of automatic forwarding.
[0063] This solution replaces the traditional single-threaded processing model with a multi-producer, multi-consumer multi-threaded processing model. The multi-threaded processing model can support automatic reply and automatic forwarding of high-throughput emails. Furthermore, in the execution of logic, the asynchronous event-driven model reduces useless requests, thereby reducing excessive network overhead.
[0064] Preferably, in step S1, the initialization settings specifically include the following sub-steps:
[0065] Step S11: Initialize the event queue;
[0066] Step S12: Initialize the Puller thread, bind the event queue, and listen for events;
[0067] Step S13: Initialize the event listener set, which is used to store threads that subscribe to user setting change events;
[0068] Step S14: Initialize a specific number of producer threads and put the event listener set into the producer threads;
[0069] Step S15: Retrieve the list of users who have set the enable option from the database and put the user list into the user list collection, where each producer thread has one user list;
[0070] Step S16: Initialize a specific number of queues and a corresponding number of consumer threads. Each consumer thread binds to a queue and puts the queue into the queue set.
[0071] In this embodiment, in step S12, since the Puller thread is bound to the event queue, the Puller thread is blocked when there are no events in the event queue; when there are events in the event queue, the Puller thread starts and listens. In step S13, the event listener set is used to store threads that subscribe to user setting change events. User setting change events refer to changes made by users on their email personal settings page to the automatic reply and automatic forwarding settings or policies, such as turning automatic reply or automatic forwarding on / off, or changing the handling of emails after automatic forwarding, such as keeping forwarded emails in the mailbox or deleting them. In step S14, a specific number of producer threads are initialized, and the event listener set is placed into the producer threads, which is beneficial for the unified management of multiple producer threads. In this embodiment, the number of producer threads is 4. In step S15, the database is the existing system database, which stores information about several users. Users who have enabled automatic reply and automatic forwarding settings are retrieved from the database and a user list is formed. In step S16, a specific number of queues and corresponding number of consumers are initialized. Each consumer is bound to a queue and the queue is put into the queue set. This facilitates the unified management of multiple queues. In this embodiment, the number of queues and consumers is 8.
[0072] Preferably, in step S16, the size of the queue is 2. n n is a positive integer. In this embodiment, the size of the queue must be guaranteed to be 2^n. n One reason is that bitwise operations are more efficient for computers, assuming the queue size is 2. 4 If we directly perform the modulo operation (%), it is based on decimal calculation, while bitwise operations are based on binary calculation. This eliminates the cost of forwarding between number systems, thus improving efficiency. On the other hand, in subsequent steps, when using a hash algorithm, bitwise operations are performed between the result value and the length of the queue set minus 1, resulting in different values and reducing the chance of result collisions.
[0073] Another aspect of this application provides an email throughput optimization system, the system comprising:
[0074] The creation module is used to create event queues, puller threads, a collection of event listeners containing multiple producer threads, a collection of queues containing multiple queues, and multiple consumer threads.
[0075] The initialization settings module is used to initialize the event queue, the Puller thread, the event listener set containing multiple producer threads, the queue set containing multiple queues, and the multiple consumer threads.
[0076] The settings module is used to set new events;
[0077] The first storage module is used to put new events into the event queue. New events include automatic replies and automatic forwarding.
[0078] The startup module is used to start the Puller thread;
[0079] The scanning module is used to scan multiple producer threads in the event listener set;
[0080] The notification module is used to notify multiple producer threads to retrieve the corresponding user list;
[0081] The first acquisition module is used to acquire corresponding user information and other information based on the corresponding user list;
[0082] The construction module is used to build the corresponding request based on the corresponding user information and other information;
[0083] The first calculation module is used to calculate the hash value of each producer thread using the user's unique identifier and a hash algorithm;
[0084] The second calculation module is used to perform a bitwise AND operation between the hash value of each producer thread and the length of the queue set minus 1, to obtain multiple result values;
[0085] The second acquisition module is used to retrieve the corresponding queue from the queue set based on each result value.
[0086] The second storage module is used to put the corresponding request into the corresponding queue;
[0087] The logic processing module is used to perform corresponding logical processing based on the type of each request.
[0088] This solution provides an email throughput optimization system that, through the cooperation of a creation module, an initialization setting module, a setting module, a first storage module, a startup module, a scanning module, a notification module, a first acquisition module, a construction module, a first calculation module, a second calculation module, a second acquisition module, a second storage module, and a logic processing module, handles automatic email replies and automatic forwarding.
[0089] This solution replaces the traditional single-threaded processing model with a multi-producer, multi-consumer multi-threaded processing model. The multi-threaded processing model can support automatic reply and automatic forwarding of high-throughput emails. Furthermore, in the execution of logic, the asynchronous event-driven model reduces useless requests, thereby reducing excessive network overhead.
[0090] Preferably, the initialization setting module includes:
[0091] The first initialization submodule is used to initialize the event queue;
[0092] The second initialization submodule is used to initialize the Puller thread, bind the event queue, and listen for events.
[0093] The third initialization submodule is used to initialize the event listener set, which is used to store the threads that subscribe to user setting change events;
[0094] The fourth initialization submodule is used to initialize a specific number of producer threads and put the event listener set into the producer threads;
[0095] The pull submodule is used to pull a list of users who have the enabled option set from the database and put the user list into a user list collection, where each producer thread has its own user list;
[0096] The fifth initialization submodule is used to initialize a specific number of queues and the corresponding number of consumer threads. Each consumer thread is bound to a queue and puts the queue into the queue set.
[0097] In this embodiment, in the second initialization submodule, since the Puller thread is bound to the event queue, the Puller thread is blocked when there are no events in the event queue; when there are events in the event queue, the Puller thread starts and listens. In the third initialization submodule, the event listener set is used to store threads that subscribe to user setting change events. User setting change events refer to changes made by users on their email personal settings page to the automatic reply and automatic forwarding settings or policies, such as turning automatic reply or automatic forwarding on / off, or changing the handling of emails after automatic forwarding, such as keeping forwarded emails in the mailbox or deleting them. In the fourth initialization submodule, a specific number of producer threads are initialized, and the event listener set is placed in the producer threads, which is beneficial for the unified management of multiple producer threads. In this embodiment, the number of producer threads is 4. In the pull submodule, the database is the existing system database, which stores information about several users. Users who have enabled automatic reply and automatic forwarding settings are pulled from the database and a user list is formed. In the fifth initialization submodule, a specific number of queues and corresponding number of consumers are initialized. Each consumer is bound to a queue and the queue is put into the queue set. This facilitates the unified management of multiple queues. In this embodiment, the number of queues and consumers is 8.
[0098] Preferably, in the fifth initialization submodule, the size of the queue is 2. n n is a positive integer. In this embodiment, the size of the queue must be guaranteed to be 2^n. n One reason is that bitwise operations are more efficient for computers, assuming the queue size is 2. 4 If we directly perform the modulo operation (%), it is based on decimal calculation, while bitwise operations are based on binary calculation. This eliminates the cost of forwarding between number systems, thus improving efficiency. On the other hand, in subsequent steps, when using a hash algorithm, bitwise operations are performed between the result value and the length of the queue set minus 1, resulting in different values and reducing the chance of result collisions.
[0099] 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.
[0100] 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 the throughput of an email account, characterized in that: Includes the following steps: Step S1: Create an event queue, a puller thread, an event listener set containing multiple producer threads, a queue set containing multiple queues, and multiple consumer threads, and initialize each of them. Step S2: Set up new events and add them to the event queue. New events include automatic replies and automatic forwarding. Step S3: Start the Puller thread; Step S4: Scan multiple producer threads in the event listener set and notify multiple producer threads to pull the corresponding user list; Step S5: Based on the corresponding user list, obtain the corresponding user information and other information; Step S6: Construct the corresponding request based on the corresponding user information and other information; Step S7: Calculate the hash value for each producer thread using the user's unique identifier and a hash algorithm; Step S8: Perform a bitwise AND operation between the hash value of each producer thread and the length of the queue set minus 1 to obtain multiple result values; Step S9: Based on each result value, retrieve the corresponding queue from the queue set and place the corresponding request into the corresponding queue; Step S10: Perform corresponding logical processing based on the type of each request.
2. The method for optimizing the throughput of an email account according to claim 1, characterized in that: In step S1, the initialization settings specifically include the following sub-steps: Step S11: Initialize the event queue; Step S12: Initialize the Puller thread, bind the event queue, and listen for events; Step S13: Initialize the event listener set, which is used to store threads that subscribe to user setting change events; Step S14: Initialize 4 producer threads and put the event listener set into the producer threads; Step S15: Retrieve the list of users who have set the enable option from the database and put the user list into the user list collection, where each producer thread has one user list; Step S16: Initialize 8 queues and 8 consumer threads. Each consumer thread binds to a queue and puts the queue into the queue set.
3. The method for optimizing the throughput of an email account according to claim 2, characterized in that: In step S16, the size of the queue is , where n is a positive integer.
4. An email throughput optimization system, characterized in that: Using the email throughput optimization method as described in any one of claims 1-3, the system comprises: The creation module is used to create event queues, puller threads, a collection of event listeners containing multiple producer threads, a collection of queues containing multiple queues, and multiple consumer threads. The initialization settings module is used to initialize the event queue, the Puller thread, the event listener set containing multiple producer threads, the queue set containing multiple queues, and the multiple consumer threads. The settings module is used to set new events; The first storage module is used to put new events into the event queue. New events include automatic replies and automatic forwarding. The startup module is used to start the Puller thread; The scanning module is used to scan multiple producer threads in the event listener set; The notification module is used to notify multiple producer threads to retrieve the corresponding user list; The first acquisition module is used to acquire corresponding user information and other information based on the corresponding user list; The construction module is used to build the corresponding request based on the corresponding user information and other information; The first calculation module is used to calculate the hash value of each producer thread using the user's unique identifier and a hash algorithm; The second calculation module is used to perform a bitwise AND operation between the hash value of each producer thread and the length of the queue set minus 1, to obtain multiple result values; The second acquisition module is used to retrieve the corresponding queue from the queue set based on each result value. The second storage module is used to put the corresponding request into the corresponding queue; The logic processing module is used to perform corresponding logical processing based on the type of each request.
5. The email throughput optimization system according to claim 4, characterized in that: The initialization setting module includes: The first initialization submodule is used to initialize the event queue; The second initialization submodule is used to initialize the Puller thread, bind the event queue, and listen for events. The third initialization submodule is used to initialize the event listener set, which is used to store the threads that subscribe to user setting change events; The fourth initialization submodule is used to initialize the four producer threads and put the event listener set into the producer threads; The pull submodule is used to pull a list of users who have the enabled option set from the database and put the user list into a user list collection, where each producer thread has its own user list; The fifth initialization submodule is used to initialize 8 queues and 8 consumer threads. Each consumer thread binds to a queue and puts the queue into the queue set.
6. The email throughput optimization system according to claim 5, characterized in that: In the fifth initialization submodule, the size of the queue is , where n is a positive integer.