kafo

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2020 License: MIT Imports: 8 Imported by: 0

README

☕ kafo-client License

Kafo-client 是 kafo 缓存服务的客户端,而 kafo 是一个高性能的轻量级分布式缓存中间件,支持 tcp/http 调用。

🖊 使用指南
  • 下载依赖:
go get github.com/avino-plan/kafo-client
  • 开始编码:
package main

import (
	"github.com/avino-plan/kafo-client"
)

func main() {

	config := kafo.DefaultConfig()
	client, err := kafo.NewTCPClient([]string{"127.0.0.1:5837"}, config)
	if err != nil {
		panic(err)
	}
	defer client.Close()

	// ...
}
⚛ 性能测试

R7-4700U,16GB RAM,1000 并发,每个并发 10 个 key,节点数是指 kafo 的进程数

操作 单节点 双节点 三节点 四节点 五节点
写入 478ms 263ms 236ms 231ms 230ms
读取 475ms 262ms 233ms 226ms 219ms
rps 21053 38168 42918 44248 45662

可以看到,随着节点数的提升,性能也在提升,尤其是从单节点变成双节点的时候,性能提升达到了 81%!这是在意料之中的,因为多节点会使用多个 TCP 连接。

但我们也可以看到随着节点数的提升,性能提升的幅度逐渐变小,主要是因为在我的笔记本上测试没办法在网络上达到完全的并行,如果是独立的物理机,相信提升幅度还会更大!

🔬 kafo-client 使用的技术
项目 作者 描述 链接
vex FishGoddess 一个高性能、且极易上手的网络通信框架 GitHub / 码云

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v0.2.0

type Config struct {

	// Network is the type of Network, which can be one of ["tcp", "tcp4", "tcp6"].
	Network string

	// Ttl is the life of connection.
	Ttl time.Duration

	// GcDuration is the duration between two gc operations.
	GcDuration time.Duration

	// NumberOfReplicas is the number of hash replicas.
	// Notice that it should equals to server.
	NumberOfReplicas int

	// MaxRetryTimes is the max retry times when something wrong happens.
	MaxRetryTimes int

	// UpdateCircleDuration is the duration between two circle updating operations.
	UpdateCircleDuration time.Duration
}

Config is the type of config.

func DefaultConfig added in v0.2.0

func DefaultConfig() Config

DefaultConfig returns a default config.

type Status

type Status struct {

	// Count records how many entries storing in kafo.
	Count int `json:"count"`

	// KeySize records the size of keys.
	KeySize int64 `json:"keySize"`

	// ValueSize records the size of value.
	ValueSize int64 `json:"valueSize"`
}

Status is the status of kafo.

type TCPClient

type TCPClient struct {
	// contains filtered or unexported fields
}

TCPClient is the client of tcp Network.

func NewTCPClient

func NewTCPClient(addresses []string, config Config) (*TCPClient, error)

NewTCPClient returns a new tcp client with given config and an error if failed.

func (*TCPClient) Close

func (tc *TCPClient) Close()

Close closes all connections.

func (*TCPClient) Delete

func (tc *TCPClient) Delete(key string) error

Delete deletes the value of key and returns an error if failed.

func (*TCPClient) Get

func (tc *TCPClient) Get(key string) ([]byte, error)

Get returns the value of key and an error if failed.

func (*TCPClient) Nodes

func (tc *TCPClient) Nodes() ([]string, error)

Nodes returns the nodes of cluster and an error if failed.

func (*TCPClient) Set

func (tc *TCPClient) Set(key string, value []byte, ttl int64) error

Set adds the key and value with given ttl to cache. Returns an error if failed.

func (*TCPClient) Status

func (tc *TCPClient) Status() (*Status, error)

Status returns the status of kafo and an error if failed.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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