Code Monkey home page Code Monkey logo

libusnet's Introduction

libusnet

libusnet is a light-weight netmap-based network stack [1]. The aim of the library is to provide an easy way for delelopers to build high performance servers with millions of connections. On FreeBSD and Debian box, processing time for sending 60-bytes data to echosvr, written in libusnet, gives smaller amount of time at least 10-30%, compared to echo server, written in FreeBSD networking stack.

We believe that further improvements are still possible, since we could add more network and application processes and take advantages of multi-queue support by network cards. In future, we shall conduct more experiments.

Here are summaries of techniques we have used:

  • wait-free algorithm and data structures which are shared among processes.
  • multi-processes: one network process for packet processing, one application process for application tasks.
  • zero-copy technique: reducing number of copying buffers as mush as we can.
  • use cache-friendly data structure to reduce algorithm costs.
  • design of mTcp.

To use libusnet, one needs netmap to be installed.

FreeBSD instructions: since recent FreeBSD distributions already include netmap, you only need build the new kernel or modules as below:

  • add 'device netmap' to your kernel config file and rebuild a kernel. This will include the netmap module and netmap support in the device drivers. Alternatively, you can build standalone modules (netmap, ixgbe, em, lem, re, igb)

  • sample applications are in the examples/ directory in this archive, or in src/tools/tools/netmap/ in FreeBSD distributions

Linux instructions: on Linux, netmap is an out-of-tree module, so you need to compile it from these sources. The Makefile in the LINUX/ directory will also let you patch device driver sources and build some netmap-enabled device drivers.

  • make sure you have kernel sources matching your installed kernel (headers only suffice, if you want NETMAP/VALE but no drivers)

  • build kernel modules and sample applications: If kernel sources are in /foo//linux-A.B.C/ , then you should do

	cd netmap/LINUX
	//build kernel modules
	make NODRIVERS=1 KSRC=/foo/linux-A.B.C/	# only netmap
	make KSRC=/a/b/c/linux-A.B.C/		# netmap+device drivers
	//build sample applications
	make KSRC=/a/b/c/linux-A.B.C/ apps	# builds sample applications

You can omit KSRC if your kernel sources are in a standard place.

  • if you use distribution packages, source may not contain headers (e.g., on debian systems). Use
        make SRC=/a/b/c/linux-sources-A.B/ KSRC=/a/b/c/linux-headers-A.B/

Libusnet installation instructions:

autoreconf -i
./configure
make
make install

Sample application:

epollfd = usnet_epoll_create(ctx,10);

while (1) {

   nfds = usnet_epoll_wait(ctx,epollfd,events,MAX_EVENTS,5000);
   
   if ( nfds <= 0 ) 
      continue;
   
   for (n = 0; n < nfds; ++n) {
      if (events[n].data.fd == fd) {
          conn_sock = usnet_accept(ctx, fd, (struct sockaddr *) &local, &addrlen);
          if (conn_sock < 0) 
             exit(-1);
          ev.events = USN_EPOLLIN | USN_EPOLLET;
          ev.data.fd = conn_sock;
          if (usnet_epoll_ctl(ctx,epollfd, USN_EPOLL_CTL_ADD, conn_sock, &ev) == -1) {
              exit(-1);
          }
      } else {
          handle_fd(ctx,events[n].data.fd);
      }
   }
}

For more details, see example at https://github.com/jackiedinh8/libusnet/blob/master/src/sample/echosvr.c

[1] https://code.google.com/p/netmap

libusnet's People

Contributors

jackiedinh38 avatar dungdv avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.