bench

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DataFlag byte = iota
	PingFlag
	PongFlag
	StartReadWriteFlag
	StopReadWriteFlag
	WriteResultFlag
)

Variables

This section is empty.

Functions

func RenewRandData

func RenewRandData(data Data, seq uint32)

RenewRandData 重新生成随机数据

Types

type BenchmarkClient

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

BenchmarkClient 基准测试客户端

func NewClient

func NewClient(client common.Client) *BenchmarkClient

NewClient 创建基准测试客户端

func (*BenchmarkClient) Run

func (c *BenchmarkClient) Run(ctx context.Context, stream *streamv1.Stream) (*Report, error)

Run 运行基准测试

type BenchmarkServer

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

BenchmarkServer 基准测试服务端

func NewServer

func NewServer(client common.Client) *BenchmarkServer

NewServer 创建基准测试服务端

func (*BenchmarkServer) Serve

func (c *BenchmarkServer) Serve(ctx context.Context, stream *streamv1.Stream) error

Serve 运行测试服务

type Data

type Data []byte

Data 数据消息

func NewRandData

func NewRandData(seq uint32, size uint64) Data

NewRandData 创建随机数据

func (Data) Checksum

func (d Data) Checksum() uint32

Checksum 返回内容的 CRC32 校验和

func (Data) Content

func (d Data) Content() []byte

Content 返回内容

func (Data) Raw

func (d Data) Raw() []byte

Raw 返回消息原始数据 格式: 0(byte) seq(uint32) checksum(uint32) content([]byte)

func (Data) Seq

func (d Data) Seq() uint32

Seq 返回包序号

func (Data) Type

func (d Data) Type() MessageType

Type 返回消息类型

type Message

type Message interface {
	// Type 返回消息类型
	Type() MessageType
	// Raw 返回消息原始数据
	Raw() []byte
}

Message 消息

func ParseMessage

func ParseMessage(raw []byte) (Message, error)

ParseMessage 解析消息

type MessageType

type MessageType string

MessageType 消息类型

const (
	DataType           MessageType = "Data"
	PingType           MessageType = "Ping"
	PongType           MessageType = "Pong"
	StartReadWriteType MessageType = "StartReadWrite"
	StopReadWriteType  MessageType = "StopReadWrite"
	WriteResultType    MessageType = "WriteResult"
)

type Ping

type Ping uint32

Ping ping 消息

func (Ping) Raw

func (m Ping) Raw() []byte

Raw 返回消息原始数据 格式: 1(byte) useless([3]byte) seq(uint32)

func (Ping) Type

func (m Ping) Type() MessageType

Type 返回消息类型

type PingResult

type PingResult struct {
	// 往返时延
	RoundTripTime time.Duration `json:"roundTripTime"`
	// 丢包率
	LossRate float64 `json:"lossRate"`
}

PingResult Ping 结果

type Pong

type Pong uint32

Pong ping 消息

func (Pong) Raw

func (m Pong) Raw() []byte

Raw 返回消息原始数据 格式: 2(byte) useless([3]byte) seq(uint32)

func (Pong) Type

func (m Pong) Type() MessageType

Type 返回消息类型

type ReadWriteMode

type ReadWriteMode byte

ReadWriteMode 读写模式

const (
	ReadMode  ReadWriteMode = 1
	WriteMode ReadWriteMode = 2
)

type ReadWriteResult

type ReadWriteResult struct {
	Read  TransmissionResult `json:"read,omitempty"`
	Write TransmissionResult `json:"write,omitempty"`
}

ReadWriteResult 读写结果

type Report

type Report struct {
	Ping      PingResult         `json:"ping,omitempty"`
	ReadOnly  TransmissionResult `json:"readOnly,omitempty"`
	WriteOnly TransmissionResult `json:"writeOnly,omitempty"`
	ReadWrite ReadWriteResult    `json:"readWrite,omitempty"`
}

Report 测试报告

type StartReadWrite

type StartReadWrite struct {
	Mode            ReadWriteMode
	ReadPackageSize uint64
}

StartReadWrite 开始读写消息

func (StartReadWrite) Raw

func (m StartReadWrite) Raw() []byte

Raw 返回消息原始数据 格式: 3(byte) mode(byte) readPackageSize(uint64)

func (StartReadWrite) Type

func (m StartReadWrite) Type() MessageType

Type 返回消息类型

type StopReadWrite

type StopReadWrite struct{}

StopReadWrite 停止读写消息

func (StopReadWrite) Raw

func (m StopReadWrite) Raw() []byte

Raw 返回消息原始数据

func (StopReadWrite) Type

func (m StopReadWrite) Type() MessageType

Type 返回消息类型

type TransmissionResult

type TransmissionResult struct {
	// 吞吐率(单位: Bytes/s )
	Throughput uint64 `json:"throughput"`
	// 丢包率
	LossRate float64 `json:"lossRate"`
	// 成功传输的数据大小
	Size uint64 `json:"size"`
	// 成功传输的包数量
	Packages uint32 `json:"packages"`
}

TransmissionResult 读结果

type WriteResult

type WriteResult struct {
	ReceivedPackageCount uint32
}

WriteResult 写结果信息

func (WriteResult) Raw

func (m WriteResult) Raw() []byte

Raw 返回消息原始数据 格式: 5(byte) receivedPackageCount(uint32)

func (WriteResult) Type

func (m WriteResult) Type() MessageType

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