Giter Club home page Giter Club logo

kcp-go's Introduction

kcp-go

GoDoc Powered MIT licensed Build Status Go Report Card Coverage Statusd

Claude_Shannon

(Claude Elwood Shannon)

Introduction

kcp-go is a Production-Grade Reliable-UDP library for golang.

It provides fast, ordered and error-checked delivery of streams over UDP packets, has been well tested with opensource project kcptun. Millions of devices(from low-end MIPS routers to high-end servers) are running with kcp-go at present, including applications like online games, live broadcasting, file synchronization and network acceleration.

Lastest Release

Features

  1. Optimized for Realtime Multiplayer Games, Audio/Video Streaming.
  2. Compatible with skywind3000's C version with language specific optimizations.
  3. Cache friendly and Memory optimized design in golang.
  4. Compatible with net.Conn and net.Listener, easy to use.
  5. FEC(Forward Error Correction) Support with Reed-Solomon Codes
  6. Packet level encryption support with AES, TEA, 3DES, Blowfish, Cast5, Salsa20, etc. in CFB mode.
  7. O(1) goroutines created for the entire server application, minimized goroutine context switch.

Conventions

Control messages like SYN/FIN/RST in TCP are not defined in KCP, you need some keepalive/heartbeat mechanism in the application-level. A real world example is to use some multiplexing protocol over session, such as smux(with embeded keepalive mechanism), see kcptun for example.

Documentation

For complete documentation, see the associated Godoc.

Specification

Frame Format

+--------------+
| SESSION      |
+--------------+
| KCP(ARQ)     |
+--------------+
| FEC          |
+--------------+
| CRYPTO       |
+--------------+
| UDP(PACKET)  |
+--------------+
| IP           |
+--------------+
| LINK         |
+--------------+
| PHY          |
+--------------+
(LAYER MODEL OF KCP-GO)

Usage

Client: full demo

kcpconn, err := kcp.DialWithOptions("192.168.0.1:10000", nil, 10, 3)

Server: full demo

lis, err := kcp.ListenWithOptions(":10000", nil, 10, 3)

Performance

  Model Name:	MacBook Pro
  Model Identifier:	MacBookPro12,1
  Processor Name:	Intel Core i5
  Processor Speed:	2.7 GHz
  Number of Processors:	1
  Total Number of Cores:	2
  L2 Cache (per Core):	256 KB
  L3 Cache:	3 MB
  Memory:	8 GB
$ go test -run=^$ -bench .
beginning tests, encryption:salsa20, fec:10/3
BenchmarkAES128-4          	  200000	      8455 ns/op	 354.81 MB/s	       0 B/op	       0 allocs/op
BenchmarkAES192-4          	  200000	      9370 ns/op	 320.16 MB/s	       0 B/op	       0 allocs/op
BenchmarkAES256-4          	  200000	     10262 ns/op	 292.32 MB/s	       0 B/op	       0 allocs/op
BenchmarkTEA-4             	  100000	     18747 ns/op	 160.02 MB/s	       0 B/op	       0 allocs/op
BenchmarkXOR-4             	 5000000	       319 ns/op	9379.21 MB/s	       0 B/op	       0 allocs/op
BenchmarkBlowfish-4        	   50000	     35845 ns/op	  83.69 MB/s	       0 B/op	       0 allocs/op
BenchmarkNone-4            	30000000	        58.5 ns/op	51252.66 MB/s	       0 B/op	       0 allocs/op
BenchmarkCast5-4           	   30000	     46058 ns/op	  65.14 MB/s	       0 B/op	       0 allocs/op
Benchmark3DES-4            	    2000	    650290 ns/op	   4.61 MB/s	       6 B/op	       0 allocs/op
BenchmarkTwofish-4         	   30000	     44042 ns/op	  68.12 MB/s	       0 B/op	       0 allocs/op
BenchmarkXTEA-4            	   30000	     59862 ns/op	  50.11 MB/s	       0 B/op	       0 allocs/op
BenchmarkSalsa20-4         	  300000	      4045 ns/op	 741.50 MB/s	       0 B/op	       0 allocs/op
BenchmarkEchoSpeed4K-4     	    5000	    286664 ns/op	  14.29 MB/s	    5534 B/op	     174 allocs/op
BenchmarkEchoSpeed64K-4    	     500	   3026142 ns/op	  21.66 MB/s	   69494 B/op	    2132 allocs/op
BenchmarkEchoSpeed512K-4   	      50	  26078786 ns/op	  20.10 MB/s	  630231 B/op	   16933 allocs/op
BenchmarkEchoSpeed1M-4     	      20	  75141637 ns/op	  13.95 MB/s	 1671859 B/op	   44578 allocs/op
BenchmarkSinkSpeed4K-4     	   10000	    147721 ns/op	  27.73 MB/s	    4206 B/op	      84 allocs/op
BenchmarkSinkSpeed64K-4    	    1000	   1033438 ns/op	  63.42 MB/s	   40962 B/op	     954 allocs/op
BenchmarkSinkSpeed256K-4   	     200	   7336797 ns/op	  71.46 MB/s	  272973 B/op	    6839 allocs/op
BenchmarkSinkSpeed1M-4     	     100	  14701943 ns/op	  71.32 MB/s	  614016 B/op	   13549 allocs/op
PASS
ok  	github.com/xtaci/kcp-go	36.141s

Tuning

Q: I'm running > 3000 connections on my server. the CPU utilization is high.

A: A standalone agent or gate server for kcp-go is suggested, not only for CPU utilization, but also important to the precision of RTT measurements which indirectly affects retransmission. By increasing update interval with SetNoDelay like conn.SetNoDelay(1, 40, 1, 1) will dramatically reduce system load.

Who is using this?

  1. https://github.com/xtaci/kcptun -- A Secure Tunnel Based On KCP over UDP.
  2. https://github.com/getlantern/lantern -- Lantern delivers fast access to the open Internet.
  3. https://github.com/smallnest/rpcx -- A RPC service framework based on net/rpc like alibaba Dubbo and weibo Motan.
  4. https://github.com/gonet2/agent -- A gateway for games with stream multiplexing.
  5. https://github.com/syncthing/syncthing -- Open Source Continuous File Synchronization.

Links

  1. https://github.com/xtaci/libkcp -- FEC enhanced KCP session library for iOS/Android in C++
  2. https://github.com/skywind3000/kcp -- A Fast and Reliable ARQ Protocol
  3. https://github.com/klauspost/reedsolomon -- Reed-Solomon Erasure Coding in Go

Support

You can support this project by the following methods:

  1. Vultr promotion code:
    http://www.vultr.com/?ref=6897065

  2. Paypal
    https://www.paypal.me/xtaci/5

  3. 支付宝 [email protected](接受在线付费咨询, Price: ¥128/45min, QQ:301008666,注明意图。)

kcp-go's People

Contributors

xtaci avatar audriusbutkevicius avatar

Watchers

James Cloos 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.