All Projects → mafei198 → Gos

mafei198 / Gos

Licence: mit
基于Go语言的分布式游戏服务器框架,通讯协议:WebSocket、TCP,消息协议:JSON、Protobuf、二进制

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Gos

Training
Container, Monitoring & Logging, Cloud & DevOps Tutorials and Labs
Stars: ✭ 121 (-17.69%)
Mutual labels:  k8s
Eunomia
A GitOps Operator for Kubernetes
Stars: ✭ 130 (-11.56%)
Mutual labels:  k8s
Kathara
A lightweight container-based network emulation system.
Stars: ✭ 139 (-5.44%)
Mutual labels:  k8s
Ingress Merge
Merge Ingress Controller for Kubernetes
Stars: ✭ 124 (-15.65%)
Mutual labels:  k8s
Kazan
Kubernetes API client for Elixir
Stars: ✭ 129 (-12.24%)
Mutual labels:  k8s
K8sh
A simple, easily extensible shell for navigating your kubernetes clusters
Stars: ✭ 136 (-7.48%)
Mutual labels:  k8s
K8s Istio Observe Backend
Go-based microservices reference platform for demo of k8s observability with Istio
Stars: ✭ 121 (-17.69%)
Mutual labels:  k8s
Taro Mall
一个项目的架构,包括设计/前端/管理后台/后端/k8s集群架构,欢迎Star,欢迎Fork
Stars: ✭ 144 (-2.04%)
Mutual labels:  k8s
Arkade
Open Source Kubernetes Marketplace
Stars: ✭ 2,343 (+1493.88%)
Mutual labels:  k8s
Awesome Cka
☸️ A curated list for awesome resources needed to pass your Certified Kubernetes Administrator (CKA) exam.
Stars: ✭ 138 (-6.12%)
Mutual labels:  k8s
K8s
Deploying Kubernetes High Availability Cluster with Ansible Playbook
Stars: ✭ 125 (-14.97%)
Mutual labels:  k8s
K8s
Kubernetes Helm Charts for the ORY ecosystem.
Stars: ✭ 127 (-13.61%)
Mutual labels:  k8s
Nice Knowledge System
📚不积跬步无以至千里,每天进步一点点,Passion,Self-regulation,Love and Share
Stars: ✭ 137 (-6.8%)
Mutual labels:  k8s
Elasticctr
ElasticCTR,即飞桨弹性计算推荐系统,是基于Kubernetes的企业级推荐系统开源解决方案。该方案融合了百度业务场景下持续打磨的高精度CTR模型、飞桨开源框架的大规模分布式训练能力、工业级稀疏参数弹性调度服务,帮助用户在Kubernetes环境中一键完成推荐系统部署,具备高性能、工业级部署、端到端体验的特点,并且作为开源套件,满足二次深度开发的需求。
Stars: ✭ 123 (-16.33%)
Mutual labels:  k8s
Tcpgoon
tcpgoon, maximum TCP connections tester
Stars: ✭ 141 (-4.08%)
Mutual labels:  goroutine
Gitwebhookproxy
A proxy to let webhooks reach running services behind a firewall – [✩Star] if you're using it!
Stars: ✭ 123 (-16.33%)
Mutual labels:  k8s
Ansible Role K3s
Ansible role for installing k3s as either a standalone server or HA cluster.
Stars: ✭ 132 (-10.2%)
Mutual labels:  k8s
K9s
🐶 Kubernetes CLI To Manage Your Clusters In Style!
Stars: ✭ 14,585 (+9821.77%)
Mutual labels:  k8s
Faas Netes
Serverless on Kubernetes with OpenFaaS
Stars: ✭ 1,875 (+1175.51%)
Mutual labels:  k8s
Apisix Ingress Controller
ingress controller for K8s
Stars: ✭ 139 (-5.44%)
Mutual labels:  k8s

#项目状态 开发中

简介

《GOS》是一款基于Go语言的分布式游戏服务器框架,通过与k8s结合实现高可用、动态伸缩、在线扩容的特性,可应用于市面上绝大多数游戏类型:SLG、RPG、ARPG、MMO等。

结构图

Architecture

结构详解

  • World(世界服务)
    • 职责:
      1. 提供账户注册、登陆
      2. 为玩家分配合适的游戏服务(Game)
    • 简介:
      1. k8s无状态集群服务
      2. 通过k8s提供一个无状态的service,提供集群内访问
  • Game(游戏服务)
    • 职责:
      1. 处理玩家请求,游戏逻辑的主要发生地
      2. 加载、持久化玩家、场景信息至数据库
      3. 广播管理:订阅、取消订阅
    • 简介:
      1. k8s有状态集群服务
      2. 每个Game对应一个k8s的Pod,服务于一个或多个场景

