Skip to content

bushed/NettyServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NettyServer

Small HTTP server with DB. This is a test job.

How to build

You should use Apache Ant to build project. Build.xml placed in /ant.
You can just run ant in this directory to build and run project - or - see command list:

  • ant compile -- To compile only.
  • ant build.jar -- To compile and create a jar-file.
  • ant or ant run -- compile, build jar and run the program with default settings. Notice that folder /build will be overwritten.
    Edit default settings right in build.xml. Default settings for ant build project:
  • [Port = 3000] - See line <property name="port" value="3000"/>

To build project without Ant
Summary:

  • JRE1.6
  • libraries: ../lib/*.jar
  • sources: ../src/nettyserver
  • Main-class: nettyserver/NettyServer
    See Implementation details below.

How to use

To run program without Ant, run it from command line.

java -jar NettyServer.jar [port]

If everything ok, program will type:

Web server started at port 3000
type "stop" to stop server

Default port is 3000. So, to check server, enter to address line in your browser http://localhost:3000/status.
According to the test job features list, there is 3 pages:

  • /status -- shows the statistic page
  • /hello -- after 10 seconds says "Hello page"
  • /redirect?url=<url> -- redirects to the specified in GET request URL.

Implementation details

Project uses Netty framework. Number of threads by default = 2 * Cores.

Project directory tree:

+---ant       
|       build.xml
|
+---benchmark
|       *.txt
|
+---build
|   |   NettyServer.jar
|   +---classes
|   |       *.class    
|   \---localdb
|           *
|
+---lib
|       hsqldb.jar
|       netty-all-4.0.10.Final.jar
|
+---screens
|       *.png;*.jpg
|
\---src
    \---nettyserver
            Database.java
            HttpServerHandler.java
            HttpServerInitializer.java
            ManualDBForm.java
            NettyServer.java
            StatDAO.java
            StatusHolder.java

Folders

  • ant -- contains build script for Apache Ant
  • benchmark -- Apache benchmark results
  • build -- destination folder for build project
  • build/localdb -- will be created automatically
  • lib -- used libraries
  • screens -- screenshots
  • src -- source code

Classes

Main-class: NettyServer

  • NettyServer -- Starts and stops server.
  • Database -- provides access to Database
  • HttpServerInitializer -- specify pipeline factory, means how we will handle connections
  • HttpServerHandler -- Http handler. Accepts http requests and responds to them.
  • ManualDBForm -- Debug tool.
  • StatDAO -- implements methods to work with Database.
  • StatusHolder -- synchronized counter

See JavaDoc for more details.

Database

This project uses embedded HSQL DB. It's fast and thread-safe. Database files placed in folder /localdb in build directory.

To change DBMS edit Database class. Besides see StatDAO class, that contains all SQL code, to use your specific DBMS features.

Database contains only two tables. Connections for each accepted request and URI for storing text strings and aggregated data.

Database diagram

Benchmark

Benchmark result

Benchmark details: CPU: Athlon x64 631 @2.6Ghz 4 Cores. RAM: 8 GB. Max heap size: 512Mb.
Description: Apache benchmark compare the size of each response to the first received. Status page generated dynamically, so obviously there is a lot of failed requests by lengths.

Screens

Status page in browser.
Page status in use

Start server in console.
Start server

About

Small HTTP server with DB. This is a test job.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages