redhub

package module
v0.0.0-...-2253302 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

REDHUB

RedHub

GoDoc FOSSA Status

High-performance RESP-Server multi-threaded framework, based on RawEpoll model.

  • Ultra high performance
  • Fully multi-threaded support
  • Low CPU resource consumption
  • Compatible with redis protocol
  • Create a Redis compatible server with RawEpoll model in Go

Installing

go get -u github.com/IceFireDB/redhub

Example

Here is a simple framework usage example,support the following redis commands:

  • SET key value
  • GET key
  • DEL key
  • PING
  • QUIT

You can run this example in terminal:

go run example/memory_kv/server.go

Benchmarks

Machine information
        OS : Debian Buster 10.6 64bit 
       CPU : 8 CPU cores
    Memory : 64.0 GiB

Go Version : go1.16.5 linux/amd64

【Redis-server5.0.3】 Single-threaded, no disk persistence.
$ ./redis-server --port 6380 --appendonly no
$ redis-benchmark -h 127.0.0.1 -p 6380 -n 50000000 -t set,get -c 512 -P 1024 -q
SET: 2306060.50 requests per second
GET: 3096742.25 requests per second
【Redis-server6.2.5】 Single-threaded, no disk persistence.
$ ./redis-server --port 6380 --appendonly no
$ redis-benchmark -h 127.0.0.1 -p 6380 -n 50000000 -t set,get -c 512 -P 1024 -q
SET: 2076325.75 requests per second
GET: 2652801.50 requests per second
【Redis-server6.2.5】 Multi-threaded, no disk persistence.
io-threads-do-reads yes
io-threads 8
$ ./redis-server redis.conf
$ redis-benchmark -h 127.0.0.1 -p 6379 -n 50000000 -t set,get -c 512 -P 1024 -q
SET: 1944692.88 requests per second
GET: 2375184.00 requests per second
【RedCon】 Multi-threaded, no disk persistence
$ go run example/clone.go
$ redis-benchmark -h 127.0.0.1 -p 6380 -n 50000000 -t set,get -c 512 -P 1024 -q
SET: 2332742.25 requests per second
GET: 14654162.00 requests per second
【RedHub】 Multi-threaded, no disk persistence
$ go run example/server.go
$ redis-benchmark -h 127.0.0.1 -p 6380 -n 50000000 -t set,get -c 512 -P 1024 -q
SET: 4087305.00 requests per second
GET: 16490765.00 requests per second

REDHUB Benchmarks

REDHUB Benchmarks

Disclaimers

When you use this software, you have agreed and stated that the author, maintainer and contributor of this software are not responsible for any risks, costs or problems you encounter. If you find a software defect or BUG, ​​please submit a patch to help improve it!

License

FOSSA Status

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListendAndServe

func ListendAndServe(addr string, options Options, rh *redHub) error

func NewRedHub

func NewRedHub(
	onOpened func(c *Conn) (out []byte, action Action),
	onClosed func(c *Conn, err error) (action Action),
	handler func(cmd resp.Command, out []byte) ([]byte, Action),
) *redHub

Types

type Action

type Action int
const (
	// None indicates that no action should occur following an event.
	None Action = iota

	// Close closes the connection.
	Close

	// Shutdown shutdowns the server.
	Shutdown
)

type Conn

type Conn struct {
	gnet.Conn
}

type Options

type Options struct {
	// Multicore indicates whether the server will be effectively created with multi-cores, if so,
	// then you must take care with synchronizing memory between all event callbacks, otherwise,
	// it will run the server with single thread. The number of threads in the server will be automatically
	// assigned to the value of logical CPUs usable by the current process.
	Multicore bool

	// LockOSThread is used to determine whether each I/O event-loop is associated to an OS thread, it is useful when you
	// need some kind of mechanisms like thread local storage, or invoke certain C libraries (such as graphics lib: GLib)
	// that require thread-level manipulation via cgo, or want all I/O event-loops to actually run in parallel for a
	// potential higher performance.
	LockOSThread bool

	// ReadBufferCap is the maximum number of bytes that can be read from the client when the readable event comes.
	// The default value is 64KB, it can be reduced to avoid starving subsequent client connections.
	//
	// Note that ReadBufferCap will be always converted to the least power of two integer value greater than
	// or equal to its real amount.
	ReadBufferCap int

	// LB represents the load-balancing algorithm used when assigning new connections.
	LB gnet.LoadBalancing

	// NumEventLoop is set up to start the given number of event-loop goroutine.
	// Note: Setting up NumEventLoop will override Multicore.
	NumEventLoop int

	// ReusePort indicates whether to set up the SO_REUSEPORT socket option.
	ReusePort bool

	// Ticker indicates whether the ticker has been set up.
	Ticker bool

	// TCPKeepAlive sets up a duration for (SO_KEEPALIVE) socket option.
	TCPKeepAlive time.Duration

	// TCPNoDelay controls whether the operating system should delay
	// packet transmission in hopes of sending fewer packets (Nagle's algorithm).
	//
	// The default is true (no delay), meaning that data is sent
	// as soon as possible after a Write.
	TCPNoDelay gnet.TCPSocketOpt

	// SocketRecvBuffer sets the maximum socket receive buffer in bytes.
	SocketRecvBuffer int

	// SocketSendBuffer sets the maximum socket send buffer in bytes.
	SocketSendBuffer int

	// ICodec encodes and decodes TCP stream.
	Codec gnet.ICodec
}

Directories

Path Synopsis
example
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL