You are on page 1of 4

2013 10th IEEE International Conference on Control and Automation (ICCA)

Hangzhou, China, June 12-14, 2013

Server Structure Based on Netty Framework for Internet-based


Laboratory
Shouheng Zhang, Shanan Zhu

Abstract—This paper describes a server structure based on


Netty for an internet-based laboratory. It contains 3 subsystems:
the configuration, the user and the experiment, with universal
Video
Video Server
Server
modules. The system has a special communication protocol User
User 11

based on TCP/IP. Because of the excellent scalability, the server


can be expended into an integrative system for both virtual and Circuit
Experiment
experimentss.
physical experiment Internet
Internet
Web
Web Server
Server
User
User 22

Keywords—Internet-based laboratory
Keywords— laboratory,, server structure, Netty ···
Pendulum
Experiment
framework A
Application
pplication
SServer
erver ···

Motor
I. INTRODUCTION UU ser
ser nn Experiment

With the development of information and internet


technology, Internet-based distant education is developed Database
Database Server
Server

rapidly[1][2]. Because of the limitation of traditional


laboratory such as time, space and cost, the openness and Figure 1. Internet-based laboratory architecture
offsite sharing of distant laboratory become more important. It
allows users to do the experiments on the internet anytime and A. Client side
anywhere[3]. In Network Laboratory of Zhejiang University The client mainly contains Flash plug-ins developed by
(NetLab), we have developed an internet-based experiment Flex embedded in web. We take this way to implement the
system which can provide both virtual simulation and physical client in order to let users to complete the whole experiments
experiments. It enhances the effects of the electric and including building circuits, simulation and getting the results
electronic distant education by providing students the of physical experiment through the browser instead of down-
principle emulation contrasted with the physical experiments. loading and running any programs[4].
Based on the B/S/C architecture and Flash technology, users
can login the experimental system through a browser and do B. Server side
the experiments. Users can also get the physical experiment
results only if correspondingly the experiment has the It contains video server, Web server, application server
hardware devices. and data server. The video server aims to transmit the real
experiment running scenes, to make users feel like personally
This paper aims to design the experimental server that is on the scene. The Web server mainly bears web resources
based on Netty framework combined with multi-threads, including Web pages, experimental plug-ins and data
database programming and so on. exchange layer. And the application server is the key session
of the whole server system. It is responsible for accepting
II.ARCHITECTURE OF INTERNET-BASED LABORATORY users’ connections and requests, building the communication
between client and experiment side, transmitting the data in
Internet-based laboratory consists of 3 parts: client side,
order to help the system realize the function. The data server
server side and experiment side. The Internet-based laboratory
mainly stores and manages user information, experiment
architecture is shown in Fig.1.
information and data when users do experiments.

C. Experiment side
Experiment side is needed when users want to do physical
experiments. Experiment side mainly aims to control physical
devices and communicates with server[5]. Since the
differences of devices, every experiment has its own control
terminal. A standard to unify the control terminals is created
with two parts: the monitoring module and the control module.
Shouheng Zhang is with Zhejiang University, Hangzhou, 310027 China
(e-mail: zhangshouhengdtc@ 163.com).
The monitoring module monitors the device state and the
Shanan Zhu is with the Electrical and Electronics Engineering internet state and the control module accepts the requests and
Department, Zhejiang University, Hangzhou, 310027 China. (corresponding transmits real time data.
author to provide phone :e-mail: zsa@zju.edu.cn).

978-1-4673-4708-2/13/$31.00 ©2013 IEEE 538


III. SERVER STRUCTURE BASED ON NETTY U ser L ogin

There are 4 parts in the server: configuration subsystem,


user server subsystem, experiment server subsystem and N Return
Check Y
experiment
universal module. The data flow of the server is shown in authority lis t
Fig.2. Y

Client Side
Receive next Notify user end the
com m and experiment

Request N Notify user N


User Server Subsystem
experiment request first Receive next
E n d ed
Y com m and Y
A PI Notify user
R equested Y
not repeated
DatabaseHandler

N
ThreadPool

Server N
S id e
Mail

Configuration
Log

Request Start N End


Subsy stem
experiment experiment experiment
Y Notify user Y
start first
R equested
Receive next
Experiment Server Subsystem com m and

