Short message sending method, device, equipment, medium and program product
By determining priority based on the performance indicators of the SMS channel and selecting the appropriate SMS channel for SMS sending, the problem that the fixed thread pool configuration cannot guarantee the maximum SMS sending rate is solved, and higher resource utilization and SMS sending rate are achieved, while ensuring that The stability of the SMS channel.
Patent Information
- Application Number
- CN202411472693.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-21
- Publication Date
- 2025-02-18
AI Technical Summary
In the large-scale SMS sending business scenario, the fixed thread pool configuration cannot guarantee the maximum SMS sending rate, resulting in low resource utilization or excessive pressure on SMS channel providers, affecting the stability of interface services.
By determining priority based on the number of transactions per second, average response time, and current maximum number of threads of the SMS channel, selecting the SMS channel with the highest priority and the thread pool is in an unsaturated state for SMS sending.
It improves the resource utilization and speed of SMS sending, while ensuring the stability of SMS channels, avoiding waste of resources and excessive interface pressure.
Smart Images

Figure CN119485183A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a method, device, equipment, medium and program product for sending short messages. Background Art
[0002] In the business scenario of sending large quantities of SMS, by configuring a fixed thread pool, submitting SMS sending tasks to the thread pool one by one, the thread pool always works with the maximum number of threads. However, it cannot guarantee the maximum SMS sending rate. If the maximum number of threads MS is configured too small, it will cause low resource utilization; if the maximum number of threads MS is configured too large, it will cause excessive pressure on SMS channel providers, affect the stability of interface services, and cause backlogs. Summary of the invention
[0003] The present disclosure aims to solve one of the technical problems in the related art at least to some extent.
[0004] To this end, the first objective of the present disclosure is to propose a method for sending short messages to improve resource utilization, short message sending rate and stability of short message sending.
[0005] The second objective of the present disclosure is to provide a device for sending short messages.
[0006] A third objective of the present disclosure is to provide an electronic device.
[0007] A fourth objective of the present disclosure is to provide a computer-readable storage medium.
[0008] A fifth object of the present disclosure is to provide a computer program product.
[0009] To achieve the above-mentioned purpose, the first embodiment of the present disclosure proposes a method for sending a text message, comprising:
[0010] Obtaining a to-be-sent short message from a to-be-sent short message pool, and determining a first short message channel from a set of short message channels, wherein the first short message channel is an available short message channel with the highest priority in the set of short message channels, and the priority is determined by the number of transactions per second, the average response time, and the current maximum number of threads corresponding to the short message channel;
[0011] Determine the working state of the thread pool corresponding to the first SMS channel, and if the working state indicates that the thread pool is in a saturated state, set the first SMS channel as an unavailable SMS channel, and re-determine the first SMS channel from the SMS channel set until the working state indicates that the thread pool is in a non-saturated state, thereby obtaining a second SMS channel;
[0012] Use the thread pool corresponding to the second SMS channel to send the SMS to be sent.
[0013] Optionally, the method further comprises:
[0014] At first preset time intervals, the number of transactions per second, the average response time, and the current maximum number of threads corresponding to each SMS channel in the SMS channel set are obtained;
[0015] The priority of each SMS channel is determined according to the number of transactions per second, the average response time, and the current maximum number of threads.
[0016] Optionally, determining the first SMS channel from the SMS channel set includes:
[0017] Determine a subset of unavailable SMS channels in the SMS channel set;
[0018] The availability information of the SMS channels in the SMS channel set is determined in sequence according to the order of priority until the availability information indicates that the SMS channel is an available SMS channel, thereby obtaining a first SMS channel; wherein, if the SMS channel is in the subset of unavailable SMS channels, the availability information indicates that the SMS channel is an unavailable SMS channel; if the SMS channel is not in the subset of unavailable SMS channels, the availability information indicates that the SMS channel is an available SMS channel.
[0019] Optionally, the method further comprises:
[0020] When the availability information of all SMS channels in the SMS channel set indicates that the SMS channel is an unavailable SMS channel, hibernation is performed for a second preset time period, and the unavailable SMS channel subset is re-determined, and the availability information of the SMS channels is determined in order of priority until the availability information indicates that the SMS channel is an available SMS channel, thereby obtaining a first SMS channel.
[0021] Optionally, determining the working status of the thread pool corresponding to the first SMS channel includes:
[0022] Obtaining current thread pool parameters of the thread pool corresponding to the first SMS channel, wherein the current thread pool parameters include the current number of active threads, the current number of thread pool queues, the current maximum number of threads, and the current thread pool queue size;
[0023] If the sum of the current number of active threads and the current number of queues in the thread pool is less than the sum of the current maximum number of threads and the current thread pool queue size, determining that the working state of the thread pool indicates that the thread pool is in an unsaturated state;
[0024] If the sum of the current number of active threads and the current number of thread pool queues is not less than the sum of the current maximum number of threads and the current thread pool queue size, it is determined that the working status indicates that the thread pool is in a saturated state.
[0025] Optionally, the method further comprises:
[0026] If the load of the thread pool is greater than the load warning value for a first preset number of times in a row, and the average response time corresponding to the thread pool is less than the first response time warning value, the maximum number of threads in the thread pool is increased according to the first step, wherein the maximum number of threads is not greater than the maximum number of threads that can be configured, and the load is determined by the number of active threads in the thread pool and the maximum number of threads;
[0027] If the average response time corresponding to the thread pool is not less than the first response time warning value and less than the second response time warning value, the thread pool parameters remain unchanged;
[0028] If the average response time corresponding to the thread pool is not less than the second response time warning value for a second preset number of times in a row, the maximum number of threads is reduced by half, wherein the maximum number of threads is not less than the initialized maximum number of threads;
[0029] If the load is less than the load idle value for a third consecutive preset number of times, the maximum number of threads is reduced according to a second step size.
[0030] Optionally, before acquiring the short message to be sent from the short message pool to be sent, the method further includes:
[0031] Obtaining the initialization thread pool parameters corresponding to each SMS channel in the SMS channel set, wherein the initialization thread pool parameters include the initialization maximum number of threads, the initialization core number of threads, and the initialization thread pool queue size;
[0032] The thread pool parameters corresponding to each SMS channel are initialized according to the initialization thread pool parameters.
[0033] To achieve the above-mentioned purpose, a second aspect of the present disclosure provides a device for sending a text message, including:
[0034] A channel determination unit, configured to obtain a to-be-sent short message from a to-be-sent short message pool, and determine a first short message channel from a set of short message channels, wherein the first short message channel is an available short message channel with the highest priority in the set of short message channels, and the priority is determined by the number of transactions per second, the average response time, and the current maximum number of threads corresponding to the short message channel;
[0035] a state determination unit, configured to determine a working state of a thread pool corresponding to the first SMS channel, and, if the working state indicates that the thread pool is in a saturated state, set the first SMS channel as an unavailable SMS channel, and re-determine the first SMS channel from the SMS channel set until the working state indicates that the thread pool is in a non-saturated state, thereby obtaining a second SMS channel;
[0036] The SMS sending unit is used to send the SMS to be sent by using the thread pool corresponding to the second SMS channel.
[0037] To achieve the above-mentioned purpose, a third aspect of the present disclosure provides an electronic device, including: a processor, and a memory communicatively connected to the processor;
[0038] Memory stores computer-executable instructions;
[0039] The processor executes the computer-executable instructions stored in the memory to implement the method shown in any one of the first aspects above.
[0040] To achieve the above-mentioned objectives, an embodiment of the fourth aspect of the present disclosure proposes a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the method shown in any one of the above-mentioned first aspects.
[0041] To achieve the above-mentioned purpose, the fifth aspect of the present disclosure provides a computer program product, including a computer program, which implements the method shown in any one of the above-mentioned first aspects when executed by a processor.
[0042] In summary, the method, apparatus, device, medium and program product provided by the present invention determine the priority of each SMS in a SMS channel set according to the number of transactions per second, the average response time and the current maximum number of threads corresponding to the SMS channel, and when sending a SMS, select an available SMS channel with the highest priority and a corresponding thread pool in a non-saturated state from the SMS channel set to complete the sending of the SMS to be sent. Therefore, resources can be fully utilized to improve the SMS sending rate while ensuring the stability of the SMS channel.
[0043] Additional aspects and advantages of the present disclosure will be given in part in the following description and in part will be obvious from the following description or learned through practice of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] The above and / or additional aspects and advantages of the present disclosure will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:
[0045] Figure 1A flowchart of a method for sending a text message provided by an embodiment of the present disclosure;
[0046] Figure 2 A flowchart of a method for sending a text message provided by another embodiment of the present disclosure;
[0047] Figure 3 A schematic diagram of the structure of a device for sending short messages provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0048] Embodiments of the present disclosure are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present disclosure, and should not be construed as limiting the present disclosure.
[0049] The present disclosure is described in detail below with reference to specific embodiments.
[0050] In the first embodiment, if Figure 1 As shown, Figure 1 The present invention provides a flowchart of a method for sending a short message provided by an embodiment of the present invention. The method can be implemented by a computer program and can be run on a device for sending short messages. The computer program can be integrated into an application or run as an independent tool application.
[0051] The SMS sending device may be an electronic device with a SMS sending function.
[0052] Among them, the text message sending method can be executed by an electronic device.
[0053] For example, the SMS sending method includes the following steps:
[0054] S101, obtaining a to-be-sent short message from a to-be-sent short message pool, and determining a first short message channel from a short message channel set;
[0055] According to some embodiments, the pool of short messages to be sent refers to a collection of at least one short message to be sent. The short message to be sent refers to a short message that needs to be sent.
[0056] In some embodiments, the SMS channel set refers to a set formed by at least one SMS channel. The SMS channel refers to an SMS sending interface provided by an operator, which can be used to achieve the purpose of batch SMS sending and custom SMS sending with a customer-specified number.
[0057] According to some embodiments, the first SMS channel is an available SMS channel with the highest priority in the set of SMS channels.
[0058] In some embodiments, the available SMS channel refers to an SMS channel in the SMS channel set that can be used for SMS sending.
[0059] According to some embodiments, the priority may be determined by the number of transactions per second, the average response time, and the current maximum number of threads corresponding to the SMS channel.
[0060] In some embodiments, transactions per second (TPS), also known as transactions per second, is a unit of measurement for software test results. A transaction refers to a process in which a client sends a request to a server and the server responds.
[0061] In some embodiments, response time (RT) refers to the total time taken to execute a request from the beginning to the end of receiving the response data, that is, the time from the client initiating the request to receiving the server response result. Average RT refers to the average RT taken when executing multiple requests.
[0062] It should be noted that in order to improve the resource utilization and SMS sending rate of SMS sending, when sending SMS, the SMS to be sent can be tilted towards the SMS channel with high TPS and short average RT. That is, when selecting SMS channel for SMS sending, the SMS channel with higher TPS and shorter average RT has higher priority.
[0063] According to some embodiments, the current maximum number of threads refers to the current maximum number of threads in the thread pool corresponding to the SMS channel.
[0064] In some embodiments, a thread pool (TP) is a thread usage mode. The thread pool maintains multiple threads, waiting for the supervisor to assign concurrently executable tasks. This avoids the cost of creating and destroying threads when processing short-time tasks. The thread pool can not only ensure full utilization of the core, but also prevent over-scheduling. The number of available threads in the thread pool can depend on the number of available concurrent processors, processor cores, memory, network programming interfaces (sockets), etc. However, too many threads in the thread pool will result in additional thread switching overhead and scheduling overhead, which will affect cache locality and overall performance.
[0065] In some embodiments, a thread (T) is an execution unit in a process, responsible for executing the program in the current process. A process has at least one thread, and a process can have multiple threads.
[0066] In some embodiments, the maximum number of threads (maximumPoolSize, MS) refers to the maximum number of threads allowed to be created in the thread pool.
[0067] It should be noted that by determining the priority of the SMS channel based on TPS and average RT in combination with MS, when SMS channel selection is performed using priority, resources can be fully utilized without causing excessive pressure on the SMS channel interface (i.e., the interface is stable), thereby achieving a faster SMS sending speed.
[0068] S102, determining the working state of the thread pool corresponding to the first SMS channel, and when the working state indicates that the thread pool is in a saturated state, setting the first SMS channel as an unavailable SMS channel, and re-determining the first SMS channel from the SMS channel set until the working state indicates that the thread pool is in a non-saturated state, thereby obtaining a second SMS channel;
[0069] According to some embodiments, the working status is used to indicate whether the thread pool can be used to send SMS messages.
[0070] In some embodiments, if the working status indicates that the thread pool is in a saturated state, it means that the thread pool cannot be used to send SMS messages.
[0071] In some embodiments, if the working status indicates that the thread pool is in a non-saturated state, it means that the thread pool can be used to send SMS messages.
[0072] According to some embodiments, the unavailable SMS channel refers to an SMS channel that is unavailable for SMS sending.
[0073] In some embodiments, the second SMS channel refers to an available SMS channel with the highest priority in the SMS channel set and a corresponding thread pool in a non-saturated state.
[0074] S103: Use the thread pool corresponding to the second SMS channel to send the SMS to be sent.
[0075] In summary, the method provided in this embodiment determines the priority of each SMS in the SMS channel set according to the number of transactions per second, the average response time and the current maximum number of threads corresponding to the SMS channel, and when sending the SMS, selects the available SMS channel with the highest priority and the corresponding thread pool in a non-saturated state from the SMS channel set to complete the sending of the SMS to be sent. Therefore, resources can be fully utilized to improve the SMS sending rate while ensuring the stability of the SMS channel.
[0076] This embodiment also provides another method for sending a text message, which can be executed by an electronic device.
[0077] For example, the SMS sending method may include the following steps:
[0078] S201, obtaining initialization thread pool parameters corresponding to each SMS channel in the SMS channel set;
[0079] According to some embodiments, the initialization thread pool parameters refer to the parameters used when initializing the thread pool corresponding to the SMS channel.
[0080] In some embodiments, the initialization thread pool parameters include but are not limited to initializing the maximum number of threads MS1, initializing the number of core threads CS1, initializing the thread pool queue size, etc.
[0081] The initialized maximum number of threads MS1 refers to a parameter used when initializing the maximum number of threads in the thread pool.
[0082] The initialized core thread number CS1 refers to the parameter used when initializing the core thread number size of the thread pool, and the core thread number size (corePoolSize, CS) refers to the minimum number of threads that the thread pool needs to maintain, unless the core thread is allowed to time out and exit.
[0083] The initialization thread pool queue size refers to the parameter used when initializing the thread pool queue size of the thread pool, and the thread pool queue size (queueSize, QS) refers to the maximum value of the thread pool queue.
[0084] S202, initializing the thread pool parameters corresponding to each SMS channel according to the initialization thread pool parameters;
[0085] According to some embodiments, the initialization thread pool parameters corresponding to each SMS channel in the SMS channel set can be stored in a database. Thereafter, when the thread pool parameters corresponding to each SMS channel are initialized according to the initialization thread pool parameters, the thread pool parameters corresponding to each SMS channel can be initialized according to the initialization thread pool parameters read from the database.
[0086] In some embodiments, the database may adopt a key-value memory database, for example, Redis, which has extremely high read and write performance, can increase the speed of obtaining the initialization thread pool parameters, and increase the initialization speed of the thread pool.
[0087] S203, obtaining the to-be-sent short message from the to-be-sent short message pool, and determining the unavailable short message channel subset in the short message channel set;
[0088] According to some embodiments, when sending a text message, a text message to be sent may be popped out from a pool of text messages to be sent, thereby obtaining the text message to be sent from the pool of text messages to be sent.
[0089] In some embodiments, the unavailable SMS channel subset refers to a set formed by gathering the unavailable SMS channels in the SMS channel set.
[0090] In some embodiments, the unavailable SMS channel in the SMS channel set may be determined based on at least one of the following factors:
[0091] Anti-disturbance time, for example, you can set the bulk SMS channel at night as an unavailable SMS channel;
[0092] SMS channel maintenance period, for example, the SMS channel during the SMS channel maintenance period can be set as an unavailable SMS channel;
[0093] The number of consecutive failures of the SMS channel. For example, when the number of consecutive failures of the SMS channel reaches the consecutive failure warning value, the SMS channel will be set as an unavailable SMS channel, and an alarm message will be sent to the operation and maintenance personnel. The operation and maintenance personnel can handle it according to the actual situation. If it is not handled within the preset timeout period, the SMS channel can be automatically set to an available SMS channel.
[0094] It should be noted that when it is confirmed that a certain SMS channel changes from an available SMS channel to an unavailable SMS channel, it can be saved in the unavailable channel list in the database; when it is confirmed that a certain SMS channel changes from an unavailable SMS channel to an available SMS channel, it can be removed from the unavailable channel list. In this case, when determining the unavailable SMS channel subset in the SMS channel set, the current unavailable channel list can be obtained from the database, and the unavailable SMS channel subset in the SMS channel set can be determined based on the current unavailable channel list, thereby increasing the speed of determining the unavailable SMS channel subset.
[0095] S204, determining availability information of the SMS channels in the SMS channel set in order of priority, until the availability information indicates that the SMS channel is an available SMS channel, thereby obtaining a first SMS channel;
[0096] According to some embodiments, the priority of each SMS channel in a preset SMS channel set can be stored in a database. Then, before obtaining the SMS to be sent from the SMS pool, each SMS channel is configured with a preset priority read from the database, and the priority is dynamically adjusted during the subsequent SMS sending process.
[0097] In some embodiments, when dynamically adjusting the priority of a SMS channel, the number of transactions per second, average response time, and current maximum number of threads corresponding to each SMS channel in the SMS channel set can be obtained at intervals of a first preset time; the priority of each SMS channel is determined based on the number of transactions per second, average response time, and current maximum number of threads. The first preset time does not specifically refer to a fixed time, and the first preset time can be determined based on the actual application scenario.
[0098] In some embodiments, the average speed of the thread pool processing SMS sending tasks can be calculated based on the number of transactions per second, the average response time, and the current maximum number of threads, as shown in the following formula:
[0099] V=min(TPS T ,1000 / RT T *MS T )
[0100] Among them, V is the average speed of the thread pool processing SMS sending tasks, T is the first preset time, TPS T The current number of transactions per second obtained after the first preset time interval T, RT T is the current average response time obtained after the first preset time interval T, MS T The current maximum number of threads obtained after the first preset time interval T.
[0101] Next, the calculated average speed of the thread pool processing SMS sending tasks corresponding to each SMS channel can be sorted by size. The larger the average speed of the thread pool processing SMS sending tasks, the higher the priority. The priority of the SMS channel in the database is updated according to the calculated priority.
[0102] According to some embodiments, the availability information is used to indicate whether the SMS channel is available for SMS sending. For example, if the SMS channel is in the subset of unavailable SMS channels, the availability information indicates that the SMS channel is an unavailable SMS channel; if the SMS channel is not in the subset of unavailable SMS channels, the availability information indicates that the SMS channel is an available SMS channel.
[0103] In some embodiments, when the availability information of all SMS channels in the SMS channel set indicates that the SMS channel is an unavailable SMS channel, the SMS channel is dormant for a second preset time period, and the unavailable SMS channel subset is re-determined, and the availability information of the SMS channels is determined in order of priority until the availability information indicates that the SMS channel is an available SMS channel, thereby obtaining the first SMS channel.
[0104] In some embodiments, the second preset duration does not specifically refer to a fixed duration, and the second preset duration can be determined according to actual application scenarios. The second preset duration can be, for example, 1 minute.
[0105] Taking a scenario as an example, after obtaining the SMS to be sent from the SMS pool, the highest priority SMS channel can be obtained from Redis, and the list of unavailable channels can be obtained from Redis to determine whether the highest priority SMS channel is available. If available, the process continues. If unavailable, the next priority SMS channel is obtained until an available SMS channel is obtained. If all SMS channels are unavailable, sleep for 1 minute, and then re-determine the available channels from the highest priority until the first SMS channel is obtained.
[0106] S205, obtaining current thread pool parameters of the thread pool corresponding to the first SMS channel;
[0107] According to some embodiments, the current thread pool parameters refer to the current parameters of the thread pool, including but not limited to the current thread pool parameters including the current number of active threads, the current number of thread pool queues, the current maximum number of threads, and the current thread pool queue size.
[0108] In some embodiments, the current number of active threads refers to the current number of active threads in the thread pool. The number of active threads (activeCount, AC) refers to the number of threads that are executing tasks in the thread pool.
[0109] In some embodiments, the current thread pool queue number refers to the current thread pool queue number of the thread pool. The thread pool queue number (workQueue, WQ) refers to the size of the task queue to be executed. When the number of submitted tasks exceeds CS, the tasks submitted are stored here.
[0110] In some embodiments, the current maximum number of threads refers to the current maximum number of threads in the thread pool, wherein the maximum number of threads MS is not greater than the maximum number of threads that can be configured MS2 and not less than the initialization maximum number of threads MS1.
[0111] In some embodiments, the current thread pool queue size refers to the current thread pool queue size of the thread pool.
[0112] It should be noted that when sending a text message, the thread pool parameters of the thread pool are adjusted according to the running information of the thread pool.
[0113] In some embodiments, the operation information of the thread pool can be recorded in the form of a log during the SMS sending process. For example, when the priority of the SMS channel is dynamically adjusted, the TPS of each SMS channel can be recorded. T , RT T ,MS T , the current number of active threads AC obtained after the first preset time interval T T , the current thread pool queue number WQ obtained after the first preset time interval TT As a log record.
[0114] According to some embodiments, the thread pool parameters of the thread pool may be adjusted in the following manner:
[0115] If the load of the thread pool is greater than the load warning value WL2 for a first preset number of times WL1, and the average response time RT corresponding to the thread pool is less than the first response time warning value WL3, the maximum number of threads MS in the thread pool is increased according to the first step, but the maximum number of threads cannot exceed the maximum configurable number of threads MS2.
[0116] If the average response time RT corresponding to the thread pool is not less than the first response time warning value WL3 and less than the second response time warning value RL1, the thread pool parameters remain unchanged;
[0117] If the average response time RT corresponding to the thread pool is not less than the second response time warning value RL1 for the second preset number of times RL2, the maximum number of threads MS is reduced by half, but the minimum number cannot be less than the initial maximum number of threads MS1;
[0118] If the load is less than the load idle value ID2 for a third consecutive preset number of times ID1, the maximum number of threads is reduced according to the second step length, but the minimum number of threads cannot be less than the initialization maximum number of threads MS1;
[0119] In all cases except the above, the thread pool parameters can remain unchanged.
[0120] In some embodiments, the load is determined by the number of active threads AC and the maximum number of threads MS of the thread pool, which can be expressed as:
[0121] Load = AC / MS*100%
[0122] In some embodiments, relevant parameters involved in adjusting the thread pool parameters of the thread pool, such as WL1, WL2, WL3, MS2, RL1, RL2, ID1, and ID2, can all be pre-stored in a database, and then the relevant parameters can be read from the database to adjust the thread pool parameters of the thread pool, thereby improving the adjustment speed.
[0123] S206, determining the working state of the thread pool according to the current thread pool parameters;
[0124] According to some embodiments, if the sum of the current number of active threads and the current number of thread pool queues is less than the sum of the current maximum number of threads and the current thread pool queue size, it can be determined that the working state of the thread pool indicates that the thread pool is in a non-saturated state;
[0125] In some embodiments, if the sum of the current number of active threads and the current number of thread pool queues is not less than the sum of the current maximum number of threads and the current thread pool queue size, it can be determined that the working status indicates that the thread pool is in a saturated state.
[0126] S207, when the working status indicates that the thread pool is in a saturated state, setting the first SMS channel as an unavailable SMS channel, and re-determining the first SMS channel from the SMS channel set until the working status indicates that the thread pool is in a non-saturated state, thereby obtaining a second SMS channel;
[0127] Taking a scenario as an example, after obtaining the first SMS channel, it can be determined whether the working status of the channel thread pool is saturated. If it is not saturated, the SMS sending task is submitted to the thread pool of the first SMS channel; if it is saturated, the available SMS channels of the next priority are obtained until the first SMS channel with a saturated working status is obtained; if all working statuses indicate that the thread pool is in a saturated state, it can be dormant for a third preset time length, and the first SMS channel can be reselected until the second SMS channel is obtained.
[0128] In some embodiments, the third preset duration does not specifically refer to a fixed duration, and the first preset duration can be adjusted according to the actual application scenario. The first preset duration can be, for example, 100 ms.
[0129] S208: Use the thread pool corresponding to the second SMS channel to send the SMS to be sent.
[0130] According to some embodiments, after sending the SMS to be sent using the thread pool corresponding to the second SMS channel, the process may return to step S203 to obtain the SMS to be sent from the SMS pool to be sent again until all the SMS to be sent in the SMS pool are sent.
[0131] Take a scenario as an example. Figure 2 The following is a flow chart of a method for sending short messages provided by an embodiment of the present disclosure. Figure 2As shown, when starting to send a text message, first, the text message channel thread initialization, the text message channel priority initialization and the text message channel availability initialization can be performed; then, if the text message to be sent can be obtained from the text message pool to be sent, the text message channel is obtained according to the priority through the text message channel priority management module, and the text message channel availability management module is used to determine whether the channel is available. If the channel is not available, the text message channel is obtained again according to the priority until the channel is determined to be available; then, the current thread pool parameters of the thread pool corresponding to the channel are obtained, wherein the thread pool parameters of the thread pool are managed by the text message channel thread pool management module; then, according to the current thread pool parameters of the thread pool, it is determined whether the thread pool is fully loaded, that is, whether it is saturated. If it is fully loaded, the text message channel is obtained again according to the priority; if it is not fully loaded, the text message is submitted to the thread pool, and the text message to be sent is obtained again until the text message to be sent cannot be obtained from the text message pool to be sent.
[0132] In some embodiments, the SMS channel priority management module can be used to perform priority calculation and dynamic adjustment, and can also obtain the TPS of each SMS channel. T , RT T ,MS T , AC T , WQ T The relevant parameters are recorded as logs for subsequent use. When the SMS channel priority is initialized, the priority in the SMS channel priority management module is initialized.
[0133] In some embodiments, the SMS channel thread pool management module can be used to determine whether to adjust the thread pool parameters according to the log records. Wherein, the thread pool parameters in the SMS channel thread pool management module are initialized when the SMS channel thread is initialized.
[0134] In some embodiments, the SMS channel availability management module includes factors used when determining unavailable SMS channels in the SMS channel set, and can manage the unavailable channel list according to the factors. The unavailable channel list can be initialized when initializing the SMS channel availability.
[0135] In summary, the method provided in this embodiment can improve the resource utilization, SMS sending rate and stability of SMS sending by monitoring the TPS and RT of each SMS channel on the basis of configuring the SMS channel set, and dynamically adjusting the SMS channel priority and channel thread pool configuration.
[0136] In order to implement the above embodiment, the present disclosure also proposes a device for sending short messages.
[0137] like Figure 3 As shown, the short message sending device 300 includes:
[0138] The channel determination unit 301 is used to obtain the to-be-sent short message from the to-be-sent short message pool, and determine the first short message channel from the short message channel set, wherein the first short message channel is the available short message channel with the highest priority in the short message channel set, and the priority is determined by the number of transactions per second, the average response time, and the current maximum number of threads corresponding to the short message channel;
[0139] The state determination unit 302 is used to determine the working state of the thread pool corresponding to the first SMS channel, and when the working state indicates that the thread pool is in a saturated state, set the first SMS channel as an unavailable SMS channel, and re-determine the first SMS channel from the SMS channel set until the working state indicates that the thread pool is in a non-saturated state, thereby obtaining a second SMS channel;
[0140] The SMS sending unit 303 is used to use the thread pool corresponding to the second SMS channel to send the SMS to be sent.
[0141] Optionally, the channel determining unit 301 is further configured to:
[0142] At first preset time intervals, the number of transactions per second, the average response time, and the current maximum number of threads corresponding to each SMS channel in the SMS channel set are obtained;
[0143] Determine the priority of each SMS channel based on the number of transactions per second, average response time, and current maximum number of threads.
[0144] Optionally, when the channel determination unit 301 is used to determine the first SMS channel from the SMS channel set, it is specifically used to:
[0145] Determine a subset of unavailable SMS channels in the SMS channel set;
[0146] The availability information of the SMS channels in the SMS channel set is determined in sequence according to the priority order until the availability information indicates that the SMS channel is an available SMS channel, thereby obtaining a first SMS channel; wherein, if the SMS channel is in a subset of unavailable SMS channels, the availability information indicates that the SMS channel is an unavailable SMS channel; if the SMS channel is not in the subset of unavailable SMS channels, the availability information indicates that the SMS channel is an available SMS channel.
[0147] Optionally, the channel determining unit 301 is further configured to:
[0148] When the availability information of all SMS channels in the SMS channel set indicates that the SMS channel is an unavailable SMS channel, the SMS channel is dormant for a second preset time period, and the unavailable SMS channel subset is re-determined, and the availability information of the SMS channels is determined in order of priority until the availability information indicates that the SMS channel is an available SMS channel, thereby obtaining a first SMS channel.
[0149] Optionally, when the state determination unit 302 is used to determine the working state of the thread pool corresponding to the first SMS channel, it is specifically used to:
[0150] Obtain current thread pool parameters of the thread pool corresponding to the first SMS channel, wherein the current thread pool parameters include the current number of active threads, the current number of thread pool queues, the current maximum number of threads, and the current thread pool queue size;
[0151] If the sum of the current number of active threads and the current number of thread pool queues is less than the sum of the current maximum number of threads and the current thread pool queue size, then determining that the working state of the thread pool indicates that the thread pool is in an unsaturated state;
[0152] If the sum of the current number of active threads and the current number of thread pool queues is not less than the sum of the current maximum number of threads and the current thread pool queue size, then it is determined that the working state indicates that the thread pool is in a saturated state.
[0153] Optionally, the state determination unit 302 is further configured to:
[0154] If the load of the thread pool is greater than the load warning value for a first preset number of times in a row, and the average response time corresponding to the thread pool is less than the first response time warning value, the maximum number of threads in the thread pool is increased according to the first step, wherein the maximum number of threads is not greater than the maximum number of threads that can be configured, and the load is determined by the number of active threads and the maximum number of threads in the thread pool;
[0155] If the average response time corresponding to the thread pool is not less than the first response time warning value and less than the second response time warning value, the thread pool parameters remain unchanged;
[0156] If the average response time corresponding to the thread pool is not less than the second response time warning value for a second preset number of times in a row, the maximum number of threads is reduced by half, wherein the maximum number of threads is not less than the initialized maximum number of threads;
[0157] If the load is less than the load idle value for a third consecutive preset number of times, the maximum number of threads is reduced according to a second step length.
[0158] Optionally, before obtaining the to-be-sent short message from the to-be-sent short message pool, the channel determination unit 301 is further configured to:
[0159] Obtain the initialization thread pool parameters corresponding to each SMS channel in the SMS channel set, wherein the initialization thread pool parameters include the initialization maximum number of threads, the initialization core number of threads, and the initialization thread pool queue size;
[0160] Initialize the thread pool parameters corresponding to each SMS channel according to the initialization thread pool parameters.
[0161] It should be noted that the above explanation of the SMS sending method embodiment is also applicable to the SMS sending device of this embodiment, and will not be repeated here.
[0162] In summary, the device provided by the embodiment of the present disclosure determines the priority of each SMS in the SMS channel set according to the number of transactions per second, the average response time and the current maximum number of threads corresponding to the SMS channel, and when sending the SMS, selects the available SMS channel with the highest priority and the corresponding thread pool in a non-saturated state from the SMS channel set to complete the sending of the SMS to be sent. Therefore, it can make full use of resources and improve the SMS sending rate while ensuring the stability of the SMS channel.
[0163] In order to implement the above embodiments, the present disclosure also proposes an electronic device, including: a processor, and a memory communicatively connected to the processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory to implement the method provided by the above embodiments.
[0164] In order to implement the above embodiments, the present disclosure further proposes a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the methods provided by the above embodiments.
[0165] In order to implement the above embodiments, the present disclosure also proposes a computer program product, including a computer program, which implements the methods provided by the above embodiments when executed by a processor.
[0166] The collection, storage, use, processing, transmission, provision and disclosure of user personal information involved in this disclosure shall comply with the relevant laws and regulations and shall not violate public order and good morals.
[0167] It should be noted that personal information from users should be collected for legitimate and reasonable purposes and should not be shared or sold outside of these legitimate uses. In addition, such collection / sharing should be carried out after receiving the user's informed consent, including but not limited to notifying the user to read the user agreement / user notice and sign the agreement / authorization including authorization of relevant user information before the user uses the function. In addition, any necessary steps should be taken to protect and safeguard access to such personal information data and ensure that others who have access to personal information data comply with its privacy policy and procedures.
[0168] The present disclosure anticipates providing implementation schemes for users to selectively block the use or access of personal information data. That is, the present disclosure anticipates providing hardware and / or software to prevent or block access to such personal information data. Once the personal information data is no longer needed, risks can be minimized by limiting data collection and deleting the data. In addition, when applicable, such personal information is de-identified to protect the privacy of the user.
[0169] The acquisition, transmission, storage, use, and processing of data in the technical solution disclosed in this disclosure are in compliance with the relevant provisions of national laws and regulations.
[0170] It should be noted that in the embodiments of the present disclosure, certain software, components, models and other existing solutions in the industry may be mentioned, which should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.
[0171] In the description of the aforementioned embodiments, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present disclosure. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, unless they are contradictory.
[0172] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of the present disclosure, "plurality" means at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0173] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a custom logical function or process, and the scope of the preferred embodiments of the present disclosure includes additional implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present disclosure belong.
[0174] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute the instructions), or in combination with these instruction execution systems, devices or apparatuses. For the purpose of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in combination with these instruction execution systems, devices or apparatuses. More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic device), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), a fiber optic device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or otherwise processing in a suitable manner if necessary, and then stored in a computer memory.
[0175] It should be understood that the various parts of the present disclosure can be implemented in hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, multiple steps or methods can be implemented in software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, any one of the following technologies known in the art or a combination thereof can be used to implement: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0176] A person skilled in the art may understand that all or part of the steps in the above-mentioned embodiment method may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.
[0177] In addition, each functional unit in each embodiment of the present disclosure may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.
[0178] The storage medium mentioned above may be a read-only memory, a disk or an optical disk, etc. Although the embodiments of the present disclosure have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations of the present disclosure. A person of ordinary skill in the art may change, modify, replace and modify the above embodiments within the scope of the present disclosure.
Claims
1. A method for sending a text message, characterized in that: include: Obtaining a to-be-sent short message from a to-be-sent short message pool, and determining a first short message channel from a set of short message channels, wherein the first short message channel is an available short message channel with the highest priority in the set of short message channels, and the priority is determined by the number of transactions per second, the average response time, and the current maximum number of threads corresponding to the short message channel; Determine the working state of the thread pool corresponding to the first SMS channel, and if the working state indicates that the thread pool is in a saturated state, set the first SMS channel as an unavailable SMS channel, and re-determine the first SMS channel from the SMS channel set until the working state indicates that the thread pool is in a non-saturated state, thereby obtaining a second SMS channel; Use the thread pool corresponding to the second SMS channel to send the SMS to be sent.
2. The method according to claim 1, characterized in that: The method further comprises: At first preset time intervals, the number of transactions per second, the average response time, and the current maximum number of threads corresponding to each SMS channel in the SMS channel set are obtained; The priority of each SMS channel is determined according to the number of transactions per second, the average response time, and the current maximum number of threads.
3. The method according to claim 1, characterized in that The determining the first SMS channel from the SMS channel set includes: Determine a subset of unavailable SMS channels in the SMS channel set; The availability information of the SMS channels in the SMS channel set is determined in sequence according to the order of priority until the availability information indicates that the SMS channel is an available SMS channel, thereby obtaining a first SMS channel; wherein, if the SMS channel is in the subset of unavailable SMS channels, the availability information indicates that the SMS channel is an unavailable SMS channel; if the SMS channel is not in the subset of unavailable SMS channels, the availability information indicates that the SMS channel is an available SMS channel.
4. The method according to claim 3, characterized in that The method further comprises: When the availability information of all SMS channels in the SMS channel set indicates that the SMS channel is an unavailable SMS channel, hibernation is performed for a second preset time period, and the unavailable SMS channel subset is re-determined, and the availability information of the SMS channels is determined in order of priority until the availability information indicates that the SMS channel is an available SMS channel, thereby obtaining a first SMS channel.
5. The method according to claim 1, characterized in that The determining the working status of the thread pool corresponding to the first SMS channel includes: Obtaining current thread pool parameters of the thread pool corresponding to the first SMS channel, wherein the current thread pool parameters include the current number of active threads, the current number of thread pool queues, the current maximum number of threads, and the current thread pool queue size; If the sum of the current number of active threads and the current number of queues in the thread pool is less than the sum of the current maximum number of threads and the current thread pool queue size, determining that the working state of the thread pool indicates that the thread pool is in an unsaturated state; If the sum of the current number of active threads and the current number of thread pool queues is not less than the sum of the current maximum number of threads and the current thread pool queue size, it is determined that the working status indicates that the thread pool is in a saturated state.
6. The method according to claim 5, characterized in that The method further comprises: If the load of the thread pool is greater than the load warning value for a first preset number of times in a row, and the average response time corresponding to the thread pool is less than the first response time warning value, the maximum number of threads in the thread pool is increased according to the first step, wherein the maximum number of threads is not greater than the maximum number of threads that can be configured, and the load is determined by the number of active threads in the thread pool and the maximum number of threads; If the average response time corresponding to the thread pool is not less than the first response time warning value and less than the second response time warning value, the thread pool parameters remain unchanged; If the average response time corresponding to the thread pool is not less than the second response time warning value for a second preset number of times in a row, the maximum number of threads is reduced by half, wherein the maximum number of threads is not less than the initialized maximum number of threads; If the load is less than the load idle value for a third consecutive preset number of times, the maximum number of threads is reduced according to a second step size.
7. The method according to claim 1, characterized in that Before acquiring the short message to be sent from the short message pool to be sent, the method further includes: Obtaining the initialization thread pool parameters corresponding to each SMS channel in the SMS channel set, wherein the initialization thread pool parameters include the initialization maximum number of threads, the initialization core number of threads, and the initialization thread pool queue size; The thread pool parameters corresponding to each SMS channel are initialized according to the initialization thread pool parameters.
8. A device for sending short messages, characterized in that: include: A channel determination unit, configured to obtain a to-be-sent short message from a to-be-sent short message pool, and determine a first short message channel from a set of short message channels, wherein the first short message channel is an available short message channel with the highest priority in the set of short message channels, and the priority is determined by the number of transactions per second, the average response time, and the current maximum number of threads corresponding to the short message channel; a state determination unit, configured to determine a working state of a thread pool corresponding to the first SMS channel, and, if the working state indicates that the thread pool is in a saturated state, set the first SMS channel as an unavailable SMS channel, and re-determine the first SMS channel from the SMS channel set until the working state indicates that the thread pool is in a non-saturated state, thereby obtaining a second SMS channel; The SMS sending unit is used to send the SMS to be sent by using the thread pool corresponding to the second SMS channel.
9. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 7 when executed by a processor.
11. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 7 when being executed by a processor.