CN108337295B - Internet of things communication method, server and system - Google Patents

Internet of things communication method, server and system Download PDF

Info

Publication number
CN108337295B
CN108337295B CN201810028886.9A CN201810028886A CN108337295B CN 108337295 B CN108337295 B CN 108337295B CN 201810028886 A CN201810028886 A CN 201810028886A CN 108337295 B CN108337295 B CN 108337295B
Authority
CN
China
Prior art keywords
time
thread
server
working mode
terminal
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
Application number
CN201810028886.9A
Other languages
Chinese (zh)
Other versions
CN108337295A (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.)
Qingdao Haier Intelligent Home Appliance Technology Co Ltd
Original Assignee
Qingdao Haier Intelligent Home Appliance Technology Co Ltd
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 Qingdao Haier Intelligent Home Appliance Technology Co Ltd filed Critical Qingdao Haier Intelligent Home Appliance Technology Co Ltd
Priority to CN201810028886.9A priority Critical patent/CN108337295B/en
Publication of CN108337295A publication Critical patent/CN108337295A/en
Application granted granted Critical
Publication of CN108337295B publication Critical patent/CN108337295B/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/12Protocols specially adapted for proprietary or special-purpose networking environments, e.g. medical networks, sensor networks, networks in vehicles or remote metering networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Health & Medical Sciences (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • General Health & Medical Sciences (AREA)
  • Medical Informatics (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The invention discloses an Internet of things communication method, a server and a system, and belongs to the technical field of Internet of things communication. The communication method of the Internet of things is applied to a server and comprises the following steps: acquiring a first time T1 required for processing a connection request sent by a terminal in a current thread working mode; and judging whether the first time T1 reaches a first time threshold, and if the first time T1 reaches the first time threshold, switching the working mode of the current thread. And a corresponding module is arranged in the server to realize the communication method of the Internet of things. The server can be flexibly switched between a single-thread working mode and a multi-thread working mode according to the communication load of the terminal, and the capacity of the server for processing the connection request is improved. The Internet of things communication system formed by the server and the terminal also has the efficient communication capacity.

Description

Internet of things communication method, server and system
Technical Field
The invention relates to the technical field of communication of the Internet of things, in particular to a communication method, a server and a system of the Internet of things.
Background
In the current communication system of the internet of things, if threads in a server are too many, the cost of thread switching is high, server resources are occupied, and the performance of the server is reduced; if the thread process in the server is less, once the terminal connection requests increase, the server cannot exert the due performance, and the queue time of the connection requests can be increased.
Disclosure of Invention
The embodiment of the invention provides an Internet of things communication method, a server and a system. The following presents a simplified summary in order to provide a basic understanding of some aspects of the disclosed embodiments. This summary is not an extensive overview and is intended to neither identify key/critical elements nor delineate the scope of such embodiments. Its sole purpose is to present some concepts in a simplified form as a prelude to the more detailed description that is presented later.
According to a first aspect of the embodiments of the present invention, there is provided an internet of things communication method, applied to a server, including: acquiring a first time T1 required for processing a connection request sent by a terminal in a current thread working mode; and judging whether the first time T1 reaches a first time threshold, and if the first time T1 reaches the first time threshold, switching the current thread working mode.
The server in the method can be flexibly switched between the single-thread working mode and the multi-thread working mode according to the communication load of the terminal of the Internet of things, the capacity of the server for processing the connection request is improved, and the communication between the server and the terminal is more efficient.
In an optional embodiment, after the first time T1 reaches the first time threshold and before the switching of the current thread operating mode, the method further includes: judging whether the duration time of the current thread working mode reaches a second time threshold value; and if the duration time of the current thread working mode reaches the second time threshold, switching the current thread working mode.
In an optional embodiment, before obtaining the first time T1 required for processing the connection request sent by the terminal in the current thread operating mode, the method further includes an initialization thread operating mode, where the initialization thread operating mode includes setting the number of threads, the first time threshold, and the second time threshold.
In an optional embodiment, the obtaining of the first time T1 required for processing the connection request sent by the terminal in the current thread working mode includes: recording a time point t1 when the connection request sent by the terminal reaches the server; a selector reads the connection request and distributes a thread for processing the connection request; the thread reads and processes the connection request; recording the time t 1' when the thread finishes processing the connection request; the first time T1, T1 ═ T1' -T1.
In an optional embodiment, when the terminal accesses, the thread reads and processes the connection request, specifically: the connection request sent by the terminal is specifically an access request; the thread reads the access request; the thread sets a configuration file for the access request; the thread accepts the access request;
when receiving terminal data, the thread reads and processes the connection request, specifically: the thread reads the connection request; the thread allows the terminal to perform read-write operation in the server; and the thread receives data sent by the terminal.
According to a second aspect of the embodiments of the present invention, there is provided an internet of things communication server, including: the device comprises a first time acquisition module, a judgment module and a switching module; the first time acquisition module is used for acquiring first time required by the server for processing the connection request sent by the terminal in the current working mode; the judging module is used for judging whether the first time reaches a first time threshold value, and if the first time reaches the first time threshold value, the switching module is started; and the switching module is used for switching the current thread working mode of the server.
In an optional embodiment, the determining module is further configured to determine whether the duration of the current thread working mode reaches a second time threshold; and if the first time reaches the first time threshold value and the duration of the current thread working mode reaches the second time threshold value, starting a switching module.
In an optional embodiment, the system further includes an initialization module, where the initialization module is configured to set the number of threads, the first time threshold, and the second time threshold.
In an optional embodiment, the system further comprises a terminal access module and a data receiving module; the terminal access module is used for receiving an access request of a terminal; the data receiving module is used for receiving data sent by the terminal; the first time acquisition module is used for acquiring first time required by the terminal access module when the terminal access module operates in the current working mode; and when the data receiving module runs, the data receiving module is used for acquiring the first time required by the server to run the data receiving module once in the current working mode.
According to a third aspect of the embodiments of the present invention, there is provided an internet of things communication system, including a server, where the server is the server provided in the second aspect of the present invention.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention, as claimed.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and together with the description, serve to explain the principles of the invention.
Fig. 1 is a flow diagram illustrating a method of communication for the internet of things in accordance with an exemplary embodiment;
FIG. 2 is a diagram illustrating a relationship reflecting a number of threads of a server and a communication efficiency of the server, according to an example embodiment;
FIG. 3 is a diagram illustrating a relationship reflecting a number of threads of a server versus a communication efficiency of the server in accordance with an illustrative embodiment;
FIG. 4 is a diagram illustrating a relationship reflecting a number of threads of a server versus a communication efficiency of the server in accordance with an illustrative embodiment;
fig. 5 is a flowchart illustrating a method for obtaining a first time T1 required by a server to process a connection request sent by a terminal according to an exemplary embodiment;
fig. 6 is a flowchart illustrating a method for obtaining a first time T1 required by a server to process a connection request sent by a terminal according to an exemplary embodiment;
FIG. 7 is a schematic diagram illustrating a process for switching the operating mode of a current thread in accordance with an illustrative embodiment;
FIG. 8 is a diagram illustrating switching of a current thread mode of operation in accordance with an illustrative embodiment;
FIG. 9 is a flowchart illustrating the initialization of a thread mode of operation in accordance with an illustrative embodiment;
fig. 10 is a diagram illustrating a terminal access procedure in accordance with an example embodiment;
fig. 11 is a diagram illustrating a terminal access procedure in accordance with an example embodiment;
FIG. 12 is a schematic flow chart illustrating reception of terminal data according to an example embodiment;
FIG. 13 is a schematic flow chart illustrating reception of terminal data according to an example embodiment;
Detailed Description
The following description and the drawings sufficiently illustrate specific embodiments of the invention to enable those skilled in the art to practice them. The examples merely typify possible variations. Individual components and functions are optional unless explicitly required, and the sequence of operations may vary. Portions and features of some embodiments may be included in or substituted for those of others. The scope of embodiments of the invention encompasses the full ambit of the claims, as well as all available equivalents of the claims. Embodiments may be referred to herein, individually or collectively, by the term "invention" merely for convenience and without intending to voluntarily limit the scope of this application to any single invention or inventive concept if more than one is in fact disclosed. Herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed. The embodiments are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other. For the structures, products and the like disclosed by the embodiments, the description is relatively simple because the structures, the products and the like correspond to the parts disclosed by the embodiments, and the relevant parts can be just described by referring to the method part.
Referring to fig. 1 to 13, which illustrate a first aspect of an embodiment of the present invention, a communication method of an internet of things, as shown in fig. 1, is applied to a server, and includes:
s101, acquiring a first time T1 required by processing a connection request sent by a terminal in a current thread working mode;
s102, judging whether the first time T1 reaches a first time threshold value, and if the first time T1 reaches the first time threshold value, executing a step S103;
and S103, switching the working mode of the current thread.
In this embodiment, the current thread working mode is the thread working mode in which the server is located when the first time T1 is obtained; the thread working modes comprise: a single thread mode of operation and a multi-thread mode of operation. If the current thread working mode is the single thread working mode, switching the current thread working mode is to switch the single thread working mode to the multi-thread working mode; if the current thread working mode is the multi-thread working mode, switching the current thread working mode is to switch the multi-thread working mode to the single-thread working mode.
The server in the method can be flexibly switched between the single-thread working mode and the multi-thread working mode according to the communication load of the terminal of the Internet of things (hereinafter referred to as the terminal), so that the capacity of the server for processing the connection request is improved, and the communication between the server and the terminal is more efficient.
The first time T1 reflects the time consumed for packet transmission between the terminal and the server, that is, the communication efficiency of the communication system, and the larger the first time T1 is, the smoother the communication between the terminal and the server is, and the lower the efficiency of the communication system is; the factors that cause the increase of the first time T1 mainly have the following two aspects: 1) the communication load between the terminal and the server is large; for example, 300 terminals send a large number of connection requests to the server in a certain period of time, and the number of threads for processing the connection requests by the server is limited, for example, 60 threads can only process 60 connection requests at a time, and the other 240 connection requests are queued, so that for the other 240 connection requests queued for waiting, the time spent queued for waiting is counted in the time spent for sending packets, and thus the time spent for sending packets becomes large, that is, the first time T1 increases; for example, if the amount of communication between the terminal and the server is increased, the time for processing one connection request is increased, and the queue time of the connection request being queued is also increased, which results in an increase in the time consumed for issuing the packet, that is, the first time T1 is increased; 2) the internal consumption of the performance of the server is large; for example, although the number of connection requests of the terminal to be processed is small, the server still schedules a large number of threads to process the small number of connection requests, the processor of the server needs to schedule the threads, the processor can only execute one thread in one time slice, for example, when the thread a is switched to the thread B, the processor needs to "save the execution site of the thread a" and then "load the execution site of the thread B", this process consumes a large amount of resources of the processor, and the larger the number of threads scheduled by the processor of the server is, the more resources of the processor are consumed; the consumption of switching threads is also: the synchronous cost of the memory, the cost of thread creation and extinction, the scheduling cost and the like; accordingly, the switching process of the thread consumes resources of the server, the efficiency of processing the connection request by the server becomes low, the time consumed for the package increases, and the first time T1 increases. In summary, the load amount of the connection request transmitted by the terminal does not match the number of processing processes of the server, and the first time T1 is increased. When the number of the processing threads of the server is small, taking the current thread working mode as a single thread working mode as an example, the first time T1 is increased, and when the first time threshold is reached, it indicates that the number of the threads in which the server works is too small to cope with an excessively high communication load, and at this time, the number of the threads in which the server works needs to be increased, and the current thread working mode is switched, that is, the single thread working mode is switched to the multi-thread working mode; when the number of the threads working in the server is too many, taking the current thread working mode as a multi-thread working mode as an example, the first time T1 is increased, and when the first time threshold is reached, it indicates that the number of the threads working in the server is too many, and the thread switching overhead is too large, at this time, the number of the threads working in the server needs to be reduced, and the current thread working state is switched, that is, the multi-thread working mode is switched to the single-thread working mode. By changing the number of working threads in the server, the communication load of the server can be matched with the number of working threads, so that the server can efficiently process the connection request sent by the terminal, and further the communication between the terminal of the Internet of things and the server is more efficient.
The multi-thread operation mode in this embodiment includes a multi-thread operation mode of 2 threads or more. Further, in an alternative embodiment, the multi-thread operating modes include a first multi-thread operating mode, a second multi-thread operating mode, a third multi-thread operating mode and a fourth multi-thread operating mode. If the maximum thread number configured by the server is N, the number of threads scheduled in the first multi-thread working mode is N/4, the number of threads scheduled in the second multi-thread working mode is N/2, the number of threads scheduled in the third multi-thread working mode is 3N/4, and the number of threads scheduled in the fourth multi-thread working mode is N. Correspondingly, the communication load is extremely small, or the number of communication requests of the terminals is extremely small, even when only one terminal sends a communication request, the server is switched to a single-thread working mode, namely the current thread working mode of the server is the single-thread working mode; with the gradual increase of the communication load, the current thread working mode can be switched to the first multithreading working mode, the second multithreading working mode, the third multithreading working mode or the fourth multithreading working mode.
The multithreading mode is further subdivided, and in an alternative embodiment, each of the operation modes with different thread numbers is a multithreading mode, that is, the multithreading mode includes a 2-thread operation mode, a 3-thread operation mode, a 4-thread operation mode … … N-1 thread operation mode and an N-thread operation mode (the total number of threads of the server is N). For a specific communication load, the server can only work in the working mode with the optimal thread number to ensure that the communication system is in the most efficient communication state. As shown in fig. 2, when the communication load is extremely small, that is, the single-thread operating mode can meet the communication requirement, as the number of threads operating in the server increases, thread switching consumption in the server increases, and the operating efficiency of the communication system gradually decreases instead; as shown in fig. 3, when the communication load is at the maximum value that can be accommodated by the communication system, as the number of threads operating in the server increases, the number of connection requests waiting in queue decreases, and the operating efficiency of the communication system gradually increases; as shown in fig. 4, when the communication load is between the maximum communication amount and the minimum communication amount, as the number of threads operating in the server increases, the number of connection requests that are queued to wait decreases, the communication efficiency of the communication system increases, and when the number of threads reaches a critical value, the thread switching consumption in the server becomes significant, and the communication efficiency of the communication system gradually decreases. Through the rule, the server is switched to the corresponding multithreading working mode according to the communication load, and the communication efficiency of the communication system is guaranteed to be in the optimal state.
The first time threshold value reflects the expected value of the communication efficiency of the communication system, and the smaller the first time threshold value is, the higher the communication efficiency of the communication system is expected to be; the larger the first time threshold, the lower the communication efficiency of the communication system is expected to be. In general, the first time threshold is positively correlated with one communication cycle, which is an average time required for the terminal and the server to complete one communication. It should be noted that, as the communication load in the communication system increases, the optimal communication efficiency of the communication system gradually decreases. That is, as the communication load of the communication system increases, the period required for the terminal and the server to complete one-time communication becomes longer, and therefore, the first time threshold needs to be increased accordingly.
Thread switching consumes server performance, and similarly, switching thread modes of operation consumes a significant amount of server performance: switching the thread operating mode means that the total number of threads changes, including a large number of creating thread processes or terminating thread processes. In order to avoid unnecessary switching of the thread operating modes of the server, in an alternative embodiment, after the first time T1 reaches the first time threshold and before switching the current thread operating mode, the method further includes: judging whether the duration time of the current thread working mode reaches a second time threshold value or not; if the first time T1 reaches the first time threshold and the duration of the current thread operating mode has reached the second time threshold, then the current thread operating mode is switched. If the duration of the current thread working mode is less than the second time threshold, the thread working mode is switched again, the interval time between the previous thread working mode switching and the current thread working mode switching is too short, the thread working mode switching is too frequent, a large amount of resources of the server are continuously consumed, the connection request sent by the server processing terminal is delayed, and the communication efficiency of the communication system is reduced. Therefore, after the duration time of the current thread working mode reaches the second time threshold, the current thread working mode is switched, so that the influence of switching the current working mode on the communication efficiency is reduced. The switching of the current thread working mode in this embodiment means that, if the current thread working mode is a single thread working mode, the single thread working mode is switched to a multi-thread working mode; and if the current thread working mode is the multi-thread working mode, switching the multi-thread working mode to the single-thread working mode.
In an alternative embodiment, the second time threshold is a time required for the communication efficiency to reach a steady state after the thread operating mode is switched. After the thread working mode is switched, the capability of the server for processing the communication load changes, that is, the communication efficiency of the communication system at this time changes, and it is the first time T1 that reflects the communication efficiency, and in order to improve accuracy, it is preferable that the first time T1 is an average value required by the server for processing the connection request, so when the thread working mode is switched, the first time T1 obtained immediately after the thread working mode is switched is affected by the previous thread working mode and is inaccurate, and if the thread working mode is switched according to the first time T1 at this time, not only the communication efficiency is affected, but also the accurate thread working mode cannot be switched, and it is not guaranteed that the communication of the communication system is in the most efficient state. Therefore, when the duration of the thread working mode reaches the second time threshold, namely the communication efficiency of the communication system becomes stable, the thread working mode is switched, so that the accurate thread working mode can be switched, and the highest communication efficiency of the communication system is ensured.
In an alternative embodiment, as shown in fig. 5, the obtaining of the first time T1 required by the server to process the connection request specifically includes:
s501, recording a time point t1 when a connection request sent by a terminal reaches a server;
s502, the selector reads the connection request and distributes a thread for processing the connection request;
s503, reading and processing the connection request by the thread;
s504, recording a time point t 1' when the thread processing connection request is completed;
s505, the first time T1, T1 ═ T1' -T1.
In an optional embodiment, the method for implementing communication of the internet of things in Java (object oriented programming language) language includes:
a Selector which can concurrently process a plurality of Socket (which are used for describing IP addresses and ports, are handles of a communication chain and can be used for realizing communication between a server and a terminal) connection read-write requests;
EventLoop, thread event handler;
as shown in fig. 6, the first time T1 required by the server to process the connection request is specifically:
s601, recording a time point t1 when a connection request sent by a terminal reaches a server;
s602, triggering a Selector to read a message;
s603, triggering a message reading operation by EventLoop;
s604, completing the operation of the EventLoop execution message and recording a time point t 1';
s605, a first time T1, T1 ═ T1' -T1.
As shown in fig. 7, after considering the second time threshold, the process of switching the thread operating mode specifically includes:
s701, initializing a thread working mode;
s702, recording a time point t1 when a connection request sent by a terminal reaches a server;
s703, reading the connection request by the selector and distributing a thread for processing the connection request;
s704, reading and processing the connection request by the thread;
s705, recording the time point when the thread processing connection request is finished;
s706, updating the total consumed time and the total number of the processed connection requests;
s707, calculating the average time required by processing the primary connection request to obtain a first time T1;
to obtain the accurate first time T1, the time for the thread to process the connection request is averaged, and the total time consumed is divided by the total number of the connection requests to obtain the first time T1;
s708, judging whether the first time T1 reaches a first time threshold, if so, executing a step S709, otherwise, executing a step S702;
s709, obtaining the duration of the current thread working mode: a second time T2;
if the server processes the connection request for the first time and the thread working mode is not switched yet, the current thread working mode is a thread working mode preset by the server, which can be a single thread working mode or a multi-thread working mode, and at this time, T2 is equal to 0;
s710, determining whether the second time T2 reaches a second time threshold, if yes, performing step S711, otherwise, performing step S708;
s711, switching the working mode of the current thread;
s712, total reset time, total number of connection requests, and a second time T2.
As shown in fig. 8, the above-mentioned flow is implemented in Java language, specifically:
s801, initializing a thread working mode;
s802, recording the time point when the connection request sent by the terminal reaches the server;
s803, triggering a Selector to read the message;
s804, triggering and reading message operation by EventLoop;
s805, completing the operation of the EventLoop execution message and recording a time point;
s806, updating the total consumed time and the total number of the processed connection requests;
s807, calculating the average time required by processing the primary connection request to obtain a first time T1;
s808, judging whether the first time T1 reaches a first time threshold value, if so, executing a step S809, otherwise, executing a step S802;
s809, acquiring the duration of the current thread working mode: a second time T2;
if the server processes the connection request for the first time and the current thread working mode is not switched yet, the current thread working mode is a thread working mode preset by the server, which can be a single thread working mode or a multi-thread working mode, and at this time, T2 is equal to 0;
s810, determining whether the second time T2 reaches a second time threshold, if yes, performing step S811, otherwise, performing step S808;
s811, switching the working mode of the current thread;
s812, total time consumed for reset, total number of connection requests, and a second time T2.
The thread operating mode is initialized in step S701 or step S801, including setting the number of threads, the first time threshold, and the second time threshold. When the thread working mode only has a single thread working mode and a multi-thread working mode, the set thread number is the number of threads scheduled in the multi-thread working mode; when the thread working modes comprise a single thread working mode, a first multithreading working mode, a second multithreading working mode, a third multithreading working mode and a fourth multithreading working mode, the initialization thread working mode comprises the steps of setting a scheduled thread number I, a first time threshold value I and a second time threshold value I for the first multithreading working mode, setting a scheduled thread number II, a first time threshold value II and a second time threshold value II for the second multithreading working mode, setting a scheduled thread number III, a first time threshold value III and a second time threshold value III for the third multithreading working mode, and setting a scheduled thread number IV, a first time threshold value IV and a second time threshold value IV for the fourth multithreading working mode; when each working mode with different thread numbers in the server is a multi-thread working mode, setting the corresponding scheduled thread number, the corresponding first time threshold and the corresponding second time threshold for each multi-thread working mode.
As shown in fig. 9, in an alternative embodiment, the initialization process of the communication system is implemented by Java, which specifically includes:
s901, starting an Accept initializer by a server EventLoop main thread, and starting the initialization work;
s902, establishing a new Selector receiver;
s903, registering an Accept event to a Selector receiver;
s904, setting related connection parameters;
s905, initializing the related parameters of the EventLoop thread to complete initialization operation;
the relevant parameters initialized in this step include: the number of threads to be scheduled, a first time threshold, a second time threshold and the like;
s906, the EventLoop thread receives the time trigger of Accept of the Selector.
In step S901 and step S906, EventLoop is an event handler individually set for Accept, and the event handler is initially operated in a single thread and is only responsible for receiving a connection request of a terminal.
The initialized server can complete a terminal access process and a terminal data receiving process, when the terminal is accessed, a connection request sent by the terminal is specifically an access request, a thread reads and processes the access request, and specifically the following steps are sequentially executed: and reading the access request by the thread, setting a configuration file for the access request by the thread, and receiving the access request by the thread.
As shown in fig. 10, the terminal access procedure specifically includes:
s1001, initializing a thread working mode;
s1002, a terminal initiates an access request;
the sequence of step S1001 and step S1002 is not limited to this, and optionally, the terminal initiates a connection request first, and the server initializes a thread working mode; step S1002 is executed first, and then step S1001 is executed;
s1003, recording the time point when the access request sent by the terminal reaches the server;
the receiving of the access request in this step only means that the server receives the access request of the terminal, and there is no limitation as to whether the server allows the terminal to access; if the server allows the terminal to access, the following steps are carried out;
s1004, reading the access request by the selector and distributing a thread for processing the access request;
s1005, reading an access request by a thread;
s1006, setting a configuration file for the access request by the thread;
in the step, the server prepares for terminal access;
s1007, the thread receives the access request;
s1008, recording the time when the thread processes the access request;
s1009, updating the total consumed time and the total number of processed access requests;
s1010, calculating the average time required by processing the primary access request to obtain a first time T1;
s1011, determining whether the first time T1 reaches a first time threshold, if yes, performing step S1012, otherwise, performing step S1002;
s1012, acquiring the duration of the current thread working mode: a second time T2;
s1013, determining whether the second time T2 reaches the second time threshold, if yes, performing step S1014, otherwise, performing step S1011;
s1014, switching the working mode of the current thread;
s1015, reset total time, total number of access requests and second time T2, execute step S1001.
As shown in fig. 11, in an alternative embodiment, the terminal access procedure is implemented by Java, specifically:
s1101, initializing a thread working mode;
s1102, the terminal initiates an access request;
the sequence of the step S1101 and the step S1102 is not limited to this, and optionally, the terminal initiates the connection request first, and the server initializes the thread working mode; step S1102 is executed first, and then step S1101 is executed;
s1103, recording the time point when the access request sent by the terminal reaches the server;
the receiving of the access request in this step only means that the server receives the access request of the terminal, and there is no limitation as to whether the server allows the terminal to access; if the terminal is allowed to access, executing the following steps;
s1104, executing a Selector by EventLoop;
s1105, triggering Accept event of Selector;
in the step, the server is ready for terminal access;
s1106, the server receives the access request;
s1107, recording the time point after the server receives the access request;
s1108, updating the total consumed time and the total number of the processed access requests;
s1109, calculating the average time required by processing the primary access request to obtain a first time T1;
s1110, judging whether the first time T1 reaches a first time threshold, if so, executing the step S1111, otherwise, executing the step S1102;
s1111, acquiring the duration of the current thread working mode: a second time T2;
s1112, determining whether the second time T2 reaches a second time threshold, if yes, performing step S1113, otherwise, performing step S1110;
s1113, switching the working mode of the current thread;
in this step, if the current thread working mode is switched, the incomplete operation of the replaced thread working mode is processed in the new thread working mode; if the current thread working mode is not switched, the current thread working mode is continuously used for completing subsequent operation;
s1114, reset total elapsed time, total number of access requests, and a second time T2, step S1101 is executed.
When the server receives the terminal data, the thread reads and processes the connection request, and specifically, the following steps are sequentially executed: and reading the connection request by the thread, allowing the terminal to perform read-write operation in the server by the thread, and receiving the data sent by the terminal by the thread.
As shown in fig. 12, the flow of the server receiving data is specifically as follows:
s1201, initializing a thread working mode;
s1202, recording a time point when a connection request sent by a terminal reaches a server;
s1203, reading the connection request by a selector and distributing a thread for processing the connection request;
s1204, reading a connection request by a thread;
s1205, allowing the terminal to perform read-write operation in the server by the thread;
s1206, receiving data sent by the terminal by the thread;
s1207, recording the time when the thread receives the data;
s1208, updating the total consumed time and the total number of the processed connection requests;
s1209, calculating the average time required by processing the primary connection request to obtain a first time T1;
s1210, determining whether the first time T1 reaches a first time threshold, if yes, performing step S1211, otherwise, performing step S1202;
s1211, obtaining the duration time of the current thread working mode: a second time T2;
s1212, determining whether the second time T2 reaches a second time threshold, if yes, performing step S1213, otherwise, performing step S1210;
s1213, switching the working mode of the current thread;
s1214, resetting the total consumed time, the total number of connection requests and a second time T2;
in the above flow, operations performed by the server are mainly performed, wherein some of the operations correspond to operations of the terminal, such as: before the server receives the connection request, the terminal initiates the connection request; when receiving the data sent by the terminal, the terminal sends the data at the same time.
As shown in fig. 13, in an alternative embodiment, the data flow of the receiving terminal is implemented by Java, specifically:
s1301, initializing a thread working mode;
s1302, recording a time point when a connection request sent by a terminal reaches a server;
s1303, a Selector registers a read-write event for the terminal;
s1304, executing Selector read-write operation by EventLoop;
s1305, receiving data sent by a terminal;
s1306, recording the time point after the data sent by the receiving terminal is finished;
s1307, updating the total consumed time and the total number of the processed connection requests;
s1308, calculating the average time required by processing the primary connection request to acquire a first time T1;
s1309, determining whether the first time T1 reaches a first time threshold, if yes, performing step S1310, otherwise, performing step S1302;
s1310, obtaining the duration of the current thread working mode: a second time T2;
s1311, determining whether the second time T2 reaches a second time threshold, if yes, performing step S1312, otherwise, performing step S1309;
s1312, switching the working mode of the current thread;
s1313, resetting total consumed time, connecting request total and second time T2;
in the above flow, operations performed by the server are mainly performed, wherein some of the operations correspond to operations of the terminal, such as: before the server receives the connection request, the terminal is required to initiate the connection request; when receiving data transmitted by a terminal, the terminal is required to transmit data at the same time. And if the current thread working mode is switched, starting a new EventLoop to execute the subsequent processing operation, otherwise, executing the subsequent processing operation by using the EventLoop in the current thread working mode.
In a second aspect of the embodiments of the present invention, there is provided an internet of things communication server, including: the device comprises a first time acquisition module, a judgment module and a switching module; the first time acquisition module is used for acquiring first time required by the server for processing the connection request sent by the terminal in the current working mode; the judging module is used for judging whether the first time reaches a first time threshold value or not, and if the first time reaches the first time threshold value, the switching module is started; and the switching module is used for switching the current thread working mode of the server.
The first time reflects the communication efficiency between the server and the terminal, that is, reflects the communication efficiency of the communication system: if the first time is larger, the communication efficiency is lower; if the first time is shorter, the communication efficiency is higher. If the current thread working mode of the server is a single thread working mode, starting a switching module, and switching the server from the single thread working mode to a multi-thread working mode; if the current thread working mode of the server is a multi-thread working mode, starting a switching module, and switching the multi-thread working mode of the server to a single-thread working mode.
The communication server can flexibly switch between a single-thread working mode and a multi-thread working mode according to the communication load of the terminal, improves the capacity of the server for processing the connection request, and enables the communication between the server and the terminal to be more efficient.
In an optional embodiment, the determining module is further configured to determine whether a duration of the current thread working mode reaches a second time threshold; and if the first time reaches a first time threshold value and the duration of the current thread working mode reaches a second time threshold value, starting the switching module.
In an optional embodiment, the system further comprises an initialization module, where the initialization module is configured to set the number of threads, the first time threshold, and the second time threshold.
In an optional embodiment, the system further comprises a terminal access module and a data receiving module; the terminal access module is used for receiving an access request of a terminal; the data receiving module is used for receiving data sent by the terminal; the first time acquisition module in the server is used for acquiring the first time required by the server to operate the terminal access module once in the current working mode when the terminal access module operates; when the data receiving module runs, the method is used for acquiring the first time required by the server to run the data receiving module once in the current working mode.
In a third aspect of the embodiments of the present invention, an internet of things communication system is provided, which includes a server, where the server is the server provided in the second aspect of the present invention.
It is to be understood that the present invention is not limited to the procedures and structures described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the invention is limited only by the appended claims.

