CN114422488B - Multithreading message processing method based on netty framework - Google Patents
Multithreading message processing method based on netty framework Download PDFInfo
- Publication number
- CN114422488B CN114422488B CN202210078856.5A CN202210078856A CN114422488B CN 114422488 B CN114422488 B CN 114422488B CN 202210078856 A CN202210078856 A CN 202210078856A CN 114422488 B CN114422488 B CN 114422488B
- Authority
- CN
- China
- Prior art keywords
- udp
- class
- processing
- message
- netty
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000003672 processing method Methods 0.000 title claims abstract description 9
- 238000010276 construction Methods 0.000 claims abstract description 5
- 238000012544 monitoring process Methods 0.000 claims abstract description 4
- 238000000034 method Methods 0.000 claims description 25
- 239000007858 starting material Substances 0.000 claims description 12
- 239000003999 initiator Substances 0.000 claims description 3
- 238000004458 analytical method Methods 0.000 abstract description 4
- 125000004122 cyclic group Chemical group 0.000 abstract 3
- 230000010365 information processing Effects 0.000 abstract 1
- 230000000903 blocking effect Effects 0.000 description 2
- 238000004891 communication Methods 0.000 description 2
- 230000003993 interaction Effects 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 239000002699 waste material Substances 0.000 description 1
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/02—Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/14—Session management
- H04L67/141—Setup of application sessions
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/22—Parsing or analysis of headers
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer Security & Cryptography (AREA)
- Computer And Data Communications (AREA)
- Stored Programmes (AREA)
Abstract
The invention provides a multithreading message processing method based on a netty framework, which relates to the technical field of computer information processing and comprises the steps of creating an event cyclic group construction thread pool, creating a udp starting class, binding a custom processing class, associating a designated port for monitoring, realizing a cyclic algorithm of the event cyclic group in the custom processing class, and executing message analysis in a mode of polling the thread pool. According to the invention, the single-thread processing mode in the netty is changed into the multithreading mode by polling the netty thread pool at the server, so that the speed of message processing is improved.
Description
Technical Field
The invention relates to the technical field of message processing communication, in particular to a multithreading message processing method based on a netty framework.
Background
The netty is a nio-based client-server framework, greatly simplifies and optimizes the network programming of tcp and udp socket servers and the like, and obviously improves the performance, the security and the like.
In a multi-unmanned aerial vehicle collaborative system platform, a plurality of unmanned aerial vehicles are integrated in the same udp client, a udp server is built on a web terminal based on a netty framework, and message interaction is carried out with the unmanned aerial vehicle client. However, for the same client, only one working thread is provided for channel connection and message processing in the netty, which greatly limits the netty asynchronous multiprocessing message capability, easily causes message blocking and reduces the system performance of the server. For the situation of a large number of communication of a single client, as the udp server of the netty only has one channel for receiving data, namely only 1 socket is for receiving and transmitting data, and then the data is queued for copying, the operation effect is similar to blocking, so that the message processing is not timely enough, and the whole message processing process is equivalent to a serial execution program.
Disclosure of Invention
In order to solve the problems, the invention provides a multithread message processing method based on a netty framework, which is based on a netty internal working thread group, uses a multithread group to replace a working mode of a single thread group, creates a netty internal thread pool when a udp server is constructed to be connected, takes the working thread group as an input to a custom processing message class, processes information by polling the internal thread group, changes the single thread processing mode in the netty into a multithread mode, thereby improving the speed of processing the message by the server and enabling a multi-unmanned-plane cooperative system platform to have the capability of concurrently processing the same udp client.
The invention provides a multithreading message processing method based on a netty framework, which comprises the following specific technical scheme:
the method is applied to a udp client and a udp server built based on netty;
the method comprises the following steps:
s1: creating an event cycle group through eventLoopGroup, and taking the event cycle group as an internal thread of a netty framework, wherein the event cycle group is used for receiving the connection of a plurality of clients and processing the information sent by the clients;
s2: creating a udp server starter as an entrance for connecting the udp client;
s3: binding the udp service end starter to an event cycle group eventLoopGroup;
s4: setting a channel of the udp server starter, which is used for receiving and transmitting the udp data packet, and setting a propagation mode of the udp;
s5: creating a udp startup class, creating a custom processing class to bind with the udp startup class, and binding the udp startup class to a designated port for message monitoring;
defining a global variable EventLoopGroup in the custom processing class, wherein the variable name is consistent with the variable name of the event cycle group, and simultaneously creating a corresponding parameter construction method to carry out global instantiation assignment on the event cycle group EventLoopGroup in the custom processing class;
s6: and adopting a polling thread pool mode to rewrite a method in the custom processing class, and analyzing and processing the message information sent by the udp client.
Further, the event loop group creates 10 worker threads.
Further, in step S3, the udp server starter binds with the eventLoopGroup by a serverboottrap.
Further, in step S4, niodatagramchannel. Class is selected as the channel of the udp server initiator.
Further, in step S4, the broadcast mode of the udp is set.
Further, the custom processing class inherits the simpleChannelInboundHandler class, and the channel read0 method is rewritten in the custom processing class to poll and analyze the message.
The beneficial effects of the invention are as follows:
in the message interaction between the udp client and the udp server built by the web end based on the netty framework, a nio thread created by the netty source code is utilized to perform concurrent processing instead of a custom thread pool, and when the udp server is constructed to be connected based on the netty internal working thread group, the netty internal thread pool is created, the working thread group is used as an input to enter custom processing message class, and then message analysis is performed in a mode of polling the internal thread group, so that the effective utilization rate of computer resources is improved, and meanwhile, the processing speed of the information of the udp client is also improved.
Drawings
FIG. 1 is a schematic flow chart of the method of the present invention.
Detailed Description
In the following description, the technical solutions of the embodiments of the present invention are clearly and completely described, and it is obvious that the described embodiments are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Example 1
The embodiment 1 of the invention discloses a multithreading message processing method based on a netty framework, which is applied to a udp client and a udp server built based on the netty; for example, a multi-unmanned aerial vehicle collaborative system platform, a java background is used as a server, an unmanned aerial vehicle plug-in unit is connected through a udp protocol, and each item of message data information of the unmanned aerial vehicle is received, and then a polling netty internal multithreading pool is adopted to analyze the message information, so that a single-thread working mode corresponding to a single client in a netty framework is changed into a multithreading working mode, and the unmanned aerial vehicle cluster is controlled.
As shown in fig. 1, the specific step flow is as follows:
s1: creating an event cycle group through eventLoopGroup, and taking the event cycle group as an internal thread of a netty framework, wherein the event cycle group is used for receiving the connection of a plurality of clients and processing the information sent by the clients;
creating an event cycle group eventLoopGroup by eventloopgroup= new NioEventLoopGroup (x); eventLoopGroup is essentially a thread pool, in this embodiment X is set to 10, i.e. 10 worker threads are created as internal threads of the netty framework.
S2: creating a udp server starter Bootstrap: serverstrotstrap = new boottrap (), as an entry to connect to the udp client;
s3: binding the udp service end starter to an event cycle group eventLoopGroup;
and binding the event cycle group eventLoopGroup to the serverBootstrap starter created above through a serverBootstrap.group () method.
S4: setting a channel of the udp server starter, which is used for receiving and transmitting the udp data packet, and setting a propagation mode of the udp;
in this embodiment, a channel niodatagramchannel. Class is selected as a channel of the udp server starter, which is capable of receiving and transmitting udp packets;
the propagation mode of the udp packet is set to be a BROADCAST mode by option (channel option. So_broadcast, true).
S5: creating a udp startup class, creating a custom processing class BootNet 5gUdpSimpleChannelInboundHandler, binding the custom processing class BootNet with the udp startup class through a handler () method, and then monitoring a message from the udp startup class bind to a designated port;
the customization processing class BootNetty5gUdpSimpleChannelInboundHandler inherits the SimpleChannelInboundHandler class;
defining global variables EventLoopGroup eventLoopGroup in the custom processing class, and simultaneously creating a corresponding parametric construction method to carry out global instantiation assignment on the event cycle group eventLoopGroup in the custom processing class, wherein the method specifically comprises the following steps:
Public BootNetty5gUdpSimpleChannelInboundHandler(EventLoopGroup eventLoopGroup){this.eventLoopGroup=eventLoopGroup;}。
under the application environment in the embodiment, for the case that one client is only connected with one server port, multiple unmanned opportunities are registered in the same client plug-in unit, and the plug-in unit communicates with the server; therefore, the server side can only be connected with one client side, namely only one netty thread can serve the client side, so that great resource waste is caused, the eventLoopGroup is used as an entry to be transmitted to a user-defined message processing class, and the client side message can be processed through the polling thread in parallel.
S6: the channel read0 method is rewritten in the self-defined processing class by adopting a polling thread pool mode, and the message information sent by the udp client is analyzed and processed;
since the eventLoopGroup created inside the netty is already bound with the udp server, the assignment is performed by the above-mentioned parameter construction method, and by the rewriting method, the message analysis is performed by adopting the polling thread pool mode in the channel read0 () method, and an executor (eventLoop) of the next event needs to be provided by the next () method, where the eventLoopGroup is based on the exetechnology to perform thread pool management, and after the next eventLoop is obtained, the exetechnology () method is called to execute the message analysis command, specifically as follows:
the invention is not limited to the specific embodiments described above. The invention extends to any novel one, or any novel combination, of the features disclosed in this specification, as well as to any novel one, or any novel combination, of the steps of the method or process disclosed.
Claims (6)
1. A multithread message processing method based on a netty framework is characterized in that the method is applied to a udp client and a udp server built based on the netty;
the method comprises the following steps:
s1: creating an event cycle group through eventLoopGroup, and taking the event cycle group as an internal thread of a netty framework, wherein the event cycle group is used for receiving the connection of a plurality of clients and processing the information sent by the clients;
s2: creating a udp server starter as an entrance for connecting the udp client;
s3: binding the udp service end starter to an event cycle group eventLoopGroup;
s4: setting a channel of the udp server starter, which is used for receiving and transmitting the udp data packet, and setting a propagation mode of the udp;
s5: creating a udp startup class, creating a custom processing class to bind with the udp startup class, and binding the udp startup class to a designated port for message monitoring;
defining a global variable EventLoopGroup in the custom processing class, wherein the variable name is consistent with the variable name of the event cycle group, and simultaneously creating a corresponding parameter construction method to carry out global instantiation assignment on the event cycle group EventLoopGroup in the custom processing class;
s6: and adopting a polling thread pool mode to rewrite a method in the custom processing class, and analyzing and processing the message information sent by the udp client.
2. The multi-threaded message processing method of claim 1 wherein the set of event loops creates 10 worker threads.
3. The method for processing multithreaded messages according to claim 1, wherein in step S3, the udp server initiator is bound to the eventLoopGroup by a serverboottrap.
4. The method according to claim 1, wherein in step S4, niodatagramchannel. Class is selected as the channel of the udp server initiator.
5. The method according to claim 1, wherein in step S4, the propagation mode of the udp is set to a broadcast mode.
6. The method of claim 1, wherein the custom processing class inherits a simplechannellnboundhandler class, and wherein the method of rewriting channelRead0 in the custom processing class polls and parses the message.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202210078856.5A CN114422488B (en) | 2022-01-24 | 2022-01-24 | Multithreading message processing method based on netty framework |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202210078856.5A CN114422488B (en) | 2022-01-24 | 2022-01-24 | Multithreading message processing method based on netty framework |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN114422488A CN114422488A (en) | 2022-04-29 |
| CN114422488B true CN114422488B (en) | 2023-09-12 |
Family
ID=81277385
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202210078856.5A Active CN114422488B (en) | 2022-01-24 | 2022-01-24 | Multithreading message processing method based on netty framework |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN114422488B (en) |
Families Citing this family (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN116016706A (en) * | 2022-12-29 | 2023-04-25 | 航天新通科技有限公司 | Efficient data conversion method based on Netty and storage medium |
Citations (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109756461A (en) * | 2017-11-06 | 2019-05-14 | 北京航天长峰科技工业集团有限公司 | A kind of remote procedure calling (PRC) method based on NETTY |
| CN111683069A (en) * | 2020-05-28 | 2020-09-18 | 杭州绿度信息技术有限公司 | A custom communication protocol and service method based on netty framework |
Family Cites Families (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US8955103B2 (en) * | 2012-01-05 | 2015-02-10 | Hightail, Inc. | System and method for decentralized online data transfer and synchronization |
| US11423111B2 (en) * | 2019-02-25 | 2022-08-23 | Oracle International Corporation | Client API for rest based endpoints for a multi-tenant identify cloud service |
-
2022
- 2022-01-24 CN CN202210078856.5A patent/CN114422488B/en active Active
Patent Citations (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109756461A (en) * | 2017-11-06 | 2019-05-14 | 北京航天长峰科技工业集团有限公司 | A kind of remote procedure calling (PRC) method based on NETTY |
| CN111683069A (en) * | 2020-05-28 | 2020-09-18 | 杭州绿度信息技术有限公司 | A custom communication protocol and service method based on netty framework |
Non-Patent Citations (1)
| Title |
|---|
| 用线程池解决服务器并发请求的方案设计;刘新强;曾兵义;;现代电子技术(15);全文 * |
Also Published As
| Publication number | Publication date |
|---|---|
| CN114422488A (en) | 2022-04-29 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US20180173570A1 (en) | Edge computing platform | |
| CN103024022B (en) | A kind of managing and control system of virtual machine application service and method | |
| US20100293360A1 (en) | Automation device with control program and method for programming thereof | |
| EP2127221A1 (en) | A method and system for monitoring messages passed over a network | |
| US8352617B2 (en) | Method and system for data processing | |
| CN114422488B (en) | Multithreading message processing method based on netty framework | |
| CN106453112B (en) | The processing method and server of stream information in the same direction in RPC communication | |
| JP4896532B2 (en) | Communication channel model | |
| Li et al. | Ori: A greybox fuzzer for SOME/IP protocols in automotive Ethernet | |
| US9614900B1 (en) | Multi-process architecture for a split browser | |
| CN112698838A (en) | Multi-cloud container deployment system and container deployment method thereof | |
| CN101551758B (en) | System and method for implementing paralleling work of device management and tasks | |
| KR20080047248A (en) | Remote security testing device and method of RPC-based software | |
| CN116233101B (en) | Data acquisition task framework based on HTTP interface hot deployment and use method | |
| CN112650706A (en) | Method for realizing high situation perception capability under big data technology system | |
| CN116582582B (en) | Data acquisition method, system, equipment and medium for component type Internet of things | |
| CN112613276A (en) | Parallel execution method and system for streaming document analysis | |
| CN115794356B (en) | Multithread synchronous connection processing method based on SSH server | |
| CN114546670B (en) | A functional asynchronous data distribution system and method based on coroutine | |
| CN112448909A (en) | Electronic lock management method, device, system and storage medium | |
| Petrone et al. | Enabling pvm to build parallel multidomain virtual machines | |
| CN114444117B (en) | Cloud data evidence obtaining method and system | |
| CN111756836A (en) | Information sending method and device based on event management model | |
| CN109302398A (en) | Receiving, parsing and storage methods for IPv6 network UDP packets | |
| US10078314B2 (en) | Method for providing functions within an industrial automation system, and industrial automation system |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |