Data processing method and server cluster

By generating random numbers in a distributed manner in a server cluster and using the computing nodes of the distributed system to generate true random numbers in parallel, the problems of /dev/random blocking and /dev/urandom low quality in the Linux operating system are solved, and efficient and stable random number acquisition is achieved.

CN118796150BActive Publication Date: 2025-09-16XFUSION DIGITAL TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410969098.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-18
Publication Date
2025-09-16
Estimated Expiration
2044-07-18

AI Technical Summary

Technical Problem

In the Linux operating system, the /dev/random device will be blocked when the entropy source is insufficient, resulting in low efficiency in random number generation. The random numbers generated by /dev/urandom are of low quality and cannot meet high security requirements.

Method used

By distributing random numbers in a server cluster, using the computing nodes of the distributed system to generate random numbers in parallel, and combining the /dev/random device to generate true random numbers, we can avoid blocking caused by insufficient entropy sources on a single server, and use the horse racing mechanism to improve acquisition efficiency.

Benefits of technology

Under the premise of ensuring the quality of random numbers, the efficiency of obtaining random numbers is improved, blocking is avoided, and the stability and response speed of the system are improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118796150B_ABST
    Figure CN118796150B_ABST
Patent Text Reader

Abstract

A data processing method, applied to a first server, wherein the first server is any one of multiple servers in a server cluster, comprises: the first server receiving a first request, wherein the first request is for obtaining N random numbers, where N ≥ 1; the first server distributing a second request to a server in the server cluster other than the first server, wherein the second server is for obtaining M random numbers, where M is a positive integer less than or equal to N; and when the number of random numbers obtained by the first server reaches N, the first server sending the N random numbers. The advantage of this application is that it can improve acquisition efficiency while ensuring the quality of random numbers.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of servers, and in particular to a data processing method and a server cluster. Background Art

[0002] Random numbers play a key role in computer science and are widely used in cryptography, simulation, security, and other fields. In the Linux operating system, random number generation is closely related to the / dev / random and / dev / urandom devices. Because / dev / random prioritizes random number generation quality, the system will block when the entropy source is insufficient. / dev / urandom, on the other hand, generates pseudo-random numbers using existing random numbers without blocking, but the quality of the random numbers it produces is inferior to / dev / random. Summary of the Invention

[0003] In order to solve the above problems, the embodiments of the present application provide a data processing method and a server cluster, which can improve the efficiency of obtaining random numbers while ensuring the quality of random numbers.

[0004] To this end, the following technical solutions are adopted in the embodiments of the present application:

[0005] In a first aspect, an embodiment of the present application provides a data processing method, which is applied to a first server, where the first server is any one of multiple servers in a server cluster, and the method includes: the first server receives a first request, where the first request is used to request N random numbers, where N≥1; the first server distributes a second request to servers other than the first server in the server cluster, where the second request is used to request M random numbers, where M is a positive integer less than or equal to N; when the number of random numbers obtained by the first server reaches N, the first server sends the N random numbers.

[0006] In this embodiment, random numbers are generated and collected on server cluster nodes in a distributed environment to improve the efficiency of random number acquisition. The efficiency of random number acquisition depends on the fastest server, which generally provides the most abundant entropy source as a computing node, thereby ensuring the quality of the random numbers. For example, by utilizing the computing nodes of a distributed system to generate random numbers, random number collection can be performed in parallel, thereby improving the efficiency of random number acquisition. Furthermore, by utilizing the servers of a distributed system to generate random numbers, blocking situations caused by insufficient entropy sources on a single server can be avoided, thereby resolving the problem of random number generation blocking.

[0007] Exemplarily, the second request may be the first request directly distributed by the first server. In this way, multiple servers in the server cluster may be used to synchronously generate random numbers. By utilizing the horse racing mechanism, the speed of obtaining random numbers can be improved while ensuring the quality of random numbers.

[0008] For example, as an achievable implementation, M is equal to N, and when the number of random numbers obtained by the first server reaches N, the first server sends the N random numbers, including: the first server generates N random numbers, and the first server sends the N random numbers generated by the first server.

[0009] In this embodiment, the first server generates random numbers at a higher rate than the servers in the server cluster except the first server. The N random numbers generated by the first server with the fastest sending rate can ensure the speed of obtaining random numbers.

[0010] For another example, as a feasible implementation, M is equal to N, and when the number of random numbers obtained by the first server reaches N, the first server sends the N random numbers, including: the first server obtains N random numbers from the second server, and the first server sends the N random numbers obtained by the first server, wherein the second server generates N random numbers faster than the first server generates N random numbers.

[0011] As an achievable implementation, the first server stores N random numbers, and when the number of random numbers obtained by the first server reaches N, the first server sends the N random numbers, including: the first server sends the N random numbers stored by the first server.

[0012] In this embodiment, the first server stores the generated random numbers during the process of generating random numbers, and can directly obtain the generated random numbers in subsequent uses, avoiding repeated generation and improving the efficiency of random number acquisition.

[0013] For example, as a feasible implementation, the first server stores K random numbers, M=NK in the second request, and when the number of random numbers obtained by the first server reaches N, the first server sends the N random numbers, including: the first server obtains M random numbers from the second server, the first server sends the M random numbers obtained from the second server and the K random numbers stored by the first server, wherein the second server is the server that generates M random numbers the fastest among other servers.

[0014] Therefore, as an achievable implementation method, after the first server sends the N random numbers, the method further includes: the first server stores the random numbers that have not been sent.

[0015] In this embodiment, the first server stores the unsent random numbers, so that the first server can quickly respond to the next request for obtaining random numbers, thereby further improving the random number acquisition speed.

[0016] As an achievable implementation, after the number of random numbers obtained by the first server reaches N, the method further includes: generating a stop signal and sending it to servers in the server cluster except the first server, so that other servers stop generating random numbers.