Claims (9)

1. The Internet of things communication method is applied to a server and comprises the following steps:
initializing a thread working mode; the initializing thread working mode comprises setting a first time threshold;
acquiring a first time T1 required for processing a connection request sent by a terminal in a current thread working mode; the obtaining mode of the first time T1 includes: averaging the time of processing the connection requests by the threads, and dividing the total time consumption by the total number of the connection requests to obtain the first time T1, wherein the first time T1 reflects the time consumption of package sending between the terminal and the server;
judging whether the first time T1 reaches the first time threshold, and if the first time T1 reaches the first time threshold, switching the current thread working mode;
the obtaining of the first time T1 required for processing the connection request sent by the terminal in the current thread working mode specifically includes: recording a time point t1 when the connection request sent by the terminal reaches the server; a selector reads the connection request and distributes a thread for processing the connection request; the thread reads and processes the connection request; recording the time t 1' when the thread finishes processing the connection request; the first time T1, T1= T1' -T1.
2. The communication method of the internet of things of claim 1, wherein after the first time T1 reaches the first time threshold and before the switching of the current thread operating mode, the method further comprises:
judging whether the duration time of the current thread working mode reaches a second time threshold value;
and if the duration time of the current thread working mode reaches the second time threshold, switching the current thread working mode.
3. The communication method for the internet of things according to claim 2, wherein the initializing the thread working mode further comprises setting a thread number and the second time threshold.
4. The internet of things communication method of claim 1, wherein when a terminal accesses, the thread reads and processes the connection request, specifically:
the connection request sent by the terminal is specifically an access request;
the thread reads the access request;
the thread sets a configuration file for the access request;
the thread accepts the access request;
when receiving terminal data, the thread reads and processes the connection request, specifically:
the thread reads the connection request;
the thread allows the terminal to perform read-write operation in the server;
and the thread receives data sent by the terminal.
5. An internet of things communication server, comprising: the device comprises an initialization module, a first time acquisition module, a judgment module and a switching module;
the initialization module is used for setting a first time threshold;
the first time acquisition module is used for acquiring first time required by the server for processing the connection request sent by the terminal in the current working mode; the first time obtaining mode comprises the following steps: averaging the time of processing the connection request by the thread, and dividing the total time consumption by the total number of the connection requests to obtain the first time, wherein the first time reflects the time consumed by package sending between the terminal and the server;
the judging module is used for judging whether the first time reaches the first time threshold value, and if the first time reaches the first time threshold value, the switching module is started;
the switching module is used for switching the current thread working mode of the server;
the obtaining of the first time T1 required for processing the connection request sent by the terminal in the current thread working mode specifically includes: recording a time point t1 when the connection request sent by the terminal reaches the server; a selector reads the connection request and distributes a thread for processing the connection request; the thread reads and processes the connection request; recording the time t 1' when the thread finishes processing the connection request; the first time T1, T1= T1' -T1.
6. The internet of things communication server of claim 5, wherein the determining module is further configured to determine whether the duration of the current thread operating mode reaches a second time threshold; and if the first time reaches the first time threshold value and the duration of the current thread working mode reaches the second time threshold value, starting the switching module.
7. The internet-of-things communication server of claim 6, wherein the initialization module is further configured to set a number of threads and the second time threshold.
8. The internet-of-things communication server according to any one of claims 5 to 7, further comprising a terminal access module and a data receiving module;
the terminal access module is used for receiving an access request of a terminal;
the data receiving module is used for receiving data sent by the terminal;
the first time acquisition module is used for acquiring first time required by the terminal access module when the terminal access module operates in the current working mode; and when the data receiving module runs, the data receiving module is used for acquiring the first time required by the server to run the data receiving module once in the current working mode.
9. An internet of things communication system comprising a server, wherein the server is the server according to any one of claims 5 to 8.
CN201810028886.9A 2018-01-12 2018-01-12 Internet of things communication method, server and system Active CN108337295B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810028886.9A CN108337295B (en) 2018-01-12 2018-01-12 Internet of things communication method, server and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810028886.9A CN108337295B (en) 2018-01-12 2018-01-12 Internet of things communication method, server and system

Publications (2)

Publication Number Publication Date
CN108337295A CN108337295A (en) 2018-07-27
CN108337295B true CN108337295B (en) 2022-09-23

Family

ID=62924267

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810028886.9A Active CN108337295B (en) 2018-01-12 2018-01-12 Internet of things communication method, server and system

Country Status (1)

Country Link
CN (1) CN108337295B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114338756B (en) * 2021-11-11 2024-03-08 北京蜂云科创信息技术有限公司 Method and system for intelligent network high concurrency communication of commercial vehicle

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1540508A (en) * 2003-04-24 2004-10-27 �Ҵ���˾ Dynamic switching of multiline range processor between single line range and complicated multiline range mode
CN101681260A (en) * 2007-06-20 2010-03-24 富士通株式会社 Arithmetic unit
CN106371976A (en) * 2016-08-31 2017-02-01 福建天晴数码有限公司 Method and system for monitoring thread by client and Web server

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6931641B1 (en) * 2000-04-04 2005-08-16 International Business Machines Corporation Controller for multiple instruction thread processors

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1540508A (en) * 2003-04-24 2004-10-27 �Ҵ���˾ Dynamic switching of multiline range processor between single line range and complicated multiline range mode
CN101681260A (en) * 2007-06-20 2010-03-24 富士通株式会社 Arithmetic unit
CN106371976A (en) * 2016-08-31 2017-02-01 福建天晴数码有限公司 Method and system for monitoring thread by client and Web server

Also Published As

Publication number Publication date
CN108337295A (en) 2018-07-27

Similar Documents

Publication Publication Date Title
US9703595B2 (en) Multi-core system with central transaction control
KR102327616B1 (en) Sequence dependent data message consolidation in a voice activated computer network environment
EP1164512A2 (en) Data acquisition apparatus and method
US20090327495A1 (en) Computing with local and remote resources using automated optimization
CN111221662B (en) Task scheduling method, system and device
CN103095691A (en) Method of controlling access to Internet of things nodes
CN103765387A (en) Distributed resource management in a portable computing device
CN105893320B (en) A kind of remote task function calling method of multi-core processor oriented
CN109766194B (en) Method and system for realizing low-coupling plan task component based on message
CN109358805B (en) Data caching method
CN110196761A (en) Delay task processing method and processing device
CN106095593B (en) A kind of forward and backward scape application behavior synchronous method and device
CN108337295B (en) Internet of things communication method, server and system
US20190243908A1 (en) Storage server and adaptive prefetching method performed by storage server in distributed file system
KR102127591B1 (en) Method and apparatus for event-based synchronous communication in asynchronous communication framework
CN109104326A (en) Timeout treatment method and device and electronic equipment
JP2010211642A (en) Workflow processing system, workflow processor, and workflow processing method
CN106936911B (en) Lightweight distributed computing platform and computing resource management and control method thereof
CN110445874A (en) A kind of conversation processing method, device, equipment and storage medium
CN113014981A (en) Video playing method and device, electronic equipment and readable storage medium
CN115469991A (en) Timer queue setting method, device and equipment and readable storage medium
CN108337285B (en) Communication system and communication method
JP2023005205A (en) Information processing device, terminal device, information processing system, information processing method, and program
JP5459393B2 (en) Multi-core processor system, control program, and control method
JP2018068052A (en) Device, method and program for power storage management

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
CB03 Change of inventor or designer information

Inventor after: Zhang Baoxin

Inventor before: Zhang Baoxin

CB03 Change of inventor or designer information