基础工具集

  • 分布式服务健康监测
  • GenServer:类似于Erlang的gen_server,封装了Groutine的基本启动、查找、消息同步/异步发送
  • 协议生成器:根据YAML生成客户端与服务器的通信协议
  • 路由管理:根据YAML文件生成路由协议,玩家请求自动分发至相应Controller进行处理
  • 热数据管理:按需加载玩家数据,并定时持久化至MySQL
  • MySQL管理:基于Rails的ActiveRecord进行migration管理,并生成Go的ORM文件
  • 定时任务:定时触发器,由redis持久化
  • 配置数据生成工具:解析excel表格生成对应的配置表
  • 排行榜服务:自定义各种排行榜,根据积分排名,可设置每个玩家自定义信息
  • 推送消息:苹果、谷歌(FCM)
  • 支付验证:苹果、谷歌

Setup gos

# 克隆项目
git checkout https://github.com/mafei198/gos.git

# 安装gRPC
brew install protobuf
go get -u google.golang.org/grpc
go get -u github.com/golang/protobuf/protoc-gen-go

# 设置执行路径
export PATH=$PATH:$GOPATH/bin

# 安装nodejs
brew install node

# 安装python
brew install python

# 安装mongo
brew install mongo

# 安装redis
brew install redis

# 安装Excel解析
pip3 install xlrd

# 初始化项目
make setup

Setup k8s

#安装Helm
  brew install kubernetes-helm

#部署Redis
  kubectl apply -f k8s/deps/redis/redis-cluster.yaml
  kubectl exec -it redis-cluster-0 -- redis-cli --cluster create --cluster-replicas 1 \
  $(kubectl get pods -l app=redis-cluster -o jsonpath='{range.items[*]}{.status.podIP}:6379 ')

#部署Mysql
  helm install stable/mysql --name single-mysql

#部署Ingress-nginx
  helm install stable/nginx-ingress --name nginx-ingress

#部署ServicePerPod
  # Create metacontroller namespace.
  kubectl create namespace metacontroller
  # Create metacontroller service account and role/binding.
  kubectl apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/metacontroller/master/manifests/metacontroller-rbac.yaml
  # Create CRDs for Metacontroller APIs, and the Metacontroller StatefulSet.
  kubectl apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/metacontroller/master/manifests/metacontroller.yaml  

  kubectl create configmap service-per-pod-hooks -n metacontroller --from-file=k8s/deps/service-per-pod/hooks
  kubectl apply -f k8s/deps/service-per-pod/service-per-pod.yaml
  

#部署游戏服务
  kubectl apply -f k8s/deployments/game-deployment.yaml
  kubectl apply -f k8s/deployments/world-service.yaml

消息结构

length | reqId | protocol | payload

length:

desc: 消息长度
type: int32

reqId:

desc: 请求编号
type: int32

protocol:

desc: 消息名字
type: uint16

payload:

desc: 消息内容
type: byte[]

TODO

FAQ

1.玩家在连接服务上的分配规则?

  • 分配规则:
    1. 直接将玩家分配到负载最低的连接服务

2.玩家在游戏服务上的分配规则?

  • 典型案例:根据游戏场景分布玩家
    1. MMO/SLG/RPG-场景:区服地图、跨服战地图
    2. MOBA/RTS/棋牌-场景: 区服大厅、对战房间
  • 内部处理逻辑:
    1. GameMgr根据玩家SceneId分配到对应Game的Scene

3.冷热数据如何管理?

  • 热数据类型有哪些?

    • 玩家热数据
      • 比如:玩家角色相关信息、个人信息
      • 玩家热数据随着玩家在服务间的迁移而迁移
    • 场景热数据
      • 比如:场景相关的信息
    • 世界热数据
      • 比如:排行榜、服务拓扑图

    注:

    1. 玩家、场景热数据由玩家当前所在场景管理
    2. 世界热数据由Redis托管
  • 冷热数据管理概述

    • HotData <-> RDS

    • HotData:玩家、场景、世界热数据

      • 职责:
        1. 热数据加载与定时回写,以及玩家下线回写
        2. 限制内存使用上限
        3. 使用LRU算法清理长时间未使用的玩家数据
    • RDS:冷数据存储

    • 关于RDS的选择: 首先根据在线玩家数量和玩家热数据持久化频率做预估,假设游戏有10w在线玩家,每个玩家平均隔5分钟进行一次数据存储,那么平均 TPS = 10w / 300s = 333

4.广播如何管理? 主动订阅自己感兴趣的事件

5.定时任务在哪里进行处理? 根据玩家SceneId,在对应场景处理

6.服务器间通信

  • RPC:
    • 技术选型:GRPC
    • 延迟不敏感、交互频率不高的场景
  • TCP:
    • 延迟敏感,交互频繁的场景

License

GOS is under The MIT License (MIT)

Copyright (c) 2018-2028 Savin Max [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].