[0017] In this embodiment, once the first server in a server cluster has generated a sufficient number of random numbers, it sends a stop signal to halt random number generation for the remaining servers in the cluster. This effectively controls the random number generation and collection process, avoiding resource waste and data confusion. Furthermore, by sending the stop signal, each server can promptly stop generating random numbers, ensuring server stability and operational efficiency.

[0018] As a feasible implementation, the random number is a true random number.

[0019] In this implementation, the server generates true random numbers using the server's / dev / random device, an entropy source provided by the Linux system. The / dev / random device generates true random numbers by collecting information such as system environmental noise and hardware device changes. This device provides high randomness and can meet security-critical applications. The / dev / random device on the server is a built-in entropy source, eliminating the need for additional hardware or software support, making true random number generation easy.

[0020] As an achievable implementation, the method for generating true random numbers includes: collecting environmental noise from an entropy source into an entropy pool, the environmental noise including one or more of keyboard input, mouse movement, and hard disk I / O; calculating an entropy value of the entropy pool; and generating a true random number in the entropy pool based on the entropy value being greater than a first threshold.

[0021] In this embodiment, by collecting data from multiple sources such as environmental noise into the entropy pool, the randomness and unpredictability of random numbers can be increased, generating higher-quality true random numbers. By calculating the entropy value and setting a threshold, true random numbers can be dynamically generated based on the degree of randomness in the entropy pool, ensuring the quality and security of the generated random numbers. By calculating the entropy value and setting a threshold, true random numbers can be dynamically generated based on the degree of randomness in the entropy pool, ensuring the quality and security of the generated random numbers.

[0022] In a second aspect, an embodiment of the present application also provides a data processing method, which is applied to a second server, and the second server is arranged in a server cluster. The server cluster also includes a first server, and the first server is used to send N random numbers to the client. The method includes: receiving a second request sent by the first server, and the second request is used to request to obtain M random numbers; when the number of random numbers obtained by the second server reaches M, sending the M random numbers to the first server, so that the first server obtains N random numbers.

[0023] In this embodiment, through the configuration of the server cluster, the second server can share the task of random number generation, use all servers in the server cluster to generate random numbers, and respond to random number acquisition requests more quickly, thereby improving acquisition efficiency while ensuring the quality of random numbers.

[0024] As an achievable implementation, the second server stores M random numbers, and the second server sends the stored M random numbers to the first server.

[0025] As a feasible implementation manner, the second server receives a termination signal and stops generating random numbers.

[0026] As a feasible implementation, after stopping generating random numbers, the second server stores the random numbers that have been generated.

[0027] In a third aspect, an embodiment of the present application also provides a first server, comprising: an interaction module, the interaction module being used to receive a first request, the first request being used to request N random numbers, where N≥1; the interaction module being further used to distribute a second request to servers other than the first server in the server cluster, the second request being used to request M random numbers, where M is a positive integer less than or equal to N; the interaction module being further used to send the N random numbers when the number of random numbers obtained by the first server reaches N.

[0028] As an achievable implementation, the first server further includes: a collection module, which collects random numbers generated by the first server based on the first request and sends the collected N random numbers to the interaction module.

[0029] In a fourth aspect, an embodiment of the present application also provides a second server, comprising: an interaction module, the interaction module being used to receive a second request sent by the first server, the second request being used to request M random numbers; the interaction module being further used to send the M random numbers to the first server when the number of random numbers obtained by the second server reaches M, so that the first server obtains N random numbers.

[0030] As a feasible implementation, the second server further includes a collection module, which collects random numbers generated by the second server based on the second request and sends the collected M random numbers to the interaction module.

[0031] In a fifth aspect, an embodiment of the present application further provides a server cluster, comprising a first server and a second server, wherein the first server is used to execute the method of the first aspect, and the second server is used to execute the method of the second aspect.

[0032] In a sixth aspect, an embodiment of the present application further provides a server, comprising a memory and a processor coupled; the memory is used to store programs; and the processor is used to call the programs stored in the memory to execute the method of the first aspect or the second aspect.

[0033] In a seventh aspect, embodiments of the present application provide a storage medium storing program instructions. When the program instructions are executed on a server, the server executes the data processing method described in the first aspect or the second aspect, and any implementation thereof. The beneficial effects thereof are as described in the first aspect and are not further elaborated here.

[0034] In an eighth aspect, embodiments of the present application provide a computer program product comprising program instructions. When the program instructions are executed on a server, the server is caused to execute the data processing method involved in the first aspect or the second aspect, and any implementation thereof. The beneficial effects thereof are as described in the first aspect and are not further elaborated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] Figure 1 A system architecture diagram showing an application scenario of the data processing method provided in an embodiment of the present application;

[0036] FIG2( a ) shows a schematic diagram of the structure of any server in the server cluster provided in an embodiment of the present application;

[0037] FIG2( b ) shows a schematic structural diagram of a first server provided in an embodiment of the present application;

[0038] Figure 3 A flow chart of a data processing method provided by an embodiment of the present application is shown;

[0039] Figure 4 A flowchart of another data processing method provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0040] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.

[0041] In the description of the embodiments of the present application, words such as "exemplary," "for example," or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary," "for example," or "for example" in the embodiments of the present application should not be construed as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary," "for example," or "for example" is intended to present the relevant concepts in a concrete manner.

[0042] In the description of the embodiments of this application, the term "and / or" is simply a description of the association relationship between associated objects, indicating that three relationships can exist. For example, A and / or B can represent the following three situations: A exists alone, B exists alone, and A and B exist at the same time. In addition, unless otherwise specified, the term "plurality" means two or more. For example, "multiple systems" refers to two or more systems, and "multiple terminals" refers to two or more terminals.

[0043] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly identifying the technical features being referred to. Thus, features specified as "first" or "second" may explicitly or implicitly include one or more of such features. The terms "include," "comprising," "having," and their variations all mean "including but not limited to," unless otherwise specifically emphasized.

[0044] In the description of the embodiments of the present application, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it can be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments, and may be combined with each other without conflict.

[0045] In the description of the embodiments of the present application, the terms "first\second\third, etc." or module A, module B, module C, etc. are only used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that the specific order or sequence can be interchanged where permitted so that the embodiments of the present application described here can be implemented in an order other than that illustrated or described here.

[0046] In the description of the embodiments of the present application, the numbers representing the steps, such as S31, S32, etc., do not necessarily mean that the steps must be executed in this manner. If permitted, the order of the previous and next steps can be interchanged, or they can be executed simultaneously.

[0047] Related terms involved in the embodiments of this application:

[0048] Random numbers (RN): Random numbers are numerical values ​​generated according to a specific pattern or probability distribution, characterized by unpredictability and disorder. Random numbers are widely used in computer science, statistics, mathematics, and other fields. For example, random numbers are used to generate parameters in encryption algorithms, such as keys and initialization vectors (IVs), to enhance security. Alternatively, in databases and data analysis, random numbers are used to generate test data. In statistics and mathematics, random numbers are used to study random processes, probability distributions, and sampling. Random number generators can be categorized as true random number generators (TRNGs) and pseudo-random number generators (PRNGs), depending on their generation method. True random number generators, such as / dev / random, rely on physical processes to generate true random numbers: for example, coin tossing, dice rolling, spinning wheels, noise from electronic components, quantum mechanical processes, thermal noise, and atmospheric noise. The uncertainty inherent in these physical processes determines the randomness of the generated values. The advantage of true random numbers is their high degree of randomness, but their disadvantages are slow generation and the need for specialized hardware. Pseudorandom number generators, such as / dev / urandom, rely on a deterministic algorithm to generate a sequence of numbers, starting with a seed. This seed and algorithm generate a series of seemingly random numbers. While not truly random, they possess statistical properties similar to those of random numbers, such as uniformity and independence. When calculating pseudorandom numbers, if the initial value (seed) remains unchanged, the sequence of pseudorandom numbers remains unchanged. Pseudorandom numbers can be generated in large quantities using computers. In simulation research, pseudorandom numbers are generally used instead of true random numbers to improve efficiency. The characteristic of pseudorandom numbers is that, given the same seed and algorithm, the generated sequence of numbers is deterministic, yet sufficiently random for practical applications.

[0049] Distributed system (DS): A distributed system consists of multiple computers connected via a network and working together to accomplish a specific task. Distributed systems are designed to improve performance, scalability, and fault tolerance by distributing computing and storage resources across multiple nodes, while mitigating the impact of single points of failure. Typical applications of distributed systems include cloud computing platforms, large-scale data processing systems, and distributed database systems.

[0050] Entropy: Entropy is a concept that represents the uncertainty or information content of a random variable. It measures the average amount of information obtained under a given probability distribution. Entropy quantitatively describes the uncertainty of a random variable. Higher entropy indicates greater uncertainty in the random variable, requiring more information to describe it.

[0051] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing the embodiments of this application only and are not intended to limit this application.

[0052] With the development of computer science, random numbers have been widely used. For example, random numbers are used in encryption and security because randomness is the foundation of reliable cryptographic algorithms. In Linux systems, random numbers can be obtained through / dev / random and / dev / urandom. It should be noted that / dev / random and / dev / urandom are two entropy source devices provided by the Linux kernel. The entropy source manager in the Linux kernel is responsible for maintaining the entropy pool and ensuring sufficient randomness for cryptographic applications. This design is intended to provide secure random numbers and prevent attacks such as password cracking.

[0053] The high-quality random numbers provided by the / dev / random device are generated based on the entropy of truly random events collected in the system environment. These truly random events may include user keyboard input, mouse movement, hard disk I / O, etc. When an application reads random numbers from / dev / random, if there is sufficient randomness available in the entropy pool, it will immediately return the corresponding number of random bytes. However, if the randomness in the entropy pool is insufficient, the read operation will be blocked until the system collects enough random events. Therefore, the random numbers provided by / dev / random have higher randomness and therefore higher quality. However, because / dev / random emphasizes blocking operations, it can only output random numbers when there is sufficient randomness in the entropy pool. Therefore, it may wait until the entropy pool is exhausted, resulting in blocking.

[0054] In other words, / dev / random collects environmental noise from entropy sources, such as keyboard input and mouse movement. The entropy source manager evaluates the randomness of this data and maintains an entropy pool. Only when the entropy pool is sufficiently high can / dev / random generate high-quality random numbers for cryptography and security applications. When the entropy pool is insufficient, / dev / random waits for more entropy, resulting in a blocking condition. This is because the system considers random numbers generated with insufficient entropy to be sufficiently secure. This design ensures that the generated random numbers are sufficiently random and unpredictable to meet high security requirements, especially in cryptography applications. The blocking condition is due to its design principle of only allowing random number generation when the entropy is sufficiently high. However, this blocking behavior can have undesirable consequences in some situations. For example, during system startup or in environments with limited entropy sources, applications may experience delays while waiting for sufficient entropy, impacting system performance and responsiveness. This may not be ideal for certain applications with high real-time requirements that cannot tolerate blocking.

[0055] In contrast, / dev / urandom is non-blocking and will continue to output random numbers even when the randomness in the entropy pool is low, but this carries a certain theoretical risk. The / dev / urandom device also generates random numbers, but / dev / urandom uses a pseudo-random number generator. Unlike / dev / random, / dev / urandom does not block waiting for a random event. Instead, it uses a pseudo-random number generation algorithm to generate random numbers. Specifically, a PRNG is based on a seed and a deterministic algorithm, typically seeded with data from an entropy source. Even when entropy is insufficient, the PRNG can still generate random numbers, using previously generated random numbers as new seeds. This allows / dev / urandom to continuously provide random numbers without blocking, ensuring system availability. Specifically, this algorithm uses the randomness in the entropy pool and a deterministic algorithm to generate pseudo-random numbers. Therefore, the random numbers provided by / dev / urandom are immediately available in all cases, but may not be as high-quality as those provided by / dev / random.

