Message sampling method, device, equipment and medium based on bitmap calculation
Through the bitmap calculation method, the problems of large space occupied by port numbers and low query efficiency in the prior art are solved, and more efficient memory usage and query speed are achieved.
Patent Information
- Application Number
- CN202110968105.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-23
- Publication Date
- 2025-03-04
- Estimated Expiration
- 2041-08-23
AI Technical Summary
In the prior art, the port number storing messages takes up a large space and the port number identification query efficiency is low.
The message sampling method based on bitmap calculation is adopted, and by obtaining the binary number corresponding to the port number of the message to be queried, bit operations are performed to locate the corresponding array element, and query the port number to identify whether it has been sampled.
Reduces memory occupied by storing port numbers and improves the efficiency of queries of port numbers.
Smart Images

Figure CN113761300B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of network data processing, and in particular to a message sampling method, device, computer equipment and computer-readable storage medium based on bitmap calculation. Background Art
[0002] In recent years, with the rapid development of information technology and the rapid growth of the scale of application systems, the resulting data has also shown a blowout growth. Seeking effective big data processing technology has become a hot topic of research. Many companies are also paying attention to related technologies to meet their own business needs. In the process of obtaining the flow of messages, it is necessary to filter the ports of the messages, retain the messages with the flow of the designated port (there may be multiple designated ports), and discard the messages with the flow of non-designated ports. There are two conventional port filtering schemes. The first is to query and filter by traversing the array; the second is to query and filter by hash table. The first scheme requires traversing the array, which occupies a large amount of memory and has low query efficiency. The port query complexity of the second scheme is constant level, and the memory usage is high.
[0003] In the existing port filtering technology, there are problems that the port number for storing messages occupies a large space and the port number identification query efficiency is low, and no effective solution has been proposed yet. Summary of the invention
[0004] Based on this, it is necessary to provide a message sampling method, device, computer equipment and computer-readable storage medium based on bitmap calculation to address the above technical problems, so as to solve the problems existing in the related technology that the storage space of port numbers is large and the efficiency of port number identification search is low.
[0005] In a first aspect, the present application implements a message sampling method based on bitmap calculation, comprising the following steps:
[0006] Obtain a first number corresponding to the port number of the message to be queried, where the first number is a binary number;
[0007] Shift the first number right by three bits to obtain a second number;
[0008] Perform a bitwise AND operation on the first number and 111 to obtain a third number;
[0009] Obtain the value of the array element corresponding to the position of the third number in the 8-bit array element corresponding to the second number plus 1 in the first array, and determine whether the message corresponding to the port number of the message to be queried is sampled according to the value of the array element; the first array is pre-created based on the port number identifiers of all messages, and the value of the array element of the first array represents the port number identifier of the message to be queried.
[0010] In some embodiments, before obtaining the first number corresponding to the port number of the message to be queried, the method further includes the following steps:
[0011] Obtain a fourth number corresponding to the maximum port number of all messages, apply for a continuous second array to store the port number identifiers of all messages, the size of the second array is the fourth number, and the fourth number is a decimal number;
[0012] The port numbers of all messages are traversed, and when it is determined that the message corresponding to the current port number needs to be sampled, the value of the array element at the position corresponding to the current port number in the second array is set to 1.
[0013] In some embodiments, before obtaining the first number corresponding to the port number of the message to be queried, the method further includes the following steps:
[0014] Obtain the fifth digit corresponding to the maximum port number of all messages, where the fifth digit is a binary number;
[0015] Shift the fifth digit right by three bits to obtain a sixth digit;
[0016] Add 1 to the sixth number and then multiply by 8 to obtain a seventh number, and apply for a continuous third array to store the port number identifiers of all messages, and the size of the third array is the seventh number;
[0017] Traverse the port numbers of all messages, perform a bitwise operation on the eighth digit corresponding to the current port number, shift right by three digits, obtain a ninth digit, perform a bitwise AND operation on the eighth digit and 111, obtain a tenth digit, and the eighth digit is a binary number;
[0018] When it is determined that the message corresponding to the current port number needs to be sampled, the value of the array element corresponding to the position of the tenth digit in the 8-bit array element corresponding to the ninth digit plus 1 in the third array is set to 1.
[0019] In some embodiments, when traversing the port numbers of all messages and determining that the message corresponding to the current port number needs to be sampled, after setting the value of the array element at the position corresponding to the current port number in the second array to 1, the method further includes:
[0020] When it is determined that the message corresponding to the current port number needs to be filtered, the value of the array element at the position corresponding to the current port number in the second array is set to 0.
[0021] In some embodiments, when it is determined that the message corresponding to the current port number needs to be sampled, after setting the value of the array element corresponding to the position of the tenth digit in the 8-bit array element corresponding to the ninth digit plus 1 in the third array to 1, the method further includes:
[0022] When it is determined that the message corresponding to the current port number needs to be filtered, the value of the array element corresponding to the position of the tenth digit in the 8-bit array element corresponding to the ninth digit plus 1 in the third array is set to 0.
[0023] In some embodiments, in the obtaining of the first array, in the 8-bit array element corresponding to the second number plus 1, the value of the array element corresponding to the position of the third number, and after determining whether the message corresponding to the port number of the message to be queried is sampled according to the value of the array element, the method further comprises the following steps:
[0024] When the value of the port number identifier of the message to be queried is 0, the message to be queried is filtered.
[0025] In some embodiments, after applying for a continuous third array to store the port number identifiers of all messages and before traversing the port numbers of all messages, the method further includes:
[0026] Clear the content of the third array applied for.
[0027] In the second aspect, a message sampling device based on bitmap calculation is provided in this embodiment, and the device further includes: an acquisition module, a first conversion module, a second conversion module, a search module and a result module:
[0028] The acquisition module is used to acquire a first number corresponding to the port number of the message to be queried, where the first number is a binary number;
[0029] The first conversion module is used to perform a bitwise operation of right-shifting the first number by three digits to obtain a second number;
[0030] The second conversion module is used to perform a bitwise AND operation on the first number and 111 to obtain a third number;
[0031] The search module is used to obtain the value of the array element corresponding to the position of the third number in the 8-bit array element corresponding to the second number plus 1 in the first array, and determine whether the message corresponding to the port number of the message to be queried is sampled according to the value of the array element; the first array is pre-created based on the port number identifiers of all messages, and the value of the array element of the first array represents the port number identifier of the message to be queried.
[0032] In a third aspect, a computer device is provided in this embodiment, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method described in the first aspect when executing the computer program.
[0033] In a fourth aspect, in this embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method described in the first aspect are implemented.
[0034] The above-mentioned message sampling method, device, computer equipment and computer-readable storage medium based on bitmap calculation, wherein the message sampling method based on bitmap calculation obtains the first digit corresponding to the port number of the message to be queried, and the first digit is a binary number; the first digit is shifted right by three bits to obtain the second digit; the first digit is bitwise ANDed with 111 to obtain the third digit; the value of the array element corresponding to the position of the third digit in the 8-bit array element corresponding to the second digit plus 1 in the first array is obtained, and whether the message corresponding to the port number is sampled is determined according to the value of the array element; the first array is pre-created, and the value of the array element of the first array represents the port number identifier of the message. In the process of port number identifier query, by one-to-one correspondence between the port number and the array element address, the memory occupied by the port number is reduced, and the port number identifier is queried by a bitmap calculation method, so as to optimize the port number identifier query method. Finally, it is determined whether the current message to be queried is sampled according to the query result. Port filtering can be performed by using the message sampling method based on bitmap calculation provided by the present application, which can reduce the memory occupied by the port number and improve the query efficiency of the port number identifier. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0036] Figure 1 This is an application scenario diagram of the message sampling method based on bitmap calculation provided in an embodiment of the present application;
[0037] Figure 2 The process of the message sampling method based on bitmap calculation provided in the embodiment of the present application is as follows Figure 1 ;
[0038] Figure 3 The process of the message sampling method based on bitmap calculation provided in the embodiment of the present application is as follows Figure 2 ;
[0039] Figure 4The process of the message sampling method based on bitmap calculation provided in the embodiment of the present application is as follows Figure 3 ;
[0040] Figure 5 It is a structural schematic diagram of a message sampling device based on bitmap calculation provided according to an embodiment of the present application;
[0041] Figure 6 It is a schematic diagram of the structure of a computer device provided according to an embodiment of the present application. DETAILED DESCRIPTION
[0042] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments provided in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.
[0043] Obviously, the drawings described below are only some examples or embodiments of the present application. For ordinary technicians in this field, the present application can also be applied to other similar scenarios based on these drawings without creative work. In addition, it can also be understood that although the efforts made in this development process may be complicated and lengthy, for ordinary technicians in this field related to the content disclosed in this application, some changes in design, manufacturing or production based on the technical content disclosed in this application are just conventional technical means, and should not be understood as insufficient content disclosed in this application.
[0044] Reference to "embodiments" in this application means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those of ordinary skill in the art that the embodiments described in this application may be combined with other embodiments without conflict.
[0045] Unless otherwise defined, the technical terms or scientific terms involved in this application should be understood by people with ordinary skills in the technical field to which this application belongs. The words "one", "a", "a", "the" and the like involved in this application do not indicate a quantitative limitation, and may represent the singular or plural. The terms "include", "comprise", "have" and any of their variations involved in this application are intended to cover non-exclusive inclusions; for example, a process, method, system, product or device that includes a series of steps or modules (units) is not limited to the listed steps or units, but may also include steps or units that are not listed, or may also include other steps or units inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there may be three relationships, for example, "A and / or B" can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects before and after are in an "or" relationship. The terms "first", "second", "third", etc. involved in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.
[0046] Figure 1 This is an application scenario diagram of a message sampling method based on bitmap calculation provided by an embodiment of the present application. Figure 1 As shown, data can be transmitted between the server 101 and the mobile terminal 102 through the network. Among them, the mobile terminal 102 is used to obtain the message to be queried and transmit the message to be queried to the server 101. After the server 101 receives the message information to be queried, the first digit corresponding to the port number of the message is extracted, and the first digit is shifted right by three bits to obtain the second digit. After obtaining the second digit, the server 101 performs a bitwise AND operation on the first digit and 111 to obtain a third digit. After obtaining the third digit, the server 101 obtains the value of the array element corresponding to the position of the third digit in the 8-bit array element corresponding to the second digit plus 1 in the first array, and determines whether the message corresponding to the port number of the message to be queried is sampled according to the value of the array element. The first array is pre-created based on the port number identifiers of all messages, and the value of the array element of the first array represents the port number identifier of the message to be queried. Among them, the server 101 can be implemented by an independent server or a server cluster composed of multiple servers, and the mobile terminal 102 can be any display screen with input function.
[0047] The embodiment of the present application provides a message sampling method based on bitmap calculation, which can be used for message sampling based on bitmap calculation in the field of network data processing, such as Figure 2 As shown, the method comprises the following steps:
[0048] Step S210, obtaining a first number corresponding to the port number of the message to be queried, where the first number is a binary number.
[0049] The port number of the message to be queried can be obtained by searching the corresponding field in the message information. During data transmission, the obtained port number may be decimal or hexadecimal, depending on the application scenario. The original port number of the message to be queried is converted into the first digit of binary, and the conversion into binary facilitates bit operations on the port number. For example, if the original port number is 17 in decimal, the first digit of the binary number is 10001.
[0050] Step S220, performing a bitwise operation of right-shifting the first number by three bits to obtain a second number.
[0051] The bitwise operation of shifting the first digit right by three bits is actually to divide the port number by 8 and round it up. For example, in the example described in step S210, the first digit converted into binary by the acquired port number becomes 10001, and the second digit obtained by shifting the first digit right by three bits is 10.
[0052] Step S230, performing a bitwise AND operation on the first number and 111 to obtain a third number.
[0053] For example, in the example described in step S220, the first digit of the acquired port number converted into binary becomes 10001, and the first digit is subjected to a bitwise AND operation with 111, and the third digit is 001.
[0054] Step S240, obtain the value of the array element corresponding to the position of the third number in the 8-bit array element corresponding to the second number plus 1 in the first array, and determine whether the message corresponding to the port number of the message to be queried is sampled according to the value of the array element; the first array is pre-created based on the port number identifiers of all messages, and the value of the array element of the first array represents the port number identifier of the message to be queried.
[0055] For example, in the example described in step S230, the second number obtained is 10 and the third number is 001, then the value of the 1st (the third number is 001, the decimal number corresponding to 001 is 1) array element in the 3rd (the second number is 10, the decimal number corresponding to 10 is 2, 2+1=3) 8-bit array element in the first array is obtained. The value of this array element has only three choices, 0, 1 or empty. According to the value of this array element, it is determined whether the message corresponding to the port number of the message to be queried is sampled.
[0056] In the related art, the address and offset of the array element are not used to store and query the port number identification of the message, and there are problems that the port number of the message is stored in a large space and the port number identification query efficiency is low. The present application reduces the memory occupied by the port number by one-to-one correspondence between the port number and the array element address during the port number identification query process through the above steps S210 to S240, and queries the port number identification by a bitmap-based calculation method to optimize the port number identification query method. Finally, it is determined whether the current message to be queried is sampled based on the query result. By using the message sampling method based on bitmap calculation provided by the present application to perform port filtering, the memory occupied by the port number can be reduced and the query efficiency of the port number identification can be improved.
[0057] like Figure 3 As shown, in one embodiment, before the above step S210 obtains the first number corresponding to the port number of the message to be queried, the following steps are also included:
[0058] Step S310, obtaining the fourth number corresponding to the maximum port number of all messages, applying for a continuous second array to store the port number identifiers of all messages, the size of the second array is the fourth number, and the fourth number is a decimal number.
[0059] For example, the fourth digit corresponding to the largest port number in all messages is 65535, so the size of the second array is 65535, and each array element occupies 1 bit of memory. The second array is used to store the port number identifiers of all messages.
[0060] Step S320, traverse the port numbers of all messages, and when it is determined that the message corresponding to the current port number needs to be sampled, set the value of the array element at the position corresponding to the current port number in the second array to 1.
[0061] All port numbers are traversed. For example, if the port number of the current message is 17, when it is determined that the message corresponding to the current port number needs to be sampled, the value of the 17th array element of the second array is set to 1.
[0062] Through the above steps S310 to S320, the one-to-one correspondence between the port number of the message and the array element address is determined. Storing the port identifier of a port only requires 1 bit. Using this method to construct an array for storing port identifiers can effectively reduce the memory occupied by storing port identifiers.
[0063] like Figure 4 As shown, in another embodiment, before the above step S210 obtains the first number corresponding to the port number of the message to be queried, the following steps are also included:
[0064] Step S410, obtaining the fifth digit corresponding to the maximum port number of all messages, where the fifth digit is a binary number.
[0065] For example, the largest port number in all messages is 27, then the corresponding fifth number is 11011.
[0066] Step S420, performing a bitwise operation of right shifting the fifth digit by three bits to obtain a sixth digit.
[0067] For example, in the example of step S410, the fifth number obtained is 11011, and the fifth number is shifted right by three bits, and the sixth number obtained is 11.
[0068] Step S430, add 1 to the sixth number and then multiply by 8 to obtain the seventh number, apply for a continuous third array to store the port number identifiers of all messages, and the size of the third array is the seventh number.
[0069] For example, in the example of step S420, the sixth digit is 11 in binary, and the corresponding decimal digit is 3. The seventh digit obtained by adding 1 to the sixth digit and multiplying it by 8 is 32. Then the size of the third array applied for is 32, and each array element occupies 1 bit of memory. The third array is used to store the port identifiers of all messages.
[0070] Step S440, traverse the port numbers of all messages, shift the eighth digit corresponding to the current port number right by three bits to obtain the ninth digit, perform a bitwise AND operation on the eighth digit and 111 to obtain the tenth digit. The eighth digit is a binary number.
[0071] Traverse all port numbers. For example, the port number of the current message is 17, and the corresponding eighth digit in binary is 10001. Then the ninth digit obtained by shifting the eighth digit right by three bits is 10, and the tenth digit obtained by performing a bitwise AND operation on the eighth digit and 111 is 001.
[0072] Step S450, when it is determined that the message corresponding to the current port number needs to be sampled, the value of the array element corresponding to the position of the tenth digit in the 8-bit array element corresponding to the ninth digit plus 1 in the third array is set to 1.
[0073] For example, in the example of step S440, the current port number is 17. When the message corresponding to the current port number needs to be sampled, the value of the first (the tenth digit is 001, the decimal digit corresponding to 001 is 1) array element in the third array, the third (the ninth digit is 10, the decimal digit corresponding to 10 is 2, 2+1=3) 8-bit array element, is set to 1.
[0074] Through the above steps S410 to S440, the one-to-one correspondence between the port number of the message and the array element address is determined. Storing the port identifier of a port only requires 1 bit. Using this method to construct an array for storing port identifiers can effectively reduce the memory occupied by storing port identifiers, and the array position storing the current port number identifier can be quickly located through bit operations.
[0075] In one embodiment, when it is determined that the message corresponding to the current port number needs to be sampled, after setting the value of the array element at the position corresponding to the current port number in the second array to 1, the following steps are also included:
[0076] When it is determined that the message corresponding to the current port number needs to be filtered, the value of the array element at the position corresponding to the current port number in the second array is set to 0.
[0077] For example, if the port number of the current message is 17, when it is determined that the message corresponding to the current port number needs to be filtered, the value of the 17th array element of the second array is set to 0.
[0078] The above steps clarify the message operation corresponding to the port number identifier of the message, and make the port number of the message correspond to the array element address one by one. Storing the port identifier of a port only requires 1 bit. Using this method to construct an array for storing port identifiers can effectively reduce the memory occupied by storing port identifiers.
[0079] In one of the embodiments, when it is determined that the message corresponding to the current port number needs to be sampled, after setting the value of the array element corresponding to the position of the tenth digit in the 8-bit array element corresponding to the ninth digit plus 1 in the third array to 1, the following steps are also included:
[0080] When it is determined that the message corresponding to the current port number needs to be filtered, the value of the array element corresponding to the position of the tenth digit in the 8-bit array element corresponding to the ninth digit plus 1 in the third array is set to 0.
[0081] For example, if the current port number is 17 and the message corresponding to the current port number needs to be filtered, the value of the first (the tenth digit is 001, the decimal digit corresponding to 001 is 1) array element in the third array, the third (the ninth digit is 10, the decimal digit corresponding to 10 is 2, 2+1=3) 8-bit array element, is set to 0.
[0082] The above steps clarify the message operation corresponding to the port number identifier of the message, and make the port number of the message correspond to the array element address one by one. It only takes 1 bit to store the port identifier of a port. Using this method to construct an array for storing port identifiers can effectively reduce the memory occupied by storing port identifiers. In addition, the array position storing the current port number identifier can be quickly located by bit operation.
[0083] In one of the embodiments, after obtaining the value of the array element corresponding to the position of the third digit in the 8-bit array element corresponding to the second digit plus 1 in the first array, and determining whether the message corresponding to the port number of the message to be queried is sampled according to the value of the array element, the following steps are also included:
[0084] When the value of the port number identifier of the message to be queried is 0, the message to be queried is filtered.
[0085] Since the array elements may be 0, 1 or empty, this embodiment clarifies that the message to be queried is filtered when the value of the port number identifier of the message to be queried is 0. Then the message to be queried may be sampled when the value of the port number identifier of the message to be queried is 1, or may be sampled when the value of the port number identifier of the message to be queried is empty.
[0086] The above steps clarify the processing operations of the port number identifier on the message under the corresponding value, and provide a complete message processing solution.
[0087] In one embodiment, after applying for a continuous third array to store the port number identifiers of all messages and before traversing the port numbers of all messages, the following steps are also included:
[0088] Clear the contents of the third array obtained.
[0089] Clearing the third array after applying for it can save the time of clearing array elements one by one after locating the array position, thereby improving the efficiency of subsequently constructing the third array.
[0090] Figure 5 is a schematic diagram of a message sampling device based on bitmap calculation according to an embodiment of the present invention, such as Figure 5As shown, a message sampling device 50 based on bitmap calculation is provided, the device includes an acquisition module 51, a first conversion module 52, a second conversion module 53 and a search module 54, wherein:
[0091] An acquisition module 51 is used to acquire a first number corresponding to the port number of the message to be queried, where the first number is a binary number;
[0092] A first conversion module 52, configured to perform a bitwise operation of right-shifting the first number by three digits to obtain a second number;
[0093] A second conversion module 53 is used to perform a bitwise AND operation on the first number and 111 to obtain a third number;
[0094] The search module 54 is used to obtain the value of the array element corresponding to the position of the third number in the 8-bit array element corresponding to the second number plus 1 in the first array, and determine whether the message corresponding to the port number of the message to be queried is sampled according to the value of the array element; the first array is pre-created based on the port number identifiers of all messages, and the value of the array element of the first array represents the port number identifier of the message to be queried.
[0095] The above-mentioned message sampling device 50 based on bitmap calculation reduces the memory occupied by storing the port number during the port number identification query process by making a one-to-one correspondence between the port number and the array element address, and optimizes the port number identification query method by querying the port number identification based on the bitmap calculation method. Finally, it is determined whether the current message to be queried is sampled based on the query result. By using the message sampling method based on bitmap calculation provided by the present application for port filtering, the memory occupied by storing the port number can be reduced and the query efficiency of the port number identification can be improved.
[0096] In one embodiment, the message sampling device 50 based on bitmap calculation also includes a first creation module, which is used to obtain a fourth number corresponding to the maximum port number of all messages before obtaining the first number corresponding to the port number of the message to be queried, and apply for a continuous second array to store the port number identifiers of all messages, the size of the second array is the fourth number, and the fourth number is a decimal number; traverse the port numbers of all messages, and when it is determined that the message corresponding to the current port number needs to be sampled, set the value of the array element at the position corresponding to the current port number in the second array to 1.
[0097] In one embodiment, the message sampling device 50 based on bitmap calculation also includes a second creation module, which is used to obtain the fifth digit corresponding to the maximum port number of all messages before obtaining the first digit corresponding to the port number of the message to be queried, and the fifth digit is a binary number; the fifth digit is shifted right by three bits to obtain a sixth digit; the sixth digit is added by 1 and then multiplied by 8 to obtain a seventh digit, and a continuous third array is applied to store the port number identifiers of all messages, and the size of the third array is the seventh digit; the port numbers of all messages are traversed, and the eighth digit corresponding to the current port number is shifted right by three bits to obtain a ninth digit, and the eighth digit is bitwise ANDed with 111 to obtain a tenth digit, and the eighth digit is a binary number; when it is determined that the message corresponding to the current port number needs to be sampled, the value of the array element corresponding to the position of the tenth digit in the 8-bit array element corresponding to the ninth digit plus 1 in the third array is set to 1.
[0098] In one of the embodiments, after traversing the port numbers of all messages, when it is determined that the message corresponding to the current port number needs to be sampled, the value of the array element at the position corresponding to the current port number in the second array is set to 1, and the first creation module is also used to set the value of the array element at the position corresponding to the current port number in the second array to 0 when it is determined that the message corresponding to the current port number needs to be filtered.
[0099] In one of the embodiments, when it is determined that the message corresponding to the current port number needs to be sampled, after setting the value of the array element corresponding to the position of the tenth digit in the 8-bit array element corresponding to the ninth digit plus 1 in the third array to 1, the second creation module is also used to set the value of the array element corresponding to the position of the tenth digit in the 8-bit array element corresponding to the ninth digit plus 1 in the third array to 0 when it is determined that the message corresponding to the current port number needs to be filtered.
[0100] In one of the embodiments, after obtaining the value of the array element corresponding to the position of the third number in the 8-bit array element corresponding to the second number plus 1 in the first array, and determining whether the message corresponding to the port number of the message to be queried has been sampled based on the value of the array element, the search module 54 is also used to filter the message to be queried when the value of the port number identifier of the message to be queried is 0.
[0101] In one embodiment, after applying for a continuous third array to store the port number identifiers of all messages, and before traversing the port numbers of all messages, the second creation module is further used to clear the content of the applied third array.
[0102] It should be noted that the above modules can be functional modules or program modules, and can be implemented by software or hardware. The above modules can be embedded in or independent of the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0103] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 6 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store a preset configuration information set. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the above-mentioned message sampling method based on bitmap calculation is implemented.
[0104] In one embodiment, a computer device is provided, which may be a terminal. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a message sampling method based on bitmap calculation is implemented. The display screen of the computer device may be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device may be a touch layer covered on the display screen, or a key, trackball, or touchpad provided on the housing of the computer device, or an external keyboard, touchpad, or mouse, etc.
[0105] Those skilled in the art will understand that Figure 6 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0106] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0107] Obtain a first digit corresponding to the port number of the message to be queried, where the first digit is a binary number;
[0108] Shift the first number right by three bits to obtain the second number;
[0109] Perform a bitwise AND operation on the first number and 111 to obtain the third number;
[0110] Obtain the value of the array element corresponding to the position of the third number in the 8-bit array element corresponding to the second number plus 1 in the first array, and determine whether the message corresponding to the port number of the message to be queried is sampled according to the value of the array element; the first array is pre-created based on the port number identifiers of all messages, and the value of the array element of the first array represents the port number identifier of the message to be queried.
[0111] In one embodiment, before obtaining the first number corresponding to the port number of the message to be queried, the processor further implements the following steps when executing the computer program:
[0112] Get the fourth number corresponding to the maximum port number of all messages, apply for a continuous second array to store the port number identifiers of all messages, the size of the second array is the fourth number, and the fourth number is a decimal number;
[0113] The port numbers of all messages are traversed, and when it is determined that the message corresponding to the current port number needs to be sampled, the value of the array element at the position corresponding to the current port number in the second array is set to 1.
[0114] In one embodiment, before obtaining the first number corresponding to the port number of the message to be queried, the processor further implements the following steps when executing the computer program:
[0115] Get the fifth digit corresponding to the maximum port number of all messages, where the fifth digit is a binary number;
[0116] Shift the fifth digit right by three bits to obtain the sixth digit;
[0117] Add 1 to the sixth number and then multiply by 8 to get the seventh number. Apply for a continuous third array to store the port number identifiers of all messages. The size of the third array is the seventh number.
[0118] Traverse the port numbers of all messages, shift the eighth digit corresponding to the current port number right by three bits to get the ninth digit, perform a bitwise AND operation on the eighth digit and 111 to get the tenth digit. The eighth digit is a binary number.
[0119] When it is determined that the message corresponding to the current port number needs to be sampled, the value of the array element corresponding to the position of the tenth digit in the 8-bit array element corresponding to the ninth digit plus 1 in the third array is set to 1.
[0120] In one embodiment, when traversing the port numbers of all messages, when it is determined that the message corresponding to the current port number needs to be sampled, after setting the value of the array element at the position corresponding to the current port number in the second array to 1, the processor further implements the following steps when executing the computer program:
[0121] When it is determined that the message corresponding to the current port number needs to be filtered, the value of the array element at the position corresponding to the current port number in the second array is set to 0.
[0122] In one embodiment, when it is determined that the message corresponding to the current port number needs to be sampled, after setting the value of the array element corresponding to the position of the tenth digit in the 8-bit array element corresponding to the ninth digit plus 1 in the third array to 1, the processor further implements the following steps when executing the computer program:
[0123] When it is determined that the message corresponding to the current port number needs to be filtered, the value of the array element corresponding to the position of the tenth digit in the 8-bit array element corresponding to the ninth digit plus 1 in the third array is set to 0.
[0124] In one embodiment, after obtaining the value of the array element corresponding to the position of the third digit in the 8-bit array element corresponding to the second digit plus 1 in the first array, and determining whether the message corresponding to the port number of the message to be queried is sampled according to the value of the array element, the processor further implements the following steps when executing the computer program:
[0125] When the value of the port number identifier of the message to be queried is 0, the message to be queried is filtered.
[0126] In one embodiment, after applying for a continuous third array to store the port number identifiers of all messages and before traversing the port numbers of all messages, the processor further implements the following steps when executing the computer program:
[0127] Clear the contents of the third array obtained.
[0128] The storage medium, in the process of port number identification query, reduces the memory occupied by storing the port number by making a one-to-one correspondence between the port number and the array element address, and optimizes the port number identification query method by querying the port number identification in a bitmap-based calculation method. Finally, it is determined whether the current message to be queried is sampled according to the query result. By using the message sampling method based on bitmap calculation provided by the present application for port filtering, the memory occupied by storing the port number can be reduced and the query efficiency of the port number identification can be improved.
[0129] It should be understood that the specific embodiments described herein are only used to explain the application, rather than to limit it. Based on the embodiments provided in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the protection scope of this application.
[0130] Obviously, the drawings are only some examples or embodiments of the present application. For ordinary technicians in the field, the present application can also be applied to other similar situations based on these drawings without creative work. In addition, it is understandable that although the work done in this development process may be complicated and lengthy, for ordinary technicians in the field, certain changes in design, manufacturing or production based on the technical content disclosed in this application are only conventional technical means and should not be regarded as insufficient content disclosed in this application.
[0131] The term "embodiment" in this application refers to a specific feature, structure or characteristic described in conjunction with the embodiment that can be included in at least one embodiment of the present application. The appearance of this phrase in various locations in the specification does not necessarily mean the same embodiment, nor does it mean that it is mutually exclusive with other embodiments and is independent or optional. It is clearly or implicitly understood by those of ordinary skill in the art that the embodiments described in this application can be combined with other embodiments without conflict.
[0132] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of patent protection. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the scope of protection of the present application. Therefore, the scope of protection of the present application shall be subject to the attached claims.
Claims
1. A message sampling method based on bitmap calculation, characterized in that: The following steps are involved: Mapping method: obtaining the fifth digit corresponding to the maximum port number of all messages, wherein the fifth digit is a binary number; Shift the fifth digit right by three bits to obtain a sixth digit; Add 1 to the sixth number and then multiply by 8 to obtain a seventh number, and apply for a continuous third array to store the port number identifiers of all messages, and the size of the third array is the seventh number; Traverse the port numbers of all messages, perform a bitwise operation on the eighth digit corresponding to the current port number, right-shift the eighth digit by three bits to obtain a ninth digit, perform a bitwise AND operation on the eighth digit and 111 to obtain a tenth digit, where the eighth digit is a binary number; when it is determined that the message corresponding to the current port number needs to be sampled, set the value of the array element corresponding to the position of the tenth digit in the 8-bit array element corresponding to the ninth digit plus 1 in the third array to 1; Sampling method: obtaining a first number corresponding to the port number of the message to be queried, where the first number is a binary number; Shift the first number right by three bits to obtain a second number; Perform a bitwise AND operation on the first number and 111 to obtain a third number; Obtain the value of the array element corresponding to the position of the third number in the 8-bit array element corresponding to the second number plus 1 in the first array, and determine whether the message corresponding to the port number of the message to be queried is sampled according to the value of the array element; the first array is pre-created based on the port number identifiers of all messages, and the value of the array element of the first array represents the value of the port number identifier of the message to be queried.
2. The message sampling method based on bitmap calculation according to claim 1, characterized in that: Before obtaining the first number corresponding to the port number of the message to be queried, the method further includes the following steps: Obtain a fourth number corresponding to the maximum port number of all messages, apply for a continuous second array to store the port number identifiers of all messages, the size of the second array is the fourth number, and the fourth number is a decimal number; The port numbers of all messages are traversed, and when it is determined that the message corresponding to the current port number needs to be sampled, the value of the array element at the position corresponding to the current port number in the second array is set to 1.
3. The message sampling method based on bitmap calculation according to claim 2 is characterized in that: In the traversal of the port numbers of all messages, when it is determined that the message corresponding to the current port number needs to be sampled, after setting the value of the array element at the position corresponding to the current port number in the second array to 1, the method further includes: When it is determined that the message corresponding to the current port number needs to be filtered, the value of the array element at the position corresponding to the current port number in the second array is set to 0.
4. The message sampling method based on bitmap calculation according to claim 1, characterized in that: In the case where it is determined that the message corresponding to the current port number needs to be sampled, after setting the value of the array element corresponding to the position of the tenth digit in the 8-bit array element corresponding to the ninth digit plus 1 in the third array to 1, the method further includes: When it is determined that the message corresponding to the current port number needs to be filtered, the value of the array element corresponding to the position of the tenth digit in the 8-bit array element corresponding to the ninth digit plus 1 in the third array is set to 0.
5. The message sampling method based on bitmap calculation according to claim 1, characterized in that: In the obtaining of the first array, in the 8-bit array element corresponding to the second number plus 1, the value of the array element corresponding to the position of the third number, after determining whether the message corresponding to the port number of the message to be queried has been sampled according to the value of the array element, the method further comprises the following steps; When the value of the port number identifier of the message to be queried is 0, the message to be queried is filtered.
6. The message sampling method based on bitmap calculation according to claim 1, characterized in that: After applying for a continuous third array to store the port number identifiers of all messages and before traversing the port numbers of all messages, the method further includes: Clear the content of the third array applied for.
7. A message sampling device based on bitmap calculation, characterized in that: The device further comprises: an acquisition module, a first conversion module, a second conversion module, a search module and a result module: The acquisition module is used to acquire a fifth digit corresponding to the maximum port number of all messages, where the fifth digit is a binary number; Shift the fifth digit right by three bits to obtain a sixth digit; Add 1 to the sixth number and then multiply by 8 to obtain a seventh number, and apply for a continuous third array to store the port number identifiers of all messages, and the size of the third array is the seventh number; Traverse the port numbers of all messages, perform a bitwise operation on the eighth digit corresponding to the current port number, right-shift the eighth digit by three bits to obtain a ninth digit, perform a bitwise AND operation on the eighth digit and 111 to obtain a tenth digit, where the eighth digit is a binary number; when it is determined that the message corresponding to the current port number needs to be sampled, set the value of the array element corresponding to the position of the tenth digit in the 8-bit array element corresponding to the ninth digit plus 1 in the third array to 1; The acquisition module is further used to acquire a first number corresponding to the port number of the message to be queried, where the first number is a binary number; The first conversion module is used to perform a bitwise operation of right-shifting the first number by three digits to obtain a second number; The second conversion module is used to perform a bitwise AND operation on the first number and 111 to obtain a third number; The search module is used to obtain the value of the array element corresponding to the position of the third number in the 8-bit array element corresponding to the second number plus 1 in the first array, and determine whether the message corresponding to the port number of the message to be queried is sampled according to the value of the array element; the first array is pre-created based on the port number identifiers of all messages, and the value of the array element of the first array represents the value of the port number identifier of the message to be queried.
8. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Port bitmap-based hardware message sampling system and method for same
CN102571563A