Skip to content

Latest commit

 

History

History
132 lines (115 loc) · 4.79 KB

File metadata and controls

132 lines (115 loc) · 4.79 KB

Examples

简体中文 | Docs Index

Example 1: Add the Module to an Application

mkdir gnalloy-app && cd gnalloy-app
go mod init example.com/gnalloy-app
go get gnalloy.org/examples@dev
go doc gnalloy.org/examples

Example 2: Inspect Current Packages

The current source tree exposes these package import paths:

  • gnalloy.org/examples/bench-client
  • gnalloy.org/examples/custom-ip-proto
  • gnalloy.org/examples/doq-query
  • gnalloy.org/examples/echo
  • gnalloy.org/examples/fixed-length
  • gnalloy.org/examples/http1
  • gnalloy.org/examples/icmp-ping
  • gnalloy.org/examples/internal/benchclient
  • gnalloy.org/examples/internal/exampleconfig
  • gnalloy.org/examples/internal/smokeclient
  • gnalloy.org/examples/internal/stresscheck
  • gnalloy.org/examples/internal/stressclient
  • gnalloy.org/examples/length-field
  • gnalloy.org/examples/line-frame
  • gnalloy.org/examples/mqtt-frame
  • gnalloy.org/examples/parity-bench
  • gnalloy.org/examples/protobuf-varint
  • gnalloy.org/examples/protocol-exchange
  • gnalloy.org/examples/raw-ip-dump
  • gnalloy.org/examples/redis-resp
  • gnalloy.org/examples/smoke-client
  • gnalloy.org/examples/stress-check
  • gnalloy.org/examples/stress-client
  • gnalloy.org/examples/udp-echo
  • gnalloy.org/examples/websocket

Use go doc against the package that matches the behavior you need:

go doc gnalloy.org/examples/bench-client
go doc gnalloy.org/examples/custom-ip-proto
go doc gnalloy.org/examples/doq-query
go doc gnalloy.org/examples/echo
go doc gnalloy.org/examples/fixed-length
go doc gnalloy.org/examples/http1
go doc gnalloy.org/examples/icmp-ping
go doc gnalloy.org/examples/internal/benchclient

Selected current exported entry points:

  • var ErrInvalidProtocol = errors.New("gnalloy/examples: invalid bench protocol") ...
  • type Config struct{ ... }
  • type Protocol string
  • type Result struct{ ... }
  • var ErrInvalidBackend = errors.New("gnalloy/examples: invalid backend") ...
  • func BackendLabel(backend transport.BackendKind) string
  • func ParseBackend(name string) (transport.BackendKind, error)
  • type Options struct{ ... }
  • var ErrInvalidProtocol = errors.New("gnalloy/examples: invalid smoke protocol") ...
  • func Run(ctx context.Context, cfg Config) error
  • type Config struct{ ... }
  • type Protocol string
  • const ProtocolBoth stressclient.Protocol = "both"
  • var ErrLeakDetected = errors.New("gnalloy/examples: stress leak detected") ...
  • type Config struct{ ... }
  • type Result struct{ ... }
  • var ErrInvalidProtocol = errors.New("gnalloy/examples: invalid stress protocol") ...
  • type Config struct{ ... }

Example 3: Use Executable Tests as Behavioral Examples

Repository tests are executable examples of supported behavior. Start with the selected names below, then read the matching _test.go files for complete setup and assertions. See Testing and Performance for the complete discovered list.

GOWORK=off GOTOOLCHAIN=local go test ./... -run Test -count=1

Selected current test, benchmark, fuzz, and example entry points:

  • TestConfigRejectsInvalidScenario
  • TestConfigValidate
  • TestExchangeFixed
  • TestExchangeHTTP1
  • TestExchangeLengthField
  • TestExchangeLine
  • TestExchangeMQTT
  • TestExchangeRaw
  • TestExchangeRedis
  • TestExchangeRejectsInvalidProtocol
  • TestExchangeWebSocket
  • TestHostForSNIUsesHostPart
  • TestOptionsResolveRejectsFixedBuffersWithoutIOUringMmap
  • TestOptionsResolveRejectsInvalidSizes
  • TestOptionsTCPConfigEnablesFixedBuffers
  • TestOptionsWriteBufferWatermarkFlowsToConfigs
  • TestParseBackendNames
  • TestParseBackendRejectsUnknownName

Example 4: Cross-Module Assembly

Direct Gnalloy dependencies for this module:

  • gnalloy.org/benchmarks
  • gnalloy.org/codec-dns
  • gnalloy.org/codec-http1
  • gnalloy.org/codec-icmp
  • gnalloy.org/codec-ip
  • gnalloy.org/codec-mqtt
  • gnalloy.org/codec-protobuf
  • gnalloy.org/codec-redis
  • gnalloy.org/codec-websocket
  • gnalloy.org/gnalloy
  • gnalloy.org/protocol
  • gnalloy.org/resolver-dns-quic
  • gnalloy.org/transport-l2
  • gnalloy.org/transport-quic
  • gnalloy.org/transport-raw
  • gnalloy.org/transport-tcp
  • gnalloy.org/transport-udp

Assembly guidance:

  • Use runnable example commands as smoke clients and integration references.
  • Examples should stay small, explicit, and close to the public APIs they exercise.
  • Production services should copy the structure, not hard-code example defaults.

Example 5: Pressure-Test Harness

For sustained load, wire this module into a scenario under gnalloy.org/benchmarks or a runnable client under gnalloy.org/examples when the module participates in network traffic. Record host, OS, CPU, Go version, protocol, payload, concurrency, warmup, repetitions, throughput, and p99 latency in the report.