Skip to main content

Go Framework (atsf4g-go)

Status: In Progress Overall; libatbus-go Completed

The Go server framework atsf4g-go is still under active development, so this page summarizes only its architecture, repository layout, and current transport benchmark baseline. Its communication bus libatbus-go is completed and has a full protocol-stack benchmark report (see libatbus-go Benchmark).

Repositories and Component Status​

atsf4g-go mirrors the layered layout of C++ atsf4g-co, using a single Go 1.27+ root module with go.work linking standalone library submodules:

RepositoryC++ CounterpartResponsibilityStatus
atsf4g-goatsf4g-coMain game server framework: shared components (src/component/), sample lobby service (src/lobbysvr/), Mako templates, and go tool dev pure-Go build toolingIn progress
libatbus-golibatbusInter-server communication bus: full v2 protocol stack, X25519 key exchange, encryption, compression, and topology routingCompleted (Benchmark)
libatapp-golibatappApplication container: process lifecycle, module management, configuration, signal handling, and built-in ants worker poolIn progress
atframe-utils-goatframe_utilsBase utilities: logging, algorithms, crypto/compression adapters, protoc-gen-mutable, and buildkitIn progress

Excel configuration conversion reuses xresloader and xres-code-generator.

Design Shared with the C++ Framework​

atsf4g-go shares the same communication protocol and development conventions as atsf4g-co, allowing Go and C++ services to coexist in the same cluster:

  • Same communication stack: libatbus-go implements the same v2 framing, handshake, encryption, compression, and routing semantics as C++ libatbus, so Go services connect through atgateway / atproxy and interoperate with C++ services.
  • Same application and task abstractions: retains the libatapp module lifecycle, Dispatcher / TaskManager / TaskAction dispatch model, router object cache (RouterObjectBase), and Redis data layer.
  • Same declarative code generation: drives config loaders, database APIs, RPC handler registration, and downstream push APIs from Protobuf and Excel using Mako templates, protoc-gen-mutable, and xresloader.

ActorExecutor and Token Scheduling​

C++ atsf4g-co runs business coroutines on a single-threaded libuv event loop, keeping per-object state access naturally serialized within a process. The Go runtime schedules goroutines across multiple OS threads, and libatapp-go dispatches tasks concurrently through a built-in ants worker pool (AppInstance.PushAction). Running multiple tasks for the same stateful entity (such as the same player) directly on the worker pool would cause data races.

To reconcile Go's multi-threaded worker pool with lock-free per-entity business logic, atsf4g-go introduces ActorExecutor and a running-token mechanism in src/component/dispatcher/:

  • Multi-threaded parallelism across ActorExecutors: each stateful object (such as a RouterObjectBase or player User) owns an independent ActorExecutor. Distinct actors hold separate tokens and are scheduled concurrently onto multiple worker goroutines and OS threads by libatapp-go's worker pool.
  • Serialized state access with multi-task I/O concurrency inside one ActorExecutor: within a single ActorExecutor, a token (currentRunningLock and currentRunningAction) ensures at most one TaskAction mutates that actor's state at any moment. When a task awaits an RPC, database query, or timer (YieldTaskAction), it sets up its await channel and releases the token before blocking, re-triggering actor scheduling so other queued tasks for the same ActorExecutor can execute concurrently during the I/O wait. Once the reply or timeout arrives, the woken task re-acquires the token before resuming.
atsf4g-go ActorExecutor and token multi-threaded scheduling diagramatsf4g-go ActorExecutor and token multi-threaded scheduling diagram

Three additional guardrails apply in the implementation:

  • Runtime ownership check: mutations to router objects or player data validate the bound actor via ActorExecutor.CheckActorExecutor(ctx) to catch cross-actor access bugs.
  • Queue and turn bounds: each ActorExecutor caps queued tasks at actor_max_pending_count (returning EN_ERR_ACTOR_MAX_PENDING_COUNT when exceeded) and limits actions processed per worker turn to actor_max_loop_count so one hot actor cannot starve a worker.
  • Actorless tasks: stateless global or system tasks can opt in via AllowNoActor() and run directly on AppInstance.PushAction.

Transport Baseline and Ongoing Work​

The completed libatbus-go library was benchmarked with the full protocol stack on the same dedicated Linux host as C++ libatbus: unencrypted, uncompressed single-pair TCP reaches 919.2K msg/s (200 B) and 1.91 GB/s (300 KB), and 1000-node fan-in sustains 1.14M msg/s (200 B) and 2.43 GB/s (300 KB). See libatbus-go Benchmark for cross-platform numbers, single-core and CPU-normalized comparisons with C++, GC and memory tuning, and cipher/compression tradeoffs.

libatapp-go connectors, service discovery, routing policies, and atsf4g-go business services remain under active development; see the atsf4g-go repository README for current build and development commands.