gomcrouter

command module
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README ΒΆ

🧭 gomcrouter

CI codecov Release License Go Version Go Report Card

gomcrouter is a high performance memcache request router written in Go. It accepts memcache protocol traffic, routes operations using configurable policies, and forwards requests to upstream memcached nodes using an event driven upstream engine.

Designed for low latency, high concurrency, and predictable routing behavior.

Supports memcache text protocol.


Features

  • Flexible routing policies per operation
  • Multiple backend servers via ordered pools
  • Active health checks
  • Prometheus metrics endpoint
  • Configurable server event loops
  • Multiple upstream connections per host
  • Configurable timeouts and buffers
  • Small static binary, multi-arch image (linux/amd64, linux/arm64) running as non-root

Installation

Every release publishes a multi-arch image and static binaries for linux/amd64 and linux/arm64 with their checksums.txt.

# Docker image
docker pull ghcr.io/tentens-tech/gomcrouter:latest

# Binary
VERSION=v1.3.4
curl -fsSL https://github.com/tentens-tech/gomcrouter/releases/download/$VERSION/gomcrouter-$VERSION-linux-amd64.tar.gz | tar xz  # gomcrouter, LICENSE, README.md
./gomcrouter --help

Quick Start

Build from source
make build        # or: go build -o gomcrouter .

Run with config file:

./gomcrouter -f router.yaml
Run with Docker
docker run --rm \
  -p 8080:8080 \
  -p 9090:9090 \
  -v $(pwd)/router.yaml:/router.yaml:ro \
  ghcr.io/tentens-tech/gomcrouter:latest \
  /bin/gomcrouter -f /router.yaml

To build the image locally, run make docker-build (or docker build -t gomcrouter .). The image runs as an unprivileged user (UID/GID 10001) and works with a read-only root filesystem.

Ports:

  • 8080 router listen
  • 9090 metrics endpoint

See examples/docker for a docker-compose setup with two memcached nodes, a writer, a metrics watcher and an end-to-end test.


Command Line Options

gomcrouter [flags]
General
-f, --router-config string
    path to router config file
    default router.yaml

-l, --listen string
    listen address
    default tcp://:8080

--log-level string
    log level
    default info

-v, --version
    print the version and exit

-h, --help
    print the help and exit
Runtime
-n, --server-event-loops int
    number of server event loops
    default 1

-C, --upstream-connections int
    upstream connections per host
    default 2

-r, --timeout-ms int
    upstream timeout in milliseconds
    default 1000

-b, --buffer-size int
    socket read / write buffer sizes in bytes
    default 1048576
Health and DNS
-H, --healthcheck-interval duration
    upstream healthcheck interval
    default 10s

-t, --dns-cache-ttl duration
    dns cache ttl
    default 30s
Metrics
-L, --metrics-listen-addr string
    metrics listen address
    default :9090

Example Router Configuration

router.yaml:

orderedPool:
  - memcache1:11211
  - memcache2:11211

route:
  type: OperationSelectorRoute
  operationPolicies:
    add: AllFastestRoute
    append: AllFastestRoute
    decr: AllFastestRoute
    delete: AllFastestRoute
    get: MissFailoverRoute
    gets: MissFailoverRoute
    incr: AllFastestRoute
    prepend: AllFastestRoute
    replace: AllFastestRoute
    set: AllFastestRoute
    version: LocalRoute
    quit: LocalRoute

Routing

The route.type field defines which routing strategy is used. Any available route implementation can be configured here.

Example:

route:
  type: OperationSelectorRoute
Route Types
Route Description
OperationSelectorRoute Select routing policy based on memcache command
AllFastestRoute Send request to all hosts and return fastest response
MissFailoverRoute Try next host on miss or failure
DefaultRoute Route to the first host in pool order
LocalRoute Handle request locally in router

Route specific options may require additional configuration fields depending on the selected type.


Protocol Support

Protocol Status
Memcached ASCII βœ… Supported
Memcached Binary ❌ Not supported yet
Memcached Meta ❌ Not supported yet

Metrics

Prometheus metrics are served on http://<metrics-listen-addr>/metrics:

Metric Labels Description
gomcrouter_requests_total cmd Requests made by clients
gomcrouter_request_duration_milliseconds cmd Request latency histogram
gomcrouter_upstream_requests_total cmd, host Requests made to upstream hosts
gomcrouter_upstream_errors_total cmd, host Errors returned from upstream hosts
gomcrouter_upstream_request_duration_milliseconds cmd, host Upstream request latency histogram
gomcrouter_upstream_get_hits_total host get/gets responses with at least one VALUE
gomcrouter_upstream_get_misses_total host get/gets responses without a VALUE
gomcrouter_upstream_healthy_hosts_total Healthy upstream hosts
gomcrouter_upstream_connections_total host Upstream connections
gomcrouter_metrics_events_dropped_total event_type Metric events dropped because the async event ring was full
gomcrouter_version version Running version

Architecture

High-level request flow inside gomcrouter:

Clients (Memcached ASCII)
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ gnet frontend          β”‚
β”‚ - multicore loops      β”‚
β”‚ - TCP accept/read/writeβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ parser + router        β”‚
β”‚ - decode cmd           β”‚
β”‚ - route/hash/dispatch  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ pools                  β”‚
β”‚ - hosts + health state β”‚
β”‚ - selection/failover   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ io.Engine              β”‚
β”‚ - pollGroups (shards)  β”‚
β”‚ - netpoll + socket I/O β”‚
β”‚ - rings/batching       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β–Ό
Memcached backends

πŸ“Š Full architecture diagram (SVG): docs/architecture.svg


Performance

See BENCHMARKS.md for memtier_benchmark results.


Contributing

Contributions are welcome, see CONTRIBUTING.md. Report security issues privately, see SECURITY.md.

make help       # list the targets
make test-race  # unit tests with the race detector
make lint       # golangci-lint
make e2e        # end-to-end suites in docker, see test/README.md

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Documentation ΒΆ

Overview ΒΆ

Command gomcrouter is a high performance memcached request router.

It accepts memcached text protocol traffic, routes every operation by configurable policies (default, all-fastest, miss-failover, local and per-operation routes) and forwards the requests to upstream memcached nodes through an event-driven upstream engine. Health checks, DNS re-resolution and Prometheus metrics are built in.

Usage:

gomcrouter -f router.yaml [-l tcp://:8080] [-L :9090]

See the README for the configuration and all flags: https://github.com/tentens-tech/gomcrouter#readme

Directories ΒΆ

Path Synopsis
internal
upstream/internal/upstreamtest
Package upstreamtest holds test helpers shared by the internal/upstream/...
Package upstreamtest holds test helpers shared by the internal/upstream/...
test
e2e/client command
Command e2e-client is a small memcached text protocol client used by the end-to-end tests.
Command e2e-client is a small memcached text protocol client used by the end-to-end tests.

Jump to

Keyboard shortcuts

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