Start End
experiment experiment
Experiment Side
Figure 3. User server subsystem workflow
Figure 2. Data flow of the server Netty is an asynchronous, event-driven network
framework[6]. Developers can develop perfect server based
A. Configuration subsystem on this framework. In the user server subsystem, the
When the server starts, the configuration subsystem will UserServer class that implements the ServerBootstrap is
read ports and address information of user server subsystem, responsible for binding address and listening to the port, at the
experiment server subsystem and database from a same time, accepting the connections by Boss thread.
configuration file. And then it will start the user server and the The user server subsystem uses non-blocking mode to deal
experiment server according to the information. with connection requests. Contrasted with blocking mode, in
non-blocking mode, the Boss thread will give the request to a
B. User server subsystem and experiment server subsystem selector[7] as soon as it receives a connection request, while
The user server subsystem and the experiment server its own accept() function returns immediately. The advantage
subsystem are the most important parts. The function of the of this mode is that the Boss thread can accept connections
user server subsystem is to accept users’ connections and deal continuously without waiting for the accept() function
with the users experimental requests. It will respond to the returning. And this improves the efficiency of dealing with
requests such as “Login the experiment”, “Request the requests.
experiment”, “Start the experiment”, “Logout the experiment” According to Netty Framework, after Boss thread accepts
and so on. It makes a thread for each legitimate user, and then a connection, the server will start Worker thread. Worker
resolves the user’s command according to our own protocol, thread when it receives the channel from Boss thread, will do
and communicates with experiment server subsystem to the reading and writing operation, trigger corresponding event
transmit the experimental requests. The function of the and pass the data to the pipline to process. In the experiment
experiment server subsystem is to accept the experiment side server subsystem, UserServerPiplineFactory class provides
connections, and it also makes a thread for each registered the methods of processing requests and the data. Especially,
experiment and resolves the control commands. When it handler processes the logical business, for example, user side
receives the experimental requests, it arranges the hardware connection and returning experiment state to users.
devices to meet the users’ requests and then returns the results
to the users. Another advantage of Netty framework is that it has good
package buffer classes. The experiment server subsystem uses
The user server subsystem and the experiment server ChannelBuffer as buffer to receive and send data. Contrasted
subsystem have similar workflow. Both of them are designed with traditional ByteBuffer, ChannelBuffer separates the
based on Netty framework. In the following, the paper reader pointer and the writer pointer, avoiding the flip
interprets the user server subsystem as an example. The operation in traditional buffer and reducing the difficulties of
workflow of user server subsystem is shown in Fig.3. the development, enhancing the program robustness and
bringing convenience to program maintainance.

539
User server Experiment server When the time is up, the thread pool will get the thread
su b system su b system back.
Start
Get the
� Log module: It is built by Log4j. We can monitor the
Get experiment server, find and solve the problems according to the
Notify
experiment thread
experiment
log.
user wanted
reinitialize

