All Projects → tidwall → Evio

tidwall / Evio

Licence: mit
Fast event-loop networking for Go

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to Evio

Goby
Attack surface mapping
Stars: ✭ 446 (-91.36%)
Mutual labels:  networking
Libzt
ZeroTier Sockets - Put a network stack in your app
Stars: ✭ 486 (-90.59%)
Mutual labels:  networking
Cjdns
An encrypted IPv6 network using public-key cryptography for address allocation and a distributed hash table for routing.
Stars: ✭ 4,766 (-7.67%)
Mutual labels:  networking
Cnp3
Computer Networking : Principles, Protocols and Practice (first and second edition, third edition is being written on https://github.com/cnp3/ebook)
Stars: ✭ 471 (-90.88%)
Mutual labels:  networking
Swift Request
Declarative HTTP networking, designed for SwiftUI
Stars: ✭ 481 (-90.68%)
Mutual labels:  networking
Netplugin
Container networking for various use cases
Stars: ✭ 497 (-90.37%)
Mutual labels:  networking
Curlcpp
An object oriented C++ wrapper for CURL (libcurl)
Stars: ✭ 462 (-91.05%)
Mutual labels:  networking
Humblenet
a cross-platform networking library that works in the browser
Stars: ✭ 515 (-90.02%)
Mutual labels:  networking
School Of Sre
At LinkedIn, we are using this curriculum for onboarding our entry-level talents into the SRE role.
Stars: ✭ 5,141 (-0.41%)
Mutual labels:  networking
State Threads
Light-weight thread library, coroutine or c++ goroutine , patched for SRS.
Stars: ✭ 500 (-90.31%)
Mutual labels:  networking
Peerdiscovery
Pure-Go library for cross-platform local peer discovery using UDP multicast 👩 🔁 👩
Stars: ✭ 476 (-90.78%)
Mutual labels:  networking
Gns3 Server
GNS3 server
Stars: ✭ 477 (-90.76%)
Mutual labels:  networking
Airshare
Cross-platform content sharing in a local network
Stars: ✭ 497 (-90.37%)
Mutual labels:  networking
Ucx
Unified Communication X (mailing list - https://elist.ornl.gov/mailman/listinfo/ucx-group)
Stars: ✭ 471 (-90.88%)
Mutual labels:  networking
Tron
Lightweight network abstraction layer, written on top of Alamofire
Stars: ✭ 508 (-90.16%)
Mutual labels:  networking
Enet Csharp
Reliable UDP networking library
Stars: ✭ 464 (-91.01%)
Mutual labels:  networking
Xniffer
A swift network profiler built on top of URLSession.
Stars: ✭ 488 (-90.55%)
Mutual labels:  networking
Trigger
Trigger is a robust network automation toolkit written in Python that was designed for interfacing with network devices.
Stars: ✭ 521 (-89.91%)
Mutual labels:  networking
Pmhttp
Swift/Obj-C HTTP framework with a focus on REST and JSON
Stars: ✭ 509 (-90.14%)
Mutual labels:  networking
Networking
⚡️ Elegantly connect to a REST JSON Api. URLSession + Combine + Decodable + Generics = <3
Stars: ✭ 499 (-90.33%)
Mutual labels:  networking

evio
GoDoc

evio is an event loop networking framework that is fast and small. It makes direct epoll and kqueue syscalls rather than using the standard Go net package, and works in a similar manner as libuv and libevent.

The goal of this project is to create a server framework for Go that performs on par with Redis and Haproxy for packet handling. It was built to be the foundation for Tile38 and a future L7 proxy for Go.

Please note: Evio should not be considered as a drop-in replacement for the standard Go net or net/http packages.

Features

Getting Started

Installing

To start using evio, install Go and run go get:

$ go get -u github.com/tidwall/evio

This will retrieve the library.

Usage

Starting a server is easy with evio. Just set up your events and pass them to the Serve function along with the binding address(es). Each connections is represented as an evio.Conn object that is passed to various events to differentiate the clients. At any point you can close a client or shutdown the server by return a Close or Shutdown action from an event.

Example echo server that binds to port 5000:

package main

import "github.com/tidwall/evio"

func main() {
	var events evio.Events
	events.Data = func(c evio.Conn, in []byte) (out []byte, action evio.Action) {
		out = in
		return
	}
	if err := evio.Serve(events, "tcp://localhost:5000"); err != nil {
		panic(err.Error())
	}
}

Here the only event being used is Data, which fires when the server receives input data from a client. The exact same input data is then passed through the output return value, which is then sent back to the client.

Connect to the echo server:

$ telnet localhost 5000

Events

The event type has a bunch of handy events:

  • Serving fires when the server is ready to accept new connections.
  • Opened fires when a connection has opened.
  • Closed fires when a connection has closed.
  • Detach fires when a connection has been detached using the Detach return action.
  • Data fires when the server receives new data from a connection.
  • Tick fires immediately after the server starts and will fire again after a specified interval.

Multiple addresses

A server can bind to multiple addresses and share the same event loop.

evio.Serve(events, "tcp://192.168.0.10:5000", "unix://socket")

Ticker

The Tick event fires ticks at a specified interval. The first tick fires immediately after the Serving events.

events.Tick = func() (delay time.Duration, action Action){
	log.Printf("tick")
	delay = time.Second
	return
}

UDP

The Serve function can bind to UDP addresses.

  • All incoming and outgoing packets are not buffered and sent individually.
  • The Opened and Closed events are not availble for UDP sockets, only the Data event.

Multithreaded

The events.NumLoops options sets the number of loops to use for the server. A value greater than 1 will effectively make the server multithreaded for multi-core machines. Which means you must take care when synchonizing memory between event callbacks. Setting to 0 or 1 will run the server as single-threaded. Setting to -1 will automatically assign this value equal to runtime.NumProcs().

Load balancing

The events.LoadBalance options sets the load balancing method. Load balancing is always a best effort to attempt to distribute the incoming connections between multiple loops. This option is only available when events.NumLoops is set.

  • Random requests that connections are randomly distributed.
  • RoundRobin requests that connections are distributed to a loop in a round-robin fashion.
  • LeastConnections assigns the next accepted connection to the loop with the least number of active connections.

SO_REUSEPORT

Servers can utilize the SO_REUSEPORT option which allows multiple sockets on the same host to bind to the same port.

Just provide reuseport=true to an address:

evio.Serve(events, "tcp://0.0.0.0:1234?reuseport=true"))

More examples

Please check out the examples subdirectory for a simplified redis clone, an echo server, and a very basic http server.

To run an example:

$ go run examples/http-server/main.go
$ go run examples/redis-server/main.go
$ go run examples/echo-server/main.go

Performance

Benchmarks

These benchmarks were run on an ec2 c4.xlarge instance in single-threaded mode (GOMAXPROC=1) over Ipv4 localhost. Check out benchmarks for more info.

echo benchmarkhttp benchmarkredis 1 benchmarkredis 8 benchmark

Contact

Josh Baker @tidwall

License

evio source code is available under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].