[go: up one dir, main page]

CN114422488A - Multi-thread message processing method based on netty framework - Google Patents

Multi-thread message processing method based on netty framework Download PDF

Info

Publication number
CN114422488A
CN114422488A CN202210078856.5A CN202210078856A CN114422488A CN 114422488 A CN114422488 A CN 114422488A CN 202210078856 A CN202210078856 A CN 202210078856A CN 114422488 A CN114422488 A CN 114422488A
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.)
Granted
Application number
CN202210078856.5A
Other languages
Chinese (zh)
Other versions
CN114422488B (en
Inventor
刘映影
陈伟
蒋龙生
代锡玻
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chongqing Innovation Center of Beijing University of Technology
Original Assignee
Chongqing Innovation Center of Beijing University of Technology
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Chongqing Innovation Center of Beijing University of Technology filed Critical Chongqing Innovation Center of Beijing University of Technology
Priority to CN202210078856.5A priority Critical patent/CN114422488B/en
Publication of CN114422488A publication Critical patent/CN114422488A/en
Application granted granted Critical
Publication of CN114422488B publication Critical patent/CN114422488B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/141Setup of application sessions
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/22Parsing or analysis of headers

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer Security & Cryptography (AREA)
  • Stored Programmes (AREA)
  • Computer And Data Communications (AREA)

Abstract

The invention provides a multi-thread message processing method based on a netty framework, which relates to the technical field of computer information processing and comprises the steps of establishing an event cycle group to construct a thread pool, establishing a udp starting class, binding a custom processing class, monitoring by associating with a specified port, realizing a cycle algorithm of the event cycle group in the custom processing class, and executing message analysis in a polling thread pool mode. The invention changes the single thread processing mode in the netty into the multi-thread mode by polling the netty thread pool at the server, thereby improving the speed of message processing.

Description

Multi-thread message processing method based on netty framework
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 client-server framework based on nio, greatly simplifies and optimizes network programming of tcp and udp socket servers and the like, and obviously improves many aspects of performance, safety and the like.
In a multi-unmanned aerial vehicle cooperative system platform, generally, a plurality of unmanned aerial vehicles are integrated in the same udp client, and an udp server is built on the basis of a netty framework on a web side to perform message interaction with the unmanned aerial vehicle client. However, for the same client, only one working thread is provided inside the netty for channel connection and message processing, which greatly limits the asynchronous message processing capability of the netty, easily causes message blocking, and reduces the performance of a server system. For the situation of a large amount of communication of a single client, because only one channel of the udp server of the netty receives and transmits data, namely only 1 socket receives and transmits data, and then queues to copy the data, 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 multithreading message processing method based on a netty framework, wherein a working mode of a single thread group is replaced by a multithreading group based on a netty internal working thread group, when a udp server is constructed to be connected, a netty internal thread pool is created, the working thread group is used as an entry parameter to be transmitted into a custom processing message class, information processing is carried out in a mode of polling an internal thread group, the single thread processing mode in the netty is changed into multithreading, and therefore the speed of processing messages by the server is improved, and the multi-unmanned-aerial-vehicle cooperative system platform has the capability of concurrently processing the same udp client.
The invention provides a multithreading message processing method based on a netty framework, which has the following specific technical scheme:
the method is applied to the udp client and the udp server built based on the netty;
the method comprises the following steps:
s1: creating an event loop group through the evenLoopgroup, wherein the event loop group serves as an internal thread of the netty framework and is used for receiving connection of a plurality of clients and processing messages sent by the clients;
s2: creating a udp server starter as an entrance for connecting the udp client;
s3: binding the udp server initiator to an event loop group evenLoopgroup;
s4: setting a channel of the udp server side starter, wherein the channel is used for receiving and transmitting an udp data packet and setting a propagation mode of udp;
s5: creating a udp starting class, creating a custom processing class and binding the udp starting class, and binding the udp starting class to a specified 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 loop group, and simultaneously creating a corresponding parameter construction method to carry out global instantiation assignment on the event loop group in the custom processing class;
s6: and adopting a polling thread pool mode rewriting method in the user-defined processing class to analyze and process the message information sent by the udp client.
Further, the event loop group creates 10 work threads.
Further, in step S3, the udp server initiator and the event loop group are bound by a server boot trace group method.
Further, in step S4, class is selected as the channel of the udp server initiator.
Further, in step S4, the propagation mode of udp is set to the broadcast mode.
Further, the custom processing class inherits the simplechannelnboundhandler class, and the method of rewriting channelRead0 in the custom processing class is used for polling and analyzing the message.
The invention has the following beneficial effects:
in the message interaction between the udp client and the udp server built on the web end based on the netty framework, a nio thread built by a netty source code is utilized, but a non-custom thread pool is concurrently processed, based on a netty internal working thread group, when the udp server is constructed for connection, the netty internal thread pool is built, the working thread group is used as an entry parameter to be transmitted into a custom processing message class, and then message analysis is performed in a polling internal thread group mode, so that the effective utilization rate of computer resources is improved, and the processing speed of information of the udp client is improved.
Drawings
FIG. 1 is a schematic flow diagram of the process of the present invention.
Detailed Description
In the following description, technical solutions in the embodiments of the present invention are clearly and completely described, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present 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 netty; for example, a multi-unmanned aerial vehicle cooperative system platform, a java background serves as a server, the java background is connected with an unmanned aerial vehicle plug-in through a udp protocol and receives various message data information of the unmanned aerial vehicle, and then a polling netty internal multithreading pool is adopted to analyze and process 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 control of an unmanned aerial vehicle cluster is achieved.
As shown in fig. 1, the specific steps are as follows:
s1: creating an event loop group through the evenLoopgroup, wherein the event loop group serves as an internal thread of the netty framework and is used for receiving connection of a plurality of clients and processing messages sent by the clients;
creating an eventloop group by new NioEventLoopgroup (x); the eventloop group is essentially a thread pool, and in the embodiment, X is set to 10, that is, 10 working threads are created as internal threads of the netty framework.
S2: creating a udp server side starter boottrap: serving as an entrance for connecting the udp client, wherein the server Bootstrap () is new Bootstrap ();
s3: binding the udp server initiator to an event loop group evenLoopgroup;
and binding the event loop group eventLoopGroup by using a server Bootstrap starter created above through a server Bootstrap group () method.
S4: setting a channel of the udp server side starter, wherein the channel is used for receiving and transmitting an udp data packet and setting a propagation mode of udp;
in this embodiment, a channel niodatagramcchannel.class is selected as a channel of the udp server initiator, and the channel can receive and transmit udp data packets;
set the propagation mode of udp packets to BROADCAST mode through option (channel option.
S5: creating a udp start class, creating a user-defined processing class BootNet 5 gddpsSimpleChannelInbound Handler, binding the udp start class with a handler () method, and then carrying out message monitoring on the udp start class bind to a specified port;
the user-defined processing class BootNet 5gUdpSimpleChannelInboundHandler inherits the SimpleChannelInboundHandler class;
defining a global variable eventloop group in the custom processing class, and simultaneously creating a corresponding parameter construction method to carry out global instantiation assignment on the event loop group in the custom processing class, wherein the specific steps are as follows:
Public BootNetty5gUdpSimpleChannelInboundHandler(EventLoopGroup eventLoopGroup){this.eventLoopGroup=eventLoopGroup;}。
in the application environment of the embodiment, for the situation that one client is only connected with one server port, multiple unmanned aerial vehicles can be registered in the same client plug-in, and the plug-in communicates with the server; therefore, the server only connects to one client, namely only one netty thread serves the client, so that great resource waste is caused, eventloop group is used as an access parameter to be transmitted to the self-defined message processing class, and the client message is conveniently processed through a polling thread.
S6: rewriting a channelRead0 method in the custom processing class by adopting a polling thread pool mode, and analyzing and processing the message information sent by the udp client;
because the eventLoop group created inside the net is already bound with the udp server, the value is assigned by the parameter construction method, the message analysis is executed by adopting a polling thread pool mode in the channelRead0() method through the rewriting method, an executor (eventLoop) of the next event needs to be provided by the next () method, the eventLoop group is thread pool management based on ExecutorService, and an execute () method is called to execute a message analysis command after the next eventLoop is obtained, which is specifically as follows:
Figure BDA0003485132320000041
the invention is not limited to the foregoing embodiments. The invention extends to any novel feature or any novel combination of features disclosed in this specification and any novel method or process steps or any novel combination of features disclosed.

Claims (6)

1. A multithreading 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 netty;
the method comprises the following steps:
s1: creating an event loop group through the evenLoopgroup, wherein the event loop group serves as an internal thread of the netty framework and is used for receiving connection of a plurality of clients and processing messages sent by the clients;
s2: creating a udp server starter as an entrance for connecting the udp client;
s3: binding the udp server initiator to an event loop group evenLoopgroup;
s4: setting a channel of the udp server side starter, wherein the channel is used for receiving and transmitting an udp data packet and setting a propagation mode of udp;
s5: creating a udp starting class, creating a custom processing class and binding the udp starting class, and binding the udp starting class to a specified 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 loop group, and simultaneously creating a corresponding parameter construction method to carry out global instantiation assignment on the event loop group in the custom processing class;
s6: and adopting a polling thread pool mode rewriting method in the user-defined processing class to analyze and process the message information sent by the udp client.
2. A method of multithreaded message processing as in claim 1 wherein the set of event loops creates 10 worker threads.
3. A multithreading message processing method according to claim 1, wherein in step S3, the udp server initiator and the event loop group eventorloopgroup are bound by a serverpottrap.
4. The multithread message processing method of claim 1, wherein in step S4, NioDatagramChannel class is selected as the channel of the udp server initiator.
5. The multithread message processing method of claim 1, wherein in step S4, the propagation mode of udp is set to broadcast mode.
6. A method for multithreaded message processing as in claim 1, wherein the custom processing class inherits a simplechannelnboundhandler class, and wherein the custom processing class rewrites a channelRead0 method for polling and parsing a message.
CN202210078856.5A 2022-01-24 2022-01-24 Multithreading message processing method based on netty framework Active CN114422488B (en)

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 true CN114422488A (en) 2022-04-29
CN114422488B 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)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116016706A (en) * 2022-12-29 2023-04-25 航天新通科技有限公司 A high-efficiency data transfer method and storage medium based on Netty

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130179947A1 (en) * 2012-01-05 2013-07-11 Adept Cloud, Inc. System and method for decentralized online data transfer and synchronization
CN109756461A (en) * 2017-11-06 2019-05-14 北京航天长峰科技工业集团有限公司 A kind of remote procedure calling (PRC) method based on NETTY
US20200272670A1 (en) * 2019-02-25 2020-08-27 Oracle International Corporation Client API for Rest Based Endpoints for a Multi-Tenant Identify Cloud Service
CN111683069A (en) * 2020-05-28 2020-09-18 杭州绿度信息技术有限公司 A custom communication protocol and service method based on netty framework

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130179947A1 (en) * 2012-01-05 2013-07-11 Adept Cloud, Inc. System and method for decentralized online data transfer and synchronization
CN109756461A (en) * 2017-11-06 2019-05-14 北京航天长峰科技工业集团有限公司 A kind of remote procedure calling (PRC) method based on NETTY
US20200272670A1 (en) * 2019-02-25 2020-08-27 Oracle International Corporation Client API for Rest Based Endpoints for a Multi-Tenant Identify Cloud Service
CN111683069A (en) * 2020-05-28 2020-09-18 杭州绿度信息技术有限公司 A custom communication protocol and service method based on netty framework

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
刘新强;曾兵义;: "用线程池解决服务器并发请求的方案设计", 现代电子技术, no. 15 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116016706A (en) * 2022-12-29 2023-04-25 航天新通科技有限公司 A high-efficiency data transfer method and storage medium based on Netty

Also Published As

Publication number Publication date
CN114422488B (en) 2023-09-12

Similar Documents

Publication Publication Date Title
KR100253930B1 (en) Dynamic eaecution unit management for high performance user level network protocol server system
US8396959B2 (en) Method and system for monitoring messages passed over a network
CN109445944A (en) A kind of network data acquisition processing system and its method based on DPDK
DE112010004017T5 (en) Single-stack ReaI-Time operating system for embedded systems
CN110851252A (en) Protocol conversion equipment and protocol conversion method based on TSN (traffic service network) architecture
CN114422488A (en) Multi-thread message processing method based on netty framework
CN113722103A (en) Encryption card calling control method and communication equipment
Qi et al. Lifl: A lightweight, event-driven serverless platform for federated learning
CN118332991A (en) Regular expression matching method, device, equipment and medium based on FPGA
CN106453112A (en) Method and server for processing coflow information in RPC communication
Luo et al. A centralized discovery-based method for integrating data distribution service and time-sensitive networking for in-vehicle networks
CN1584842A (en) Method for applied server of computer system
US20030202522A1 (en) System for concurrent distributed processing in multiple finite state machines
KR20080047248A (en) Remote security testing device and method of RPC-based software
CN105302557A (en) Thread establishing and processing method and apparatus
CN116233101B (en) Data acquisition task framework based on HTTP interface hot deployment and use method
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
CN114444117B (en) Cloud data evidence obtaining method and system
CN115733886B (en) Embedded communication system, method, device, medium and vehicle based on FPGA and ROS
CN118474183A (en) Data transmission method, CUC architecture, storage medium and program product based on data analysis
CN113535389B (en) Experimental scheme parallel deduction management and control system
CN102693434B (en) Communication apparatus and method for interface layer of radio frequency identification device
CN114546670B (en) A functional asynchronous data distribution system and method based on coroutine
Petrone et al. Enabling pvm to build parallel multidomain virtual machines

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