Instant messaging message storage method, device, equipment and computer readable medium
By building a cache layer and an asynchronous task pool on the instant messaging server, the writes of instant messaging messages are asynchronously spread to multiple client caches, solving the problem of large performance consumption of group messages synchronous storage and improving message storage and query response speed.
Patent Information
- Application Number
- CN202111160494.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-30
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2041-09-30
AI Technical Summary
In the instant messaging scenario where multiple users participate in large group chats, the synchronous storage performance of group messages consumes a lot, resulting in a reduced storage and query response speed of instant messaging messages.
By building a cache layer and an asynchronous task pool on the server, the instant messaging messages are not directly stored in the database, but the message writing is asynchronously spreads the message writing into the corresponding caches of multiple instant messaging clients.
It reduces the performance requirements of the server, reduces the number of visits to the server central server, improves the storage and query response speed of instant messaging messages, and solves the problem of high performance consumption of synchronous storage of group messages.
Smart Images

Figure CN113886494B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet technology, and in particular to a message storage method, device, equipment and computer-readable medium for instant messaging. Background Art
[0002] Instant Messaging (IM) is a real-time communication system that allows two or more people to use the Internet to transmit text messages, files, voice and video in real time. The real-time requirements of the instant messaging system are very high, so the performance requirements for the server are also extremely high. However, in the related art, the server of the instant messaging system directly stores the instant messaging messages in the database, and the frequency of read and write operations on the database is extremely high. Limited by the performance bottleneck, in the instant messaging scenario with multiple users participating in large group chats, since the group messages need to be synchronized to each participating end, the synchronous storage performance of the group messages consumes a lot, and the storage and query response speed of the instant messaging messages are reduced.
[0003] Currently, no effective solution has been proposed to the problem of high performance consumption of synchronous storage of group messages. Summary of the invention
[0004] The present application provides a method, device, equipment and computer-readable medium for storing instant messaging messages to solve the technical problem of high performance consumption of synchronous storage of group messages.
[0005] According to one aspect of an embodiment of the present application, the present application provides a message storage method for instant messaging, which is applied to a server, comprising:
[0006] When the first process receives a target message, the target message is stored in a first cache, and a distributed storage task of the target message is created in an asynchronous task pool, wherein the target message is an instant messaging message sent by an instant messaging client in a target group, and the first process is used to receive the instant messaging message;
[0007] When the second process detects the presence of a distributed storage task in the asynchronous task pool, the target message in the first cache is saved to multiple second caches, wherein the second cache is a cache corresponding to multiple instant messaging clients in the target group, one instant messaging client corresponds to one second cache, and the second cache is used for the corresponding instant messaging client to read the target message from the second cache according to the message receiving instruction.
[0008] Optionally, when the first process receives the target message, storing the target message in the first cache, and creating a distributed storage task of the target message in the asynchronous task pool specifically includes:
[0009] When the first process receives the target message, the target message is stored in the first cache;
[0010] After receiving a message that the target message is successfully stored in the first cache, creating a distributed storage task for the target message in the asynchronous task pool;
[0011] After receiving a message indicating that the target message fails to be stored in the first cache, the distributed storage task of creating the target message in the asynchronous task pool is abandoned.
[0012] Optionally, saving the target message in the first cache to the plurality of second caches includes saving the target message to one second cache in the following manner:
[0013] Reading a target message from a first buffer;
[0014] Extract the message body and identification mark of the target message, wherein the message body is a data structure for storing instant messaging messages on the server side;
[0015] The identification mark is pushed into the unread message queue and the historical message queue in the second cache, and the identification mark and the message body mapping are stored in the second cache.
[0016] Optionally, after pushing the identification mark into the unread message queue and the historical message queue in the second cache, and storing the identification mark and the message body mapping in the second cache, the method further includes:
[0017] Push the identification mark and message body of the target message into the backend message queue;
[0018] When the third process monitors the identification mark and the message body of the target message from the backend message queue, the identification mark and the message body of the target message are mapped and stored in the backend database.
[0019] Optionally, after pushing the identification mark into the unread message queue and the historical message queue in the second cache, and storing the identification mark and the message body mapping in the second cache, the method further includes:
[0020] When read confirmation information of the target message is received, the identification mark of the target message is pushed out of the unread message queue of the second cache, wherein the read confirmation information is sent by the instant messaging client corresponding to the second cache after reading the target message from the second cache.
[0021] Optionally, after pushing the identification mark into the unread message queue and the historical message queue in the second cache, and storing the identification mark and the message body mapping in the second cache, the method further includes:
[0022] Upon receiving a message query request sent by a target instant messaging client, confirming a query target of the message query request;
[0023] Extracting the identification mark of the query target from the unread message queue in the second cache; and / or,
[0024] Extracting the identification mark of the query target from the historical message queue in the second cache;
[0025] The target message body stored and mapped with the identification identifier of the query target is determined in the second cache, and the target message body is returned to the target instant messaging client.
[0026] Optionally, when the unread message queue in the second cache does not contain the identification mark of the query target, extracting the identification mark of the query target from the unread message queue in the backend database; and / or,
[0027] When the historical message queue in the second cache does not contain the identification mark of the query target, the identification mark of the query target is extracted from the historical message queue in the backend database.
[0028] Optionally, when the target message body stored in the mapping with the identification identifier of the query target is not found in the second cache, the target message body stored in the mapping with the identification identifier of the query target is determined from the backend database.
[0029] Optionally, upon receiving a message withdrawal request, confirming a withdrawal target of the message withdrawal request;
[0030] Deleting the message body and identification mark of the withdrawal target in the first cache and the asynchronous task pool;
[0031] If the asynchronous task has been executed, the message body and identification mark of the withdrawn target stored in the second cache and the backend message queue are deleted;
[0032] If the backend message queue has been executed, the message body and identification of the withdrawn target stored in the backend database are deleted.
[0033] Optionally, saving the target message from the first cache to the plurality of second caches includes:
[0034] Determining the message responsiveness of all instant messaging clients, wherein the message responsiveness includes the frequency of the instant messaging clients reading messages from the corresponding second cache and the average duration of actively receiving unread messages;
[0035] Sort all second caches according to message responsiveness;
[0036] Create at least one thread;
[0037] The target message is read from the first cache through the thread, and the target message is written into all the second caches in sequence according to the sorting order of the second caches.
[0038] According to another aspect of an embodiment of the present application, the present application provides a message storage device for instant messaging, including:
[0039] The intermediate storage module is used to store the target message in the first cache and create a distributed storage task of the target message in the asynchronous task pool when the first process receives the target message, wherein the target message is an instant messaging message sent by the instant messaging client in the target group, and the first process is used to receive the instant messaging message;
[0040] A distributed storage module is used to save the target message in the first cache to multiple second caches when the second process detects the existence of a distributed storage task in the asynchronous task pool, wherein the second cache is a cache corresponding to multiple instant messaging clients in the target group, one instant messaging client corresponds to one second cache, and the second cache is used for the corresponding instant messaging client to read the target message from the second cache according to the message receiving instruction.
[0041] According to another aspect of an embodiment of the present application, the present application provides an electronic device, including a memory, a processor, a communication interface and a communication bus, wherein the memory stores a computer program that can be run on the processor, the memory and the processor communicate through the communication bus and the communication interface, and the steps of the above method are implemented when the processor executes the computer program.
[0042] According to another aspect of an embodiment of the present application, the present application also provides a computer-readable medium having a non-volatile program code executable by a processor, and the program code enables the processor to execute the above method.
[0043] The above technical solution provided by the embodiment of the present application has the following advantages compared with the related art:
[0044] The technical solution of the present application is that when the first process receives the target message, the target message is stored in the first cache, and a distributed storage task of the target message is created in the asynchronous task pool, wherein the target message is an instant messaging message sent by the instant messaging client in the target group, and the first process is used to receive the instant messaging message; when the second process detects the existence of a distributed storage task in the asynchronous task pool, the target message in the first cache is saved to multiple second caches, wherein the second cache is a cache corresponding to multiple instant messaging clients in the target group, one instant messaging client corresponds to one second cache, and the second cache is used for the corresponding instant messaging client to read the target message from the second cache according to the message receiving instruction. The present application does not directly store the instant messaging message in the database by building a cache layer and an asynchronous task pool, and writes and diffuses the instant messaging message to the caches corresponding to multiple instant messaging clients under the same message group in an asynchronous manner. The asynchronous method reduces the performance requirements of the server, and the distributed cache method also reduces the access volume of the server-side central server, improves the storage and query response speed of instant messaging messages, and solves the technical problem of high performance consumption of synchronous storage of group messages. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0046] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0047] Figure 1 A schematic diagram of a hardware environment for an optional instant messaging message storage method provided according to an embodiment of the present application;
[0048] Figure 2 A schematic diagram of an optional instant messaging message storage method according to an embodiment of the present application;
[0049] Figure 3 A schematic diagram of an optional instant messaging message storage structure provided according to an embodiment of the present application;
[0050] Figure 4 A message storage timing diagram of an optional instant messaging provided according to an embodiment of the present application;
[0051] Figure 5 An optional instant messaging message query sequence diagram provided according to an embodiment of the present application;
[0052] Figure 6 A block diagram of an optional instant messaging message storage device provided according to an embodiment of the present application;
[0053] Figure 7 A schematic diagram of an optional electronic device structure provided in an embodiment of the present application. DETAILED DESCRIPTION
[0054] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0055] In the subsequent description, the suffixes such as "module", "component" or "unit" used to represent elements are only used to facilitate the description of the present application and have no specific meaning. Therefore, "module" and "component" can be used interchangeably.
[0056] In the related art, the server of the instant messaging system directly stores the instant messaging messages in the database, and the frequency of the database read and write operations is extremely high. Limited by the performance bottleneck, in the instant messaging scenario where multiple users participate in a large group chat, since the group messages need to be synchronized to each participating end, the synchronous storage performance of the group messages consumes a lot of performance, and the storage and query response speed of the instant messaging messages are reduced.
[0057] In order to solve the problem mentioned in the background technology, according to one aspect of the embodiments of the present application, an embodiment of a method for storing instant messaging messages is provided.
[0058] Optionally, in the embodiment of the present application, the instant messaging message storage method can be applied to: Figure 1 The hardware environment shown is composed of an instant messaging client 101 and a server 103. Figure 1As shown, the server 103 is connected to the instant messaging client 101 through a network, and can be used to provide services (such as instant messaging services) for the terminal or the client installed on the terminal. A back-end database 105 can be set on the server 103 or independently of the server 103 to provide data storage services for the server 103. The instant messaging client 101 is one or more. In the group-based instant messaging service, the instant messaging client 101 is a plurality of instant messaging clients participating in the message group. The above-mentioned network includes but is not limited to: a wide area network, a metropolitan area network or a local area network, and the instant messaging client 101 includes but is not limited to a PC, a mobile phone, a tablet computer, etc.
[0059] In the embodiment of the present application, a message storage method for instant messaging can be executed by the server 103, such as Figure 2 As shown, the method may include the following steps:
[0060] Step S202, when the first process receives the target message, the target message is stored in the first cache, and a distributed storage task of the target message is created in the asynchronous task pool, wherein the target message is an instant messaging message sent by the instant messaging client in the target group, and the first process is used to receive instant messaging messages.
[0061] The message transmission between instant messaging clients actually relies on the server to transfer data, that is, the sender sends an instant messaging message, which is first received by the server, and then the server sends a new message notification to the receiver. After receiving the new message notification, the receiver obtains the instant messaging message from the server, or the receiver actively receives the new instant messaging message. The server plays the role of a recorder, that is, it stores the instant messaging messages sent by the sender and records the reading status of the instant messaging messages. In the related technology, the server directly stores the instant messaging messages in the database, and when the receiver receives the message, it obtains the corresponding instant messaging message from the database. In this way, the frequency of read and write operations on the database is extremely high, especially in the instant messaging scenario with multiple users participating in large group chats. Since the group messages need to be synchronized to each participating end, the synchronous storage performance of the group messages consumes a lot, and the storage and query response speed of the instant messaging messages are reduced.
[0062] In an embodiment of the present application, after an instant messaging client in the target group sends a new instant messaging message (target message) in the message group, the first process of the server listens to the target message from the external message interface. The first process does not store the target message directly in the database, but temporarily stores it in the first cache first, and creates a distributed storage task for the target message in the asynchronous task pool. Taking the implementation of the asynchronous task pool by workqueue as an example, creating a task is to create a thread for the task. Different threads carry different tasks. The order in which the tasks are executed is determined by the queue. At the same time, the queue is also used to temporarily store tasks. Each task is temporarily stored in the work queue until the process or thread that monitors the work queue extracts the task from the work queue, destroys the corresponding thread, and releases the memory. It should be noted that the server executes the step of creating an asynchronous task after receiving the confirmation information of the successful storage of the first cache, that is:
[0063] When the first process receives the target message, the target message is stored in the first cache;
[0064] After receiving a message that the target message is successfully stored in the first cache, creating a distributed storage task for the target message in the asynchronous task pool;
[0065] After receiving a message indicating that the target message fails to be stored in the first cache, the distributed storage task of creating the target message in the asynchronous task pool is abandoned.
[0066] In an embodiment of the present application, after the server receives the target message, it is necessary to first query whether the target message already exists, that is, to deduplicate the target message. The specific method of deduplication is: extract the identification identifier of the target message; when the identification identifier is queried in any of the first cache, asynchronous task pool, second cache and back-end database, it is determined that the target message already exists. If the target message already exists, the target message will no longer be stored in the first cache, and the asynchronous task will not be created. If it is determined that the target message is a new message through the deduplication step, it will be stored in the first cache first, and then the asynchronous task will be created if the storage is successful. After the asynchronous task is successfully created, a storage success confirmation receipt is returned to the instant messaging client that sent the target message.
[0067] In the embodiment of the present application, the first process does not need to wait for the distributed storage task to be completed, and can return to continue listening to the external message interface after creating the task.
[0068] Step S204, when the second process detects the presence of a distributed storage task in the asynchronous task pool, the target message in the first cache is saved to multiple second caches, wherein the second cache is a cache corresponding to multiple instant messaging clients in the target group, one instant messaging client corresponds to one second cache, and the second cache is used for the corresponding instant messaging client to read the target message from the second cache according to the message receiving instruction.
[0069] In the embodiment of the present application, the second process of the server and the first process use different working clocks, that is, the two are executed asynchronously, and the second process is used to monitor the asynchronous task pool, that is, to monitor the work queue. The second cache is the cache space configured by the server for multiple instant messaging clients of the target group. The second cache and the first cache can be separated in physical space, that is, the appropriate service node can be selected as the second cache of the instant messaging client according to the distance from the instant messaging client, and the instant messaging service is provided to the instant messaging client through the service node. The server in the embodiment of the present application can be a service system composed of a central server + distributed sub-servers, and the distributed sub-servers are the service nodes, as sub-servers, and the central server is the main server, which jointly provide instant messaging services to the instant messaging client. The mode of central server + distributed sub-servers can greatly alleviate the high concurrency pressure of the central server.
[0070] In the embodiment of the present application, when the second process detects the existence of the distributed storage task, the server reads the target message from the first cache and sends the target message to the second cache corresponding to the multiple instant messaging clients in the target group, wherein one instant messaging client can correspond to one second cache, that is, one service node only serves one instant messaging client. Of course, in actual situations, in order to maximize resource utilization, one service node can serve multiple instant messaging clients, that is, one second cache can correspond to multiple instant messaging clients. When the instant messaging client in the target group receives a new message, it reads the new message from the corresponding second cache, which can reduce the pressure on the central server and improve the efficiency and response speed of message storage.
[0071] In an embodiment of the present application, based on the central server + distributed sub-server model, the first process and the second process of the server can be processes on a hardware device, such as a central server, or can be processes executed on different hardware devices, such as a central server and distributed sub-servers, and different processes and threads can be communicated with each other.
[0072] Through steps S202 to S204, the present application builds a cache layer and an asynchronous task pool, does not directly store instant messaging messages in the database, and asynchronously writes and spreads the instant messaging messages to the caches corresponding to multiple instant messaging clients under the same message group. The asynchronous method reduces the performance requirements of the server, and the distributed cache method also reduces the access volume of the server center server, improves the storage and query response speed of instant messaging messages, and solves the technical problem of high performance consumption of synchronous storage of group messages.
[0073] As an optional implementation manner, saving the target message from the first cache to the plurality of second caches includes:
[0074] Step 1, determining the message responsiveness of all instant messaging clients, wherein the message responsiveness includes the frequency of the instant messaging client reading messages from the corresponding second cache and the average duration of actively receiving unread messages;
[0075] Step 2, sorting all second caches according to message responsiveness;
[0076] Step 3, create at least one thread;
[0077] Step 4: read the target message from the first cache through the thread, and write the target message into all the second caches in sequence according to the sorting order of the second caches.
[0078] In an embodiment of the present application, when sending instant messaging messages to the second caches corresponding to multiple instant messaging clients in the target group at the same time, there may be response delays due to high concurrency. In order to relieve the pressure on the server, the priority of the message distributed cache can be determined based on the frequency of the instant messaging client reading messages from the second cache and the average duration of actively receiving unread messages. If some users often click on the target group to check whether there are new messages, the user's instant messaging client reads messages from the second cache frequently. If some users do not click on the target group for a long time, new messages are always received by the user after a long time, and the average duration of the user's instant messaging client actively receiving unread messages is longer. The present application combines the above two factors to form a message responsiveness, thereby sorting all second caches according to the message responsiveness, and then writing the target message to all second caches in sequence according to the sorting order of the second caches through at least one thread.
[0079] As an optional implementation manner, saving the target message in the first cache to multiple second caches includes saving the target message to one second cache in the following manner:
[0080] Step 1, read the target message from the first cache;
[0081] Step 2, extracting the message body and identification mark of the target message, wherein the message body is a data structure for storing instant messaging messages on the server side;
[0082] Step 3: Push the identification mark into the unread message queue and the historical message queue in the second cache, and store the identification mark and the message body mapping in the second cache.
[0083] In the present application embodiment, Figure 3 As shown, if the first cache of the server stores new messages of session A, the second process reads the new messages of session A from the first cache, writes the new messages into the message body, and writes the message ID (i.e., identification mark) of the new messages into the historical message queue and the unread message queue of session A, thereby recording the reading status of the new messages by the instant messaging client through the historical message queue and the unread message queue. Similarly, if the first cache of the server stores new messages of session B, the second process reads the new messages of session B from the first cache, writes the new messages into the message body, and writes the message ID (i.e., identification mark) of the new messages into the historical message queue and the unread message queue of session B, thereby recording the reading status of the new messages by the instant messaging client through the historical message queue and the unread message queue. The above identification mark at least includes the first message ID determined by the sender according to the order in which the messages are sent and the second message ID assigned by the server.
[0084] As an optional implementation, after pushing the identification mark into the unread message queue and the historical message queue in the second cache, and storing the identification mark and the message body mapping in the second cache, the method further includes:
[0085] Step 1: Push the identification mark and message body of the target message into the backend message queue;
[0086] Step 2: When the third process monitors the identification mark and message body of the target message from the backend message queue, the identification mark and message body of the target message are mapped and stored in the backend database.
[0087] In the embodiment of the present application, the third process can be a process on the central server or a process on a distributed sub-server. The third process and the first process use different working clocks, that is, the two are executed asynchronously. Through the third process, the server writes the instant messaging message to the back-end database in an asynchronous manner, reducing the synchronization pressure. The first process does not need to wait for the instant messaging message to be stored in the back-end database before listening to the external message interface, which greatly improves the response speed of message reception and storage.
[0088] Optionally, after the target message is saved in the backend database, the target message in the first cache may be deleted.
[0089] As an optional implementation, after pushing the identification mark into the unread message queue and the historical message queue in the second cache, and storing the identification mark and the message body mapping in the second cache, the method further includes:
[0090] When read confirmation information of the target message is received, the identification mark of the target message is pushed out of the unread message queue of the second cache, wherein the read confirmation information is sent by the instant messaging client corresponding to the second cache after reading the target message from the second cache.
[0091] In an embodiment of the present application, the reading status of the instant messaging client for new messages is recorded through the historical message queue and the unread message queue. After the user's instant messaging client reads the target message from the second cache, the instant messaging client will return a read confirmation information ack, and the server will delete the identification identifier of the target message from the unread message queue of the second cache, thereby changing the target message from an unread message to a read message.
[0092] Optionally, if an unread message queue is also set up in the back-end database, then when the read confirmation information of the target message is received, the identification mark of the target message needs to be pushed out of the unread message queue of the back-end database. Deleting the identification mark of the target message from the unread message queue of the second cache and deleting the identification mark of the target message from the unread message queue of the back-end database can be asynchronous, wherein the second cache interacts with the instant messaging client more frequently and has stronger real-time requirements, so the status in the second cache can be updated in a limited manner, and the back-end database can perform status updates through an asynchronous task pool.
[0093] The following is a comprehensive description of the complete message storage process of this application.
[0094] like Figure 4 As shown, the API gateway is the central interface that connects the instant messaging client to the server. The API gateway can handle important security and management matters, such as authentication, input validation, metric collection, and response conversion. Different devices and users need to access different information, so a unique API (Application Programming Interface) can be assigned to each user and each type of instant messaging client, so that a quick response can be made when a new message from the instant messaging client is received. The instant messaging client sends an instant messaging message through the API provided by the API gateway. The complete message storage process includes:
[0095] Step 1: The instant messaging client sends an instant messaging message through the API interface provided by the API gateway.
[0096] Step 2: The message service (the instant messaging service provided by the server) puts the instant messaging message into the distributed cache (the first cache also constitutes the distributed cache).
[0097] Step 3: If the cache is successful, the instant messaging message is put into the asynchronous task.
[0098] Step 4: The server returns confirmation information ACK of the message storage to the instant messaging client.
[0099] Step 5: The message service writes the instant messaging message into the distributed cache (second cache) corresponding to the receiving end through an asynchronous write diffusion operation, which actually writes the instant messaging message into the message queue of the receiving end.
[0100] Step 6: The message service writes the instant messaging message to the message queue corresponding to the backend database (backend message queue) in an asynchronous manner.
[0101] Step 7: The database (backend database) reads the instant messaging message from the message queue and writes it into the database.
[0102] Step 8: The message service deletes the instant messaging message temporarily stored in the second cache.
[0103] Based on the above message storage method, the present application also proposes a message query method.
[0104] As an optional implementation, after pushing the identification mark into the unread message queue and the historical message queue in the second cache, and storing the identification mark and the message body mapping in the second cache, the method further includes:
[0105] Step 1, upon receiving a message query request sent by a target instant messaging client, confirming a query target of the message query request;
[0106] Step 2: extracting the identification mark of the query target from the unread message queue in the second cache; and / or extracting the identification mark of the query target from the historical message queue in the second cache;
[0107] Step 3: determine the target message body stored in the second cache that is mapped with the identification identifier of the query target, and return the target message body to the target instant messaging client.
[0108] In addition, when the unread message queue in the second cache does not contain the identification mark of the query target, extracting the identification mark of the query target from the unread message queue in the backend database; and / or,
[0109] When the historical message queue in the second cache does not contain the identification mark of the query target, the identification mark of the query target is extracted from the historical message queue in the backend database.
[0110] When the historical message queue in the second cache does not contain the identification mark of the query target, the identification mark of the query target is extracted from the historical message queue in the backend database.
[0111] In the embodiment of the present application, historical messages and unread messages can be queried. When querying historical messages, the server first searches and returns the message ID in the historical message queue, then finds the message body stored in the ID mapping of the historical message, and returns the message body to the instant messaging client. When querying unread messages, the server first searches and returns the message ID in the unread message queue, then finds the message body stored in the ID mapping of the unread message, and returns the message body to the instant messaging client. Regardless of the query of the ID or the query of the message body, the server will first query the second cache corresponding to the instant messaging client. If there is no hit, it will penetrate to the back-end database for query.
[0112] like Figure 5 The following is a schematic diagram of the message query process provided by this application. The message query includes:
[0113] Step 1: The instant messaging client sends a message query request for an instant messaging message through the API interface provided by the API gateway.
[0114] Step 2: The server queries the message ID in the distributed cache (second cache). If the query is successful, the message ID is returned. If the query fails, the server queries the message ID in the backend database.
[0115] Step 3, the server queries the message body stored in the distributed cache (second cache) for the message ID mapping. If the query is successful, the message body is returned. If the query fails, the server queries the message body in the backend database.
[0116] Step 4: The server compiles the queried messages into a message list and returns it to the instant messaging client.
[0117] The present application also provides a message withdrawal method, the method comprising:
[0118] Step 1, upon receiving a message withdrawal request, confirming a withdrawal target of the message withdrawal request;
[0119] Step 2, deleting the message body and identification mark of the withdrawal target in the first cache and asynchronous task pool;
[0120] Step 3: If the asynchronous task has been executed, the message body and identification mark of the withdrawal target stored in the second cache and the backend message queue are deleted;
[0121] Step 4: If the backend message queue has been executed, the message body and identification mark of the withdrawal target stored in the backend database are deleted.
[0122] In the embodiment of the present application, since the first cache and the asynchronous task pool constitute the first-level storage, the second cache and the back-end message queue constitute the second-level storage, and the back-end database constitutes the third-level storage in the server, when performing the message withdrawal step, it is necessary to withdraw step by step, that is, if the withdrawal target is only stored in the first cache and the asynchronous task pool (an asynchronous distributed cache task is created in the asynchronous task pool), it is only necessary to delete the message body and identification mark of the withdrawal target in the first cache and the asynchronous task pool. If the asynchronous task has been executed, it is necessary to penetrate to the second-level storage to perform the message withdrawal operation, that is, delete the message body and identification mark of the withdrawal target stored in the second cache and the back-end message queue. If the back-end message queue has been executed, it is necessary to penetrate to the third-level storage to perform the message withdrawal operation, that is, delete the message body and identification mark of the withdrawal target stored in the back-end database.
[0123] According to another aspect of the embodiment of the present application, Figure 6 As shown, a message storage device for instant messaging is provided, comprising:
[0124] The intermediate storage module 601 is used to store the target message in the first cache when the first process receives the target message, and to create a distributed storage task of the target message in the asynchronous task pool, wherein the target message is an instant messaging message sent by the instant messaging client in the target group, and the first process is used to receive the instant messaging message;
[0125] The distributed storage module 603 is used to save the target message in the first cache to multiple second caches when the second process detects the existence of a distributed storage task in the asynchronous task pool, wherein the second cache is a cache corresponding to multiple instant messaging clients in the target group, one instant messaging client corresponds to one second cache, and the second cache is used for the corresponding instant messaging client to read the target message from the second cache according to the message receiving instruction.
[0126] It should be noted that the intermediate storage module 601 in this embodiment can be used to execute step S202 in the embodiment of the present application, and the distributed storage module 603 in this embodiment can be used to execute step S204 in the embodiment of the present application.
[0127] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. It should be noted that the above modules as part of the device can be run in Figure 1 In the hardware environment shown, it can be implemented by software or by hardware.
[0128] Optionally, the intermediate storage module is specifically used for:
[0129] When the first process receives the target message, the target message is stored in the first cache;
[0130] After receiving a message that the target message is successfully stored in the first cache, creating a distributed storage task for the target message in the asynchronous task pool;
[0131] After receiving a message indicating that the target message fails to be stored in the first cache, the distributed storage task of creating the target message in the asynchronous task pool is abandoned.
[0132] Optionally, the distributed storage module is used to save the target message to a second cache in the following manner:
[0133] Reading a target message from a first buffer;
[0134] Extract the message body and identification mark of the target message, wherein the message body is a data structure for storing instant messaging messages on the server side;
[0135] The identification mark of the target message is pushed into the unread message queue and the historical message queue in the second cache, and the identification mark and the message body mapping are stored in the second cache.
[0136] Optionally, the instant messaging message storage device further includes a database storage module, which is used to:
[0137] Push the identification mark and message body of the target message into the backend message queue;
[0138] When the third process monitors the identification mark and the message body of the target message from the backend message queue, the identification mark and the message body of the target message are mapped and stored in the backend database.
[0139] Optionally, the instant messaging message storage device further includes an unread message updating module, which is used to:
[0140] When read confirmation information of the target message is received, the identification mark of the target message is pushed out of the unread message queue of the second cache, wherein the read confirmation information is sent by the instant messaging client corresponding to the second cache after reading the target message from the second cache.
[0141] Optionally, the instant messaging message storage device further includes a message query module, which is used to:
[0142] Upon receiving a message query request sent by a target instant messaging client, confirming a query target of the message query request;
[0143] Extracting the identification mark of the query target from the unread message queue in the second cache; and / or,
[0144] Extracting the identification mark of the query target from the historical message queue in the second cache;
[0145] The target message body stored and mapped with the identification identifier of the query target is determined in the second cache, and the target message body is returned to the target instant messaging client.
[0146] Optionally, the message query module is further used to:
[0147] If the unread message queue in the second cache does not contain the identification mark of the query target, extract the identification mark of the query target from the unread message queue in the backend database; and / or,
[0148] When the historical message queue in the second cache does not contain the identification mark of the query target, the identification mark of the query target is extracted from the historical message queue in the backend database.
[0149] Optionally, the message query module is further used to:
[0150] When the target message body stored in the mapping with the identification identifier of the query target is not found in the second cache, the target message body stored in the mapping with the identification identifier of the query target is determined from the backend database.
[0151] Optionally, the instant messaging message storage device further includes a message withdrawal module, which is used to:
[0152] In case of receiving a message withdrawal request, confirming a withdrawal target of the message withdrawal request;
[0153] Deleting the message body and identification mark of the withdrawal target in the first cache and the asynchronous task pool;
[0154] If the asynchronous task has been executed, the message body and identification mark of the withdrawn target stored in the second cache and the backend message queue are deleted;
[0155] If the backend message queue has been executed, the message body and identification of the withdrawn target stored in the backend database are deleted.
[0156] Optionally, the distributed storage module is further used for:
[0157] Determining the message responsiveness of all instant messaging clients, wherein the message responsiveness includes the frequency of the instant messaging clients reading messages from the corresponding second cache and the average duration of actively receiving unread messages;
[0158] Sort all second caches according to message responsiveness;
[0159] Create at least one thread;
[0160] The target message is read from the first cache through the thread, and the target message is written into all the second caches in sequence according to the sorting order of the second caches.
[0161] According to another aspect of the embodiments of the present application, the present application provides an electronic device, such as Figure 7 As shown, it includes a memory 701, a processor 703, a communication interface 705 and a communication bus 707. The memory 701 stores a computer program that can be run on the processor 703. The memory 701 and the processor 703 communicate through the communication interface 705 and the communication bus 707. When the processor 703 executes the computer program, the steps of the above method are implemented.
[0162] The memory and processor in the above electronic device communicate via a communication bus and a communication interface. The communication bus may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus may be divided into an address bus, a data bus, a control bus, etc.
[0163] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0164] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0165] According to another aspect of the embodiments of the present application, a computer program product or a computer program is provided, the computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the steps of any of the above embodiments.
[0166] Optionally, in an embodiment of the present application, the computer-readable medium is configured to store program codes for the processor to perform the following steps:
[0167] When the first process receives a target message, the target message is stored in a first cache, and a distributed storage task of the target message is created in an asynchronous task pool, wherein the target message is an instant messaging message sent by an instant messaging client in a target group, and the first process is used to receive the instant messaging message;
[0168] When the second process detects the presence of a distributed storage task in the asynchronous task pool, the target message in the first cache is saved to multiple second caches, wherein the second cache is a cache corresponding to multiple instant messaging clients in the target group, one instant messaging client corresponds to one second cache, and the second cache is used for the corresponding instant messaging client to read the target message from the second cache according to the message receiving instruction.
[0169] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment will not be described in detail here.
[0170] When the embodiments of the present application are specifically implemented, reference may be made to the above-mentioned embodiments, which have corresponding technical effects.
[0171] It is understood that the embodiments described herein may be implemented in hardware, software, firmware, middleware, microcode, or a combination thereof. For hardware implementation, the processing unit may be implemented in one or more application specific integrated circuits (ASIC), digital signal processors (DSP), digital signal processing devices (DSPD), programmable logic devices (PLD), field programmable gate arrays (FPGA), general purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the functions described in the present application, or a combination thereof.
[0172] For software implementation, the technology described herein can be implemented by a unit that performs the functions described herein. The software code can be stored in a memory and executed by a processor. The memory can be implemented in the processor or outside the processor.
[0173] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0174] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0175] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0176] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0177] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0178] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a ROM, a RAM, a magnetic disk or an optical disk. It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. Moreover, the term "include", "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements that are not explicitly listed, or also includes elements inherent to such a process, method, article or device. Without more constraints, an element defined by the phrase "comprising a..." does not exclude the existence of other identical elements in the process, method, article or apparatus comprising the element.
[0179] The above description is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest range consistent with the principles and novel features applied for herein.
Claims
1. A message storage method for instant messaging, applied to a server, characterized in that: include: When the first process receives a target message, the target message is stored in a first cache, and a distributed storage task of the target message is created in an asynchronous task pool, wherein the target message is an instant messaging message sent by an instant messaging client in a target group, and the first process is used to receive the instant messaging message; When the second process detects the existence of the distributed storage task in the asynchronous task pool, the target message in the first cache is saved to multiple second caches, wherein the second cache is a cache corresponding to multiple instant messaging clients in the target group, one instant messaging client corresponds to one second cache, and the second cache is used for the corresponding instant messaging client to read the target message from the second cache according to a message receiving instruction.
2. The method according to claim 1, characterized in that When the first process receives the target message, storing the target message in the first cache and creating a distributed storage task of the target message in the asynchronous task pool specifically includes: When the first process receives the target message, storing the target message in the first cache; After receiving a message indicating that the target message is successfully stored in the first cache, creating a distributed storage task for the target message in an asynchronous task pool; and / or After receiving a message indicating that the target message fails to be stored in the first cache, the distributed storage task of creating the target message in the asynchronous task pool is abandoned.
3. The method according to claim 1, characterized in that Saving the target message in the first cache to multiple second caches includes saving the target message to one of the second caches in the following manner: Reading the target message from the first buffer; Extracting the message body and identification mark of the target message, wherein the message body is a data structure for storing instant messaging messages on the server side; The identification mark is pushed into the unread message queue and the historical message queue in the second cache, and the identification mark and the message body mapping are stored in the second cache.
4. The method according to claim 3, characterized in that After pushing the identification mark into the unread message queue and the historical message queue in the second cache, and storing the identification mark and the message body mapping in the second cache, the method further includes: Pushing the identification mark and message body of the target message into the backend message queue; When the third process monitors the identification mark and the message body of the target message from the backend message queue, the identification mark and the message body of the target message are mapped and stored in the backend database.
5. The method according to claim 3, characterized in that: After pushing the identification mark into the unread message queue and the historical message queue in the second cache, and storing the identification mark and the message body mapping in the second cache, the method further includes: When read confirmation information of the target message is received, the identification mark of the target message is pushed out of the unread message queue of the second cache, wherein the read confirmation information is sent by the instant messaging client corresponding to the second cache after reading the target message from the second cache.
6. The method according to claim 3, characterized in that: After pushing the identification mark into the unread message queue and the historical message queue in the second cache, and storing the identification mark and the message body mapping in the second cache, the method further includes: Upon receiving a message query request sent by a target instant messaging client, confirming a query target of the message query request; Extracting the identification mark of the query target from the unread message queue in the second cache; and / or, Extracting the identification mark of the query target from the historical message queue in the second cache; A target message body stored and mapped with the identification identifier of the query target is determined in the second cache, and the target message body is returned to the target instant messaging client.
7. The method according to claim 6, characterized in that The method further comprises: If the unread message queue in the second cache does not contain the identification of the query target, extracting the identification of the query target from the unread message queue in the backend database; and / or, When the historical message queue of the second cache does not contain the identification mark of the query target, the identification mark of the query target is extracted from the historical message queue of the backend database.
8. The method according to claim 6 or 7, characterized in that: The method further comprises: In the case that the target message body stored in the mapping with the identification identifier of the query target is not found in the second cache, the target message body stored in the mapping with the identification identifier of the query target is determined from the backend database.
9. The method according to any one of claims 1 to 7, further comprising: In case of receiving a message withdrawal request, confirming a withdrawal target of the message withdrawal request; Deleting the message body and identification mark of the withdrawal target in the first cache and the asynchronous task pool; If the asynchronous task has been executed, deleting the message body and identification mark of the withdrawn target stored in the second cache and the backend message queue; If the backend message queue has been executed, the message body and identification mark of the withdrawn target stored in the backend database are deleted.
10. The method according to any one of claims 1 to 7, characterized in that: Saving the target message in the first cache to multiple second caches includes: Determining the message responsiveness of all the instant messaging clients, wherein the message responsiveness includes the frequency of the instant messaging clients reading messages from the corresponding second cache and the average duration of actively receiving unread messages; sorting all the second caches according to the message responsiveness; Create at least one thread; The target message is read from the first cache through the thread, and the target message is written into all the second caches in sequence according to the sorting order of the second caches.
11. A message storage device for instant messaging, characterized in that: include: The intermediate storage module is used to store the target message in the first cache and create a distributed storage task of the target message in the asynchronous task pool when the first process receives the target message, wherein the target message is an instant messaging message sent by the instant messaging client in the target group, and the first process is used to receive the instant messaging message; A distributed storage module is used to save the target message in the first cache to multiple second caches when the second process detects the existence of the distributed storage task in the asynchronous task pool, wherein the second cache is a cache corresponding to multiple instant messaging clients in the target group, one instant messaging client corresponds to one second cache, and the second cache is used for the corresponding instant messaging client to read the target message from the second cache according to a message receiving instruction.
12. An electronic device, comprising a memory, a processor, a communication interface and a communication bus, wherein the memory stores a computer program that can be run on the processor, and the memory and the processor communicate through the communication bus and the communication interface, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 10 are implemented.
13. A computer-readable medium having a non-volatile program code executable by a processor, characterized in that: The program code enables the processor to execute the method according to any one of claims 1 to 10.
Citation Information
Patent Citations
Cloud storage service method based on asynchronous messages
CN110311974A
Instant messaging multi-terminal synchronization method based on timeline model
CN113407622A