This is a demo project showcasing a high-performance TCP/UDP game server built with Go and cgo. It includes a server, simulator, and stress testing tool for development and evaluation. It also provides a RESTful service that exposes two RPC methods to view the server status and metrics.
git clone --recurse-submodules https://github.com/wanliqun/cgo-game-server.git
This downloads the required submodule ( C++ Random Name Generator ) automatically.
Requirements:
- automake
- clang++
make cgo
This generates a .so
dynamic link library used by cgo.
Install Go (v1.21+) and edit the configuration file (config/config.yml) for customization, then run:
go run main.go --help
This displays usage instructions and available commands.
- Start Server (TCP, UDP, RESTful):
go run main.go server
- Start Simulator (client for debugging):
go run main.go simulator
- Stress Testing:
Establish Mass Connections and Measure TPS:
go run main.go loadrunner -w 100 -r 100 -d 1h
-w: Number of concurrent workers (go-routines) -r: Robots (clients) allocated per worker -d: Duration of the test
cgo-game-server
starts a RESTful service which provides two RPC methods to view the server status and metrics. eg., You can open the following URL in a web browser to check the server running statistics if you are running as predefined configurations:
- Server status: http://127.0.0.1:8787/status
- RPC metrics: http://127.0.0.1:8787/metrics
The following projects are referenced: