Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Gophers-Future/znet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

151 Commits

Repository files navigation

znet

golang powerful network framework

Features

  • High-performance Event-Loop under multi-threads model
  • Supporting multiple protocols: TCP,Websocket
  • Supporting reactor event-notification mechanisms: epoll in Linux/Windows and kqueue in FreeBSD
  • Supporting safe goroutines worker pool
  • Supporting two contentType: JSON/Protobuf
  • Supporting router service for different operate and handle functions

Quick start

  • install
go get -u github.com/ebar-go/znet
  • go run server.go
// server.go
package main
import (
	"github.com/ebar-go/ego/utils/runtime/signal"
	"github.com/ebar-go/znet"
)
const(
	ActionFoo = 1 // define a foo operate
)
func main() {
	// new instance
	instance := znet.New()
	// listen tcp and websocket
	instance.ListenTCP(":8081")
	instance.ListenWebsocket(":8082")
 
	// register a router for some operate
	instance.Router().Route(ActionFoo, func(ctx *znet.Context) (any, error) {
		// return response to the client
		return map[string]any{"foo": "bar"}, nil
	})
	
	// run the instance, graceful stop by ctrl-c.
	instance.Run(signal.SetupSignalHandler())
}

Architecture

Protocol

  • TCP : We design the protocol for sticky packet problem
|-------------- header --------------|-------- body --------|
|packetLength| action | seq |-------- body --------|
| 4 | 2 | 2 | n |
  • WebSocket : don't need the packet length
|-------------- header --------------|-------- body --------|
| action | seq |-------- body --------|
| 2 | 2 | n |

Benchmark

goos: linux
goarch: amd64
pkg: github.com/ebar-go/znet
cpu: Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
|-----------------------------------|
| connections | memory | cpu |
|-----------------------------------|
| 10000 | 50MB | |
|-----------------------------------|

About

golang powerful network framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages

  • C 55.5%
  • Go 44.5%

AltStyle によって変換されたページ (->オリジナル) /