[0056] Therefore, / dev / urandom has a theoretical security compromise because it doesn't wait for sufficient entropy. In certain high-security scenarios, / dev / random may be more suitable. Furthermore, different Linux systems may implement / dev / urandom slightly differently, which may affect the quality and performance of random numbers.

[0057] Based on this, an embodiment of the present application provides a data processing method and a server cluster. The embodiment of the present application uses a server cluster in a distributed system to prepare random numbers, which can not only fully utilize the randomness of / dev / random, but also use a distributed environment to reduce the probability of blocking during random number preparation.

[0058] In order to more fully understand the present application, the following examples are given. These examples are used to specifically illustrate the embodiments of the present application and should not be understood in any way as limiting the scope of the present application.

[0059] Figure 1 The system architecture diagram of the data processing method provided in the embodiment of the present application is shown. Figure 1 As shown, the application scenario includes an electronic device 100 and a server cluster 200. The electronic device 100 and the server cluster 200 can be linked via wired and / or wireless communication links. A user can use the electronic device 100 to interact with the server cluster 200 to receive or send messages, etc. Exemplarily, the communication network between the electronic device 100 and the server cluster 200 can be a local area network (LAN) or a wide area network (WAN) (such as the Internet). In addition, the electronic device 100 can also establish a communication connection with the server cluster 200 through short-range wireless communication technology, such as through a Bluetooth connection.

[0060] It is understandable that the network established between the electronic device 100 and the server cluster 200 can be implemented using any known network communication protocol. The above-mentioned network communication protocol can be various wired or wireless communication protocols, such as Ethernet, universal serial bus (USB), peripheral component interconnect standard (PCI) bus, extended industry standard architecture (EISA) bus, FireWire, global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), new radio (NR), Bluetooth, wireless fidelity (Wi-Fi) and other communication protocols.

[0061] The electronic device 100 may be any electronic device with a display screen, including but not limited to a smartphone, a tablet computer, a laptop computer, and a desktop computer. The electronic device 100 may be configured with a client, which may be a desktop application, a mobile application, a web application, or a web-based application, without limitation. Furthermore, the number of electronic devices 100 may be one or more, and this application does not impose strict limitations thereon.

[0062] The server cluster 200 can be a logical entity in a distributed system that completes computing work according to a protocol, and can include processes or machines that perform certain tasks. The server cluster 200 can include stateless nodes, which do not need to store their own intermediate state information, such as Nginx (HTTP and reverse proxy web server); the server cluster 200 can also include stateful nodes, and the state and data of stateful nodes can be persisted to media such as disks, such as MySQL (relational database management system). Exemplarily, the server cluster 200 includes multiple servers 201 as computing nodes, for example, it can include three servers 201. Specifically, during the application process, the number of servers can be adjusted according to demand, and this is not limited here. The server 201 can be a rack server, a blade server, or a tower server, and this is not limited here.

[0063] It should be noted that the server in this embodiment can deploy an operating system related to the Linux kernel, such as Fedora, CentOS, etc., and the deployed Linux kernel can provide a / dev / random entropy source device for preparing random numbers to meet the data processing needs of this application. In other possible implementations, the Linux kernel can also provide a / dev / urandom entropy source device.

[0064] It should be understood that the numbers of the above-mentioned clients, distributed server clusters, and servers are merely illustrative and any number of clients, distributed server clusters, and servers may be provided as required.

[0065] It should be noted that the data processing method provided in the embodiment of the present application can generally be executed by a server in a server cluster. The application scenario of the data processing method provided in the embodiment of the present application is the scenario of quickly collecting random numbers. The client can use the server cluster in the distributed system to quickly collect random numbers.

[0066] Figure 2(a) shows a schematic diagram of the structure of any server in the server cluster provided by an embodiment of the present application. As shown in Figure 2(a), any server 201 includes a processor 2011, a memory 2012, and a communication interface 2013. The processor 2011, the memory 2012, and the communication interface 2013 are connected to each other via a bus 2014.

[0067] The processor 2011 may perform various appropriate actions and processes according to the program stored in the memory 2012. The processor 2011 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or a related chipset and / or a dedicated microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 2011 may also include onboard memory for caching purposes. The processor 2011 may include a single processing unit or multiple processing units for performing different actions of the method flow according to the embodiments of the present disclosure.

[0068] The processor 2011 is configured to generate a random number after the server 201 receives a first request (for ease of description, the first request will be referred to as a random number acquisition request in some of the following content) sent by the electronic device 100. The random number acquisition request is used to instruct the server to generate a number N of random numbers requested by the client, where N ≥ 1. The processor 2011 is further configured to determine the number of random numbers generated and, if the number of random numbers generated meets the requirements of the electronic device 100, send the generated random numbers to the electronic device 100 via the communication interface 2013.

[0069] Memory 2012 stores various programs and data required for the operation of server 201. Processor 2011 executes the various operations of the method flow according to the embodiment of the present disclosure by executing the programs in memory 2012. It should be noted that there may be one or more memories 2012. Processor 2011 may also execute the various operations of the method flow according to the embodiment of the present disclosure by executing the programs stored in the one or more memories.

[0070] It should be noted that the random number acquisition request (first request) sent by the electronic device 100 to the server cluster 200 is received by any server 201 in the server cluster 200. For ease of description, the first server 201 to receive the random number acquisition request is referred to as the first server. Referring to Figure 2(b), Figure 2(b) shows a schematic diagram of the structure of the first server provided in an embodiment of the present application. As shown in Figure 2(b), the communication interface 2013 of the first server is configured with an interaction module, and the processor 2011 is configured with a collection module.

[0071] After receiving the first request, the interaction module of the first server generates a random number locally, which is collected by the collection module. The interaction module then distributes a second request to servers in the server cluster other than the first server. The second request is used to obtain M random numbers, where M ≥ 1.

[0072] It should be noted that, in one case, the second request may be a request directly distributed by the first server, in which case M is equal to N.

[0073] Exemplarily, the number of random numbers generated by the first server is determined by the acquisition module, and when the number of random numbers generated by the first server reaches N, the interaction module of the first server sends the N random numbers generated by the first server to the client of the electronic device 100. At this time, the rate at which the first server generates N random numbers is higher than that of the servers other than the first server in the server cluster. In some embodiments, when the number of random numbers generated by the first server does not reach N, and the number of random numbers generated by the second server reaches N, the first server sends the N random numbers obtained from the second server to the electronic device 100, wherein the second server is any server 201 in the server cluster other than the first server, and the speed at which the second server generates N random numbers is faster than the speed at which the first server generates N random numbers. In this embodiment, the first server stores the unsent random numbers so as to respond to the random number acquisition request sent by the electronic device 100 next time, thereby further improving the efficiency of random number acquisition.

[0074] For example, in some embodiments, the first server stores more than N random numbers. Based on the first request, the first server sends the N random numbers stored by the first server. It is understood that the random numbers stored by the first server are random numbers prepared based on the last random number acquisition request sent by the client. The last prepared random numbers were not sent to the client and are therefore stored in the memory 2012 of the first server.

[0075] Optionally, a data buffering function can be added to the acquisition module to cache the random numbers collected by the acquisition module. In this way, when the acquisition is terminated, the random number data stored in the acquisition module can also be used to respond to the random number acquisition request next time.

[0076] Specifically, the data buffering function of the acquisition module can be implemented in the following ways:

[0077] During the initialization phase when the acquisition module receives a random number acquisition request, a buffer is created and initialized to ensure it can be used to store the collected random number data. During the random number data acquisition process, the collected random number data is temporarily stored in the buffer. This allows each collected random number data to be added to the end of the buffer. When the acquisition module stops acquiring data, the buffer is not cleared. This allows the random number data already stored in the buffer to be retained even if it has not been sent to the client, and can be used the next time a random number acquisition request is received. When the next random number acquisition request is received, the data already stored in the buffer can be used directly without having to restart the acquisition process. Data can be read from the buffer on demand until the buffer is empty or the amount of data requested for the random number acquisition is reached.

[0078] In another scenario, the first server stores K random numbers. In this case, the second request distributed by the first server to other servers in the server cluster is generated based on the first request, where M = NK. In this scenario, the first server obtains M random numbers from the second server and sends the M random numbers obtained from the second server along with the K random numbers stored by the first server. The second server is the server that generates the M random numbers the fastest among the other servers.

[0079] In some embodiments, after the first server reaches N random numbers generated by itself or receives N random numbers sent by the second server, it generates a stop signal and sends it to servers in the server cluster other than the first server via the interaction module. The stop signal is used to instruct the server to stop generating random numbers. It is understood that the first server has already stopped generating random numbers when sending the stop signal.

[0080] The server 201 other than the first server in the server cluster receives the suspension signal from the first server and stops generating random numbers.

[0081] Optionally, the random number generated by the server 201 in the server cluster that has not sent the random number is stored in its own local memory 2012 to facilitate responding to the random number acquisition request sent by the electronic device 100 next time, further improving the efficiency of random number acquisition.

[0082] In some implementations, the second server has the same structure as the first server, that is, the communication interface 2013 of the second server is also configured with an interaction module, and the processor 2011 is also configured with a collection module.

[0083] The interaction module in the second server is configured to receive a second request sent by the first server, where the second request is used to request to obtain M random numbers. The second server starts generating random numbers based on the second request.

[0084] The interaction module is further configured to send M random numbers to the first server when the number of random numbers obtained by the second server reaches M, so that the first server obtains N random numbers.

[0085] In some implementations, the M random numbers sent by the second server to the first server are the M random numbers stored in the second server.

[0086] In some embodiments, the interaction module in the second server is further configured to receive a stop signal, and based on the stop signal, the second server stops generating random numbers.

[0087] It is worth mentioning that the random numbers generated by the first server and the second server in the server cluster are true random numbers, which are prepared by the / dev / random true random number generator in the server 201.

[0088] In this way, the application scenario of the data processing method provided in the embodiment of the present application makes use of the server cluster in the distributed system, and two modules, an interaction module and an acquisition module, are deployed on each server node. The interaction module is responsible for accepting the client's random number acquisition request and distributing the request to other nodes in the server cluster. The acquisition module collects the random numbers of the local / dev / random of each server. After the random numbers collected by the random number acquisition module meet the client's requirements, the collected random numbers are sent to the interaction module. The interaction module returns the collected random numbers to the client and sends a collection termination signal to other modules at the same time. After receiving the termination signal, the other acquisition modules stop the random number collection of the local machine. In summary, using the / dev / random of all servers in the server cluster to generate true random numbers can respond to random number acquisition requests more quickly, thereby improving the acquisition efficiency while ensuring the quality of the random numbers.

[0089] The above is an introduction to the application scenarios of the data processing method involved in this solution. Next, based on the above content, the process of the data processing method provided in the embodiment of the present application is introduced.

[0090] Figure 3 FIG. 1 shows a flow chart of a data processing method provided by an embodiment of the present application. Figure 3 As shown, the data processing method in this embodiment is applied to the first server shown in FIG2( b ), where the first server is any one of the multiple servers in the server cluster. The data processing method may include the following steps:

[0091] S301. A first server receives a first request, where the first request is used to request N random numbers, where N≥1.

[0092] In this step, the first server is the first server in the server cluster to receive the first request, and the first server is any server, and the first request is Figure 1The random number acquisition request sent by the client in the electronic device 100. The random number acquisition request carries the number of random numbers to be collected. For example, the collection number can be set to 1 million random numbers to be collected for the collection operation, and when this number is reached, the collection action will be terminated. Alternatively, the collection number can be set to the size of the memory occupied by the number of random numbers to be collected by the collection operation, such as 1MB-1GB. Exemplarily, in this embodiment, it can be set to collect random numbers of 1GB in size. It should be noted that if the size of the number of random numbers to be collected is too large, such as 10GB, and at the same time, the number of servers in the distributed cluster nodes is small or the external load of the server is large, the collection of 10GB of random numbers can be divided into multiple random number acquisition requests for collection. For example, for the 10G random numbers required by the client, it can be divided into 10 collections, and the size of the random numbers collected each time is 1GB.

[0093] In a server cluster, when a client sends the first request to the server cluster, a load balancing mechanism is usually involved. Load balancing can ensure that the request is distributed to a server in the server cluster. Common load balancing methods include polling, minimum number of connections, IP hashing, etc. Therefore, the first request sent by the client is usually decided by the load balancer to which server. In the absence of special configuration, each server generally has the same chance of receiving the first request. However, which server is more likely to receive the first request depends on the load balancing algorithm adopted and the load situation of the server cluster. It should be noted that the above-mentioned load balancer is configured on an independent load balancing server. Optionally, the load balancing server is located between the client and the server cluster (not shown in the figure). Its main task is to receive requests from the client and distribute the first request to a server in the server cluster according to the preset load balancing algorithm.

[0094] For example, if a round-robin algorithm is used, the first request may be sent to the first server in the polling list; if a minimum number of connections algorithm is used, the first request may be sent to the server with the fewest connections. If an IP hashing algorithm is used, the request is hashed based on the client's IP address to determine which server to send it to. Therefore, which server receives the first request depends on the load balancing algorithm selected and the load of the server cluster, which is not a limitation in this embodiment.

[0095] S302: The first server distributes a second request to servers other than the first server in the server cluster, where the second request is for obtaining M random numbers, where M is a positive integer less than or equal to N. In other words, the second request can be a directly distributed first request (M equals N) or a second request generated based on the first request (M less than N).

[0096] In this way, the second request can be distributed to each server in the server cluster, so that the remaining servers can also generate random numbers, reducing the possibility of blocking during the random number generation process and improving the quality and reliability of the generated random numbers.

[0097] It should be noted that, after receiving the first request, the first server can start collecting random numbers in the first server through the collection module in FIG2(b), and the random numbers can be generated or stored by the first server. Similarly, after receiving the second request, the second server can start collecting random numbers generated in the second server through the collection module in FIG2(b). It should be understood that in some embodiments, random numbers are also stored in the second server. In one possible implementation, the random numbers collected and generated by the first server and the second server in the server cluster are true random numbers, which are prepared by the / dev / random true random number generator in the server.

[0098] Exemplarily, generating a true random number based on / dev / random provided by the server Linux kernel may include the following steps:

[0099] S101. Collect environmental noise from an entropy source into an entropy pool.

[0100] In this step, the server's / dev / random device collects environmental noise into an entropy pool through entropy sources, thereby collecting truly random events. This environmental noise may include user keyboard input, mouse movement, disk I / O, etc. Each entropy source contributes some randomness to the entropy pool.

[0101] It's important to note that an entropy source refers to a physical or logical source of random events. It's the foundation for generating truly random numbers, as random numbers rely on random events in the environment. Key characteristics of an entropy source are its unpredictability and independence. In other words, the events in the entropy source should be unpredictable, their outcomes impossible to predict using any algorithm or model, and they should be independent of other events to ensure high-quality random numbers.

[0102] For example, in the server, the entropy source may include the following:

[0103] Hardware entropy sources: These entropy sources utilize randomness in physical processes to generate random numbers. For example, thermal noise, thermal fluctuations in electronic devices, and radioactive decay can all serve as hardware entropy sources. In this embodiment, the server Linux kernel is equipped with a dedicated hardware module, such as an entropy source manager, to collect these hardware entropy sources and store them in an entropy pool.

[0104] Software entropy sources: These entropy sources generate random numbers by collecting non-deterministic events from the operating system and applications. For example, mouse movements, keystroke intervals, disk I / O operations, etc. can all serve as software entropy sources.

[0105] The / dev / random device in the Linux operating system generates random numbers through these hardware entropy sources and / or software entropy sources, combined with their statistical characteristics.

[0106] S102: Calculate the entropy value of the entropy pool.

[0107] Exemplarily, the calculation of the entropy value in the entropy pool can be achieved through a compression algorithm or an information entropy formula.

[0108] Exemplarily, the compression algorithm may be Lempel-Ziv-Welch (LZW), Deflate, etc. When the compression algorithm is used to calculate the entropy value in the entropy pool, the data in the entropy pool may be compressed first, and then the entropy value may be obtained by calculating the difference in bit length of the data before and after compression. For example, assuming that the data contained in the entropy pool is "110101010101010101", after compression, it becomes "1(10)5(01)5(01)", then the entropy value may be calculated by comparing the lengths of the data before and after compression.

[0109] Calculating the entropy value in the entropy pool using the information entropy formula follows the definition of information entropy. The formula for calculating information entropy is: H(X) = -Σp(x)log2p(x), where p(x) represents the probability of a data point occurring. By counting the frequency of occurrence of different data points in the entropy pool, the probability of each data point can be calculated. This probability is then substituted into the information entropy formula to obtain the entropy value in the entropy pool.

[0110] In other words, the information entropy formula uses statistical methods to estimate the entropy value in the entropy pool, which can be done through the following steps:

[0111] Collect data in the entropy pool: First, you need to collect data samples in the entropy pool, which can be any type of data, such as random numbers, sensor data, etc.

[0112] Statistical frequency: Perform frequency statistics on the data in the entropy pool and calculate the probability of each data occurrence. The probability of the data can be estimated by calculating the frequency or proportion of each data occurrence.

[0113] Calculate information entropy: Based on the information entropy formula H(X) = -Σp(x)log2p(x), the entropy value is calculated using the probability of the data. Substitute the probability of each data point into the formula and sum to get the entropy value.

[0114] For example, assuming the data in the entropy pool is [1, 2, 1, 3, 2, 1, 3, 1, 2, 2], we can first count the frequency of each data: 1 appears 4 / 10, 2 appears 4 / 10, and 3 appears 2 / 10. Then calculate the information entropy: H(X) = -[-(4 / 10) × log2(4 / 10) - (4 / 10) × log2(4 / 10) - (2 / 10) × log2(2 / 10)] = 1.52193.

[0115] S103: Generate a true random number in the entropy pool based on the entropy value being greater than a first threshold.

[0116] Typically, the unit of measurement for entropy is bits, which represents the uncertainty of information. For example, the first threshold value can be set to 20 bits. When dev / random generates random numbers, it first checks the level of randomness in the entropy pool. If the randomness in the entropy pool is high enough (the entropy value is greater than the first threshold value), dev / random will immediately generate a corresponding number of random numbers. These random numbers are generated based on the entropy of truly random events in the entropy pool. It should be noted that in this embodiment, by utilizing the entropy source manager that comes with the Linux kernel to maintain the entropy pool, it can be ensured that the entropy pool has sufficient randomness for dev / random to generate random numbers.

[0117] For example, after dev / random generates a random number, the server can directly collect the command of / dev / random locally as follows:

[0118] dd if= / dev / random of=random_data.bin bs=1M count=1024

[0119] It should be noted that in the above command, dd: is a command for copying files. if = / dev / random: specifies the input file as

[0120] The / dev / random device provides the system with true random data, but if the system entropy pool is insufficient, it may block and wait.

[0121] of=random_data.bin: Specifies the output file as random_data.bin, which will be used to write random data read from / dev / random. bs=1M: Sets the block size to 1MB, indicating that each read or write is 1MB in size. count=1024: Specifies that a total of 1024 blocks will be read or written, meaning a total of 1024 × 1MB = 1GB of data will be read or written.

[0122] S303: When the number of random numbers obtained by the first server reaches N, the first server sends N random numbers.

[0123] In this step, in one possible implementation, the first server generates N random numbers, and the first server sends the N random numbers generated by the first server. In this implementation, the first server generates random numbers faster than any other server in the server cluster except the first server.

[0124] In another possible implementation, if the number of random numbers generated by the first server does not reach N, but the number of random numbers generated by the second server reaches N, the second server sends N random numbers to the first server, the first server obtains the N random numbers generated by the second server from the second server, and the first server sends the obtained N random numbers to the client. The second server is any server in the server cluster other than the first server, and the second server generates N random numbers faster than the first server. In other words, the second server is the first server to generate N random numbers.

[0125] In one possible implementation, the first server stores N random numbers, and the first server sends the N random numbers stored by the first server. It is understandable that the N random numbers stored by the first server are random numbers prepared based on the last random number acquisition request sent by the client. The last prepared random numbers are stored in the first server because they were not sent to the client.

[0126] In one possible implementation, the first server stores K random numbers, and M=NK in the second request. The first server generates M random numbers, and sends the M random numbers it generated and the K random numbers it stored. The first server is the fastest server among the other servers in generating the M random numbers.

[0127] In one possible implementation, the first server stores K random numbers, and M=NK in the second request. The first server obtains M random numbers from the second server, and the first server sends the M random numbers obtained from the second server and the K random numbers stored by the first server. The second server generates the M random numbers faster than the first server. Exemplarily, the second server is the fastest server at generating the M random numbers among the other servers.

[0128] In some embodiments, as Figure 3As shown, a data processing method provided in an embodiment of the present application may further include: S304 or S305. Exemplarily, S304 or S305 may be executed after S303. For example, after the first server sends N random numbers in S303, indicating that the client has obtained the required random numbers, S304 or S305 is then executed.

[0129] S304. After the total number of random numbers reaches N, for example, the first server may generate N random numbers, or receive N random numbers sent by the second server, or the total number of random numbers received plus the number of random numbers stored by the first server reaches N, the first server generates a termination signal and sends it to the servers in the server cluster except the first server. The termination signal is used to instruct the server to terminate the generation of random numbers.

[0130] S305 : The servers in the server cluster other than the first server receive a stop signal from the first server and stop generating random numbers.

[0131] In this step, because the first server to reach the number of random numbers requested by the client has already sent the generated random numbers to the first server, it is necessary to stop generating random numbers for the other servers in the server cluster. Specifically, when the number of random numbers generated by the first server reaches N, the interaction module of the first server will simultaneously send a stop signal to the interaction modules of the other servers in the server cluster. The stop signal is used to instruct the server to stop generating random numbers. In response to the stop signal, the multiple servers in the server cluster stop generating random numbers.

[0132] It is worth mentioning that in order to improve the corresponding efficiency of random number acquisition requests, after the server stops generating random numbers, the random numbers generated by other servers are stored in the memory 2012 deployed by itself. Since they are not sent to the client, the random number data stored in the memory 2012 can also be used to respond to the random number acquisition request next time, so as to further improve the random number response efficiency.

[0133] In some embodiments, as Figure 4 As shown, another data processing method provided in an embodiment of the present application is applied to a second server, the second server is set in a server cluster, and the server cluster also includes a first server, the first server is used to send N random numbers to the client, and the method includes:

[0134] S401. Receive a second request sent by the first server, where the second request is used to request M random numbers, where M is less than or equal to N.

[0135] S402: When the number of random numbers obtained by the second server reaches M, the M random numbers are sent to the first server, so that the first server obtains N random numbers.

[0136] In this step, the second server generates M random numbers faster than the first server generates M random numbers.

[0137] In one embodiment, the second server stores M random numbers, and the second server sends the stored M random numbers to the first server.

[0138] Optionally, after S402, the data processing method may further include:

[0139] S403: The second server receives the termination signal and stops generating random numbers.

[0140] It can be understood that the termination signal comes from the first server.

[0141] S404: After stopping generating random numbers, the second server stores the generated random numbers.

[0142] It should be noted that the random numbers that have been generated and stored in the second server are random numbers that exceed M. The random numbers that exceed M are stored in the second server because they are not sent to the first server, so as to respond to the next random number acquisition request to improve the response efficiency.

[0143] The data processing method provided in this embodiment is primarily used for quickly collecting random numbers. Using this method, clients can leverage a distributed system to quickly collect random numbers. It has been verified that generating 10 x 1GB of random numbers on a single server takes 15 hours. However, using this method, using 20 servers as random number generators, the generation time is reduced to less than an hour.

[0144] It is understandable that the size of the serial number of each step in the above-mentioned embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. In addition, in some possible implementations, the steps in the above-mentioned embodiments can be selectively executed according to actual conditions, and can be partially executed or fully executed, which is not limited here. In addition, all or part of any features of any of the above-mentioned embodiments can be freely and arbitrarily combined without contradiction; the combined technical solutions are also within the scope of this application.

[0145] In this way, the data processing method provided in the embodiment of the present application uses a server cluster in a distributed system and uses / dev / random on a computing node server in each server cluster to generate a true random number. It can fully utilize the randomness of / dev / random and use a distributed environment to reduce the probability of blocking when preparing random numbers. Moreover, each server can receive a random number acquisition request and execute the same acquisition command. The final acquisition speed depends on the server node with the fastest response (the fastest random number generation rate). Using the horse racing mechanism, it is possible to improve the acquisition speed of random numbers while ensuring the quality of random numbers. In other words, the present application comprehensively considers the randomness and availability of random numbers, improves response efficiency, and reduces response time.

[0146] The present application also provides a computer-readable storage medium. The computer-readable storage medium is used to store computer program instructions. When the computer program instructions are executed on a server, the server executes the data processing method involved in the above embodiment. The computer-readable storage medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a magnetic tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive).

[0147] The present application also provides a computer program product comprising instructions, which, when executed on a server, causes the server to execute the data processing method described in the above embodiment.

[0148] Finally, it should be noted that the above embodiments are merely illustrative of the technical solutions of the present application. Those skilled in the art should understand that, although the present application has been described in detail with reference to the aforementioned embodiments, the technical solutions described in the aforementioned embodiments may be modified or some of the technical features thereof may be replaced with equivalents. However, such modifications or replacements do not deviate from the spirit and scope of the technical solutions in the various embodiments of the present application.

Claims

1. A data processing method, characterized in that: Applied to a first server, where the first server is any one of a plurality of servers in a server cluster, the method includes: The first server receives a first request, where the first request is for obtaining N random numbers, where N ≥ 1; The first server distributes a second request to a second server other than the first server in the server cluster, where the second request is used to request M random numbers, where M is a positive integer less than or equal to N; When the number of random numbers obtained by the first server reaches N, the first server sends the N random numbers; The first server stores K random numbers, K is greater than or equal to 0, M=NK in the second request, and when the number of random numbers obtained by the first server reaches N, the first server sending the N random numbers includes: The first server obtains M random numbers from the second server, and the first server sends the M random numbers obtained from the second server and the K random numbers stored by the first server, wherein the second server generates the M random numbers faster than the first server generates the M random numbers; or The first server generates M random numbers, and sends the M random numbers generated by itself and the K random numbers stored by the first server, wherein the speed at which the first server generates the M random numbers is faster than the speed at which the second server generates the M random numbers.

2. The method according to claim 1, characterized in that M is equal to N, and when the number of random numbers obtained by the first server reaches N, the first server sends the N random numbers, specifically including: The first server generates N random numbers, and the first server sends the N random numbers generated by the first server. The first server generates the N random numbers faster than other servers in the server cluster except the first server.

3. The method according to claim 1, characterized in that M is equal to N, and when the number of random numbers obtained by the first server reaches N, the first server sends the N random numbers, specifically including: The first server obtains N random numbers from the second server, and the first server sends the N random numbers obtained by the first server, wherein the second server generates the N random numbers faster than the first server.

4. The method according to claim 1, wherein The first server stores N random numbers, and when the number of random numbers obtained by the first server reaches N, the first server sends the N random numbers, specifically including: The first server sends the N random numbers stored by the first server.

5. The method according to any one of claims 1 to 4, characterized in that After the first server sends the N random numbers, the method further includes: The first server stores the unsent random number.

6. The method according to claim 5, characterized in that After the number of random numbers obtained by the first server reaches N, the method further includes: A stop signal is generated and sent to servers in the server cluster except the first server, so that the other servers stop generating random numbers.

7. A data processing method, characterized in that: Applied to a second server, the second server being arranged in a server cluster, the server cluster further comprising a first server, the first server being configured to send N random numbers to a client, the method comprising: receiving a second request sent by the first server, where the second request is used to request M random numbers; When the number of random numbers obtained by the second server reaches M, the M random numbers are sent to the first server, so that the first server obtains N random numbers.

8. The method according to claim 7, characterized in that The second server receives the termination signal and stops generating random numbers.

9. A server cluster, characterized in that: The method comprises a first server and a second server, wherein the first server is used to execute the method according to any one of claims 1 to 6, and the second server is used to execute the method according to any one of claims 7 to 8.

Citation Information

Patent Citations

  • Random number generation method and device based on blockchain, and storage medium

    CN111158637A

  • System starting method and system of random number generator based on hardware

    CN114281420A