rely

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2020 License: BSD-3-Clause Imports: 3 Imported by: 0

README

rely

port of reliable.io to Go

GoDoc Build Status

performance

Tests below done on Ubuntu with Go 1.10. For whatever reasons when I run the pooled test on a mac it runs in .34s so YMMV.

rely without pooling

$ go build -tags=test && /usr/bin/time -v ./soak -iterations=8100
	Command being timed: "./soak -iterations=8100"
	User time (seconds): 0.71
	System time (seconds): 0.00
	Percent of CPU this job got: 108%
	Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.66
	Average shared text size (kbytes): 0
	Average unshared data size (kbytes): 0
	Average stack size (kbytes): 0
	Average total size (kbytes): 0
	Maximum resident set size (kbytes): 8364
	Average resident set size (kbytes): 0
	Major (requiring I/O) page faults: 0
	Minor (reclaiming a frame) page faults: 1462
	Voluntary context switches: 880
	Involuntary context switches: 93
	Swaps: 0
	File system inputs: 0
	File system outputs: 0
	Socket messages sent: 0
	Socket messages received: 0
	Signals delivered: 0
	Page size (bytes): 4096
	Exit status: 0

rely with pooling

$ go build -tags=test && /usr/bin/time -v ./soak -iterations=8100 -pool=true
	Command being timed: "./soak -iterations=8100 -pool=true"
	User time (seconds): 0.54
	System time (seconds): 0.01
	Percent of CPU this job got: 102%
	Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.54
	Average shared text size (kbytes): 0
	Average unshared data size (kbytes): 0
	Average stack size (kbytes): 0
	Average total size (kbytes): 0
	Maximum resident set size (kbytes): 8492
	Average resident set size (kbytes): 0
	Major (requiring I/O) page faults: 0
	Minor (reclaiming a frame) page faults: 1487
	Voluntary context switches: 408
	Involuntary context switches: 63
	Swaps: 0
	File system inputs: 0
	File system outputs: 0
	Socket messages sent: 0
	Socket messages received: 0
	Signals delivered: 0
	Page size (bytes): 4096
	Exit status: 0

reliable.io

$ /usr/bin/time -v ./bin/soak 8100
	Command being timed: "./bin/soak 8100"
	User time (seconds): 0.35
	System time (seconds): 0.00
	Percent of CPU this job got: 99%
	Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.35
	Average shared text size (kbytes): 0
	Average unshared data size (kbytes): 0
	Average stack size (kbytes): 0
	Average total size (kbytes): 0
	Maximum resident set size (kbytes): 1960
	Average resident set size (kbytes): 0
	Major (requiring I/O) page faults: 0
	Minor (reclaiming a frame) page faults: 379
	Voluntary context switches: 1
	Involuntary context switches: 32
	Swaps: 0
	File system inputs: 0
	File system outputs: 0
	Socket messages sent: 0
	Socket messages received: 0
	Signals delivered: 0
	Page size (bytes): 4096
	Exit status: 0

Documentation

Overview

This is a port of reliable.io to Go. See also https://gafferongames.com/post/reliable_ordered_messages/

Index

Constants

View Source
const (
	MaxPacketHeaderBytes = 9
	FragmentHeaderBytes  = 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Name                         string
	Context                      interface{}
	Index                        int
	MaxPacketSize                int
	FragmentAbove                int
	MaxFragments                 int
	FragmentSize                 int
	AckBufferSize                int
	SentPacketsBufferSize        int
	ReceivedPacketsBufferSize    int
	FragmentReassemblyBufferSize int
	RttSmoothingFactor           float64
	PacketLossSmoothingFactor    float64
	BandwidthSmoothingFactor     float64
	PacketHeaderSize             int

	// TransmitPacketFunction is called by SendPacket to do the actual transmitting of packets
	TransmitPacketFunction func(interface{}, int, uint16, []byte)
	// ProcessPacketFunction is called by ReceivePacket once a fully assembled packet is received
	ProcessPacketFunction func(interface{}, int, uint16, []byte) bool
	// Allocate can be used to implement custom memory allocation
	Allocate func(int) []byte
	// Free can be used to implement custom memory allocation
	Free func([]byte)
}

Config holds endpoint configuration data

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig creates a typical endpoint configuration

type Endpoint

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

Endpoint is a reliable udp endpoint

func NewEndpoint

func NewEndpoint(config *Config, time float64) *Endpoint

NewEndpoint creates an endpoint

func (*Endpoint) Bandwidth

func (e *Endpoint) Bandwidth() (float64, float64, float64)

Bandwith returns the sent, received, and acked bandwidth in Kbps

func (*Endpoint) ClearAcks

func (e *Endpoint) ClearAcks()

ClearAcks clears the endpoints ack array

func (*Endpoint) GetAcks

func (e *Endpoint) GetAcks() []uint16

GetAcks returns the acks received so far, make sure to clear acks too

func (*Endpoint) NextPacketSequence

func (e *Endpoint) NextPacketSequence() uint16

NextPacketSequence returns the next packet sequence that will be used

func (*Endpoint) PacketLoss

func (e *Endpoint) PacketLoss() float64

PacketLoss returns the percent of packets lost this endpoint is experiencing

func (*Endpoint) PacketsAcked

func (e *Endpoint) PacketsAcked() uint64

PacketsAcked returns the number of packets acked

func (*Endpoint) PacketsReceived

func (e *Endpoint) PacketsReceived() uint64

PacketsReceived returns the number of packets received

func (*Endpoint) PacketsSent

func (e *Endpoint) PacketsSent() uint64

PacketsSent returns the number of packets sent

func (*Endpoint) ReceivePacket

func (e *Endpoint) ReceivePacket(packetData []byte)

ReceivePacket reliably receives a packet of data sent by SendPacket

func (*Endpoint) Reset

func (e *Endpoint) Reset()

Reset starts the endpoint fresh

func (*Endpoint) Rtt

func (e *Endpoint) Rtt() float64

Rtt returns the round-trip time

func (*Endpoint) SendPacket

func (e *Endpoint) SendPacket(packetData []byte)

SendPacket reliably sends one or more packets with the passed

func (*Endpoint) Update

func (e *Endpoint) Update(time float64)

Update recalculates statistics (like packet loss)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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