N Experiment D. Communication
Get the request N
O nline
nline??
queue The communication between 3 parts is our own protocol
Y
Notify user based on TCP/IP. The form of the data package is shown in
Notify
this
experiment
Y Fig.5. It includes 4 bytes to record the length of the data, 1 byte
experiment
offline server user do to indicate the type of the service, 4 bytes to express the
The user already Y
th is
in the queue
number of the commands, n bytes to represent the experiment
Notify user
data and 4 bytes to record the end of the data package.
N
success
Command
Notify user Add the user in L ength (4 bytes ) T ype
ype((1 b y te ) D a ta (n bytes ) E n dd((4 bytes
bytes))
Notify user numbers((4 bytes )
numbers
no repeat to the queue registered
request
Figure 5. The form of data package of protocol
Notify user
experiment Although there are 2 experiment modes, the synchronous
false
E nd
mode and the asynchronous mode[8][9], to improve the user
experience, the protocol is the same. The difference is the
Figure 4. User request experiment workflow Type data.
When experiment server subsystem accepts a connection, Since the hole physical experiment uses B/S/C mode, the
it will make a thread for the experiment, and then put it in hash client plug-ins is built by Flex, the server side is built by Java,
map with its experiment ID, as well as inserting “Online” state and the experiment side is built by C++, every part of the
in database. This is the key step to realize the communication system utilizes different storage mode. The client side and the
between the user server subsystem and the experiment server server side use big-endian and the experiment side uses little-
subsystem. Client inquires database continuously in order to endian. Considered the key position of the server, the strategy
get the state of each experiment device. And users can select of coordination is: if the package is transmitted to the server, it
one of the online experiments according to the returning will be organized by big-endian wherever it comes from, as
information to do the experiment. As soon as the user server well as the data package length is built by big-endian [10].
subsystem receives “Request the experiment” command, it
inquires the experiment hash map in order to get the right IV. SERVER INSTANCE AND PERFORMANCE ANALYSIS
experiment thread and add this request into the request queue
Internet-based experiment server relies on IBM good
of this experiment waiting for running. And then it must
performance server(Model:x3850X5E7-4850). It mainly
update the experiments list in the client. When it is the turn of
contains 4-core CPU(2.0GHz, 24MB Cache), 4G Memory,
this user, the user will get the control of the experiment
200G Hard Disk, Dual Gigabit Ethernet card. Besides, Raid 5
devices, and click on “Start the experiment” to do the
disk array technology is used to significantly improve data
experiment. This workflow is shown in Fig.4.
security. Fig.6 is the example of user login and the experiment
scene.
C. Universal modules
These universal modules serve all subsystems of the
experiment server. It includes database module, mail module,
thread pool module and log module.
� Database module: This module is necessary since the
server has to exam the users’ validity, get scheduled
requests and store or get the experimental data. This
module is used to connect database and communicate
with it. It uses JDBC to build.
� Mail module: It is responsible for sending the results of
the asynchronous experiment. It is built by mail
package in javax.
Figure 6. User login and experiment scene
� Thread pool module: In order to improve the threads
Internet-based server seperates the user server subsystem
efficiency, descend the cost when start or destroy a
and the experiment server subsystem. By listeng to different
thread, we use Netty thread pool. And we set the
ports and dealing with requests, it avoids the interaction
minimum number of the thread pool, which we
between the client side and the experiment side. The system
consider some users or experiments can be timeout.
has its own communication protocol, which makes the server
reject the inlegal data[11]. Also, the system has perfect
540
permission mechanism. That means the foreground plugins
can only access specified ports, at the same time different
users have different operating authority. These measures make
sure of the security of the server, the user data and experiment
data.
Using Netty framework, NIO and non-blocking mode, the
server can process requests fast and efficiently. In the stress
test, the concurrent connections can reach 5,000. Considering
the system bottleneck to be the number of experiment side
devices, and the number of users online simultaneously can
only reach 400, the server current handling capacity has
greatly exceeded the actual needs.

V.CONCLUSION
Since 2005, Netlab has been used for experimental
teaching for students who are majored in electrical and
electronics engineering. And the experiment server has been
used in the Internet-based laboratory since then, and opened to
about 8000 students from 124 learning centers of School of
Distant Education at Zhejiang University.
With the Netlab scalability becomes bigger, the system
will add more functions to improve the user experience, such
as the teaching assistant system including online interaction
between teachers and students, intelligent marking and so on.
This needs higher requirements on the server. The server
structure above can meet this requirement because of its good
scalability. By adding new modules, it can do more jobs while
its performance is affected slightly. Netlab with this
experiment server can meet growing demands of the distant
education of China.

REFERENCES
[1] Finn H, Maxwell M, Calver M.Why does experimentation matter in
teaching ecology[J]. Journal of Biological Education, 2002, 36(4):
158-164.
[2] Magin D, Kanapathipillai S. Engineering students understanding of the
role of experimentation[J]. European Journal of Engineering Education,
2000, 25(4): 351-358.
[3] Qiaoling Zhan. Build of a Internet-based Remote Virtual
Laboratory[J]. Technology Information, 2008(4):86-87
[4] Zhenyin Shi, Shanan Zhu. Internet-based Electrical Engineering
Virtual Lab Based on Modelica[J]. Computer Engineering, 2012,
38(11):287-289
[5] Lei Yan, Shanan Zhu. Internet-based blowing pendulum control
experiment system[J]. Industrial Control Computer, 2005, 18(1):13-14.
[6] Zeyad Tareq Mikhael Haddad. Implementing a TCP Hole Punching
NAT Traversal Solution for P2P Applications Using Netty[D].
University of Stirling, 2010.
[7] Elliote Rusty Harold. Java Network Programming.3rd[M]. USA,
O'Reilly Media Inc, 2004.
[8] Yufeng Hu, Zhihai Sun, Shanan Zhu. Internet-based Electric and
Electronic Experiment System[J]. Education Theory and Practice, 2007,
27(Special Issue):258-260.
[9] J. U. Duncombe, “Infrared navigation—Part I: An assessment of
feasibility (Periodical style),” IEEE Trans. Electron Devices, vol.
ED-11, pp. 34–39, Jan. 1959.
[10] Zhiwei Xu, Design of Server Side of Internet-based Electric and
Electronic Laboratory[D]. Journal of Zhejiang University, 2007.
[11] Hanyang Li. NetLab Server and User Management System
Optimization[D]. Journal of Zhejiang University, 2008

541

You might also like