个人网站建设作用,利用电脑做网站,济南全包圆装修400电话,wordpress禁止外链背景介绍
open-match是Google和unity联合开源的支持实时多人匹配的框架#xff0c;已有多家游戏厂商在生产环境使用#xff0c;官网 https://open-match.dev/site/ 。原本我们使用的是UOS上提供的匹配能力#xff0c;但是UOS目前不支持自建的Dedicated servers 集群#x…
背景介绍
open-match是Google和unity联合开源的支持实时多人匹配的框架已有多家游戏厂商在生产环境使用官网 https://open-match.dev/site/ 。原本我们使用的是UOS上提供的匹配能力但是UOS目前不支持自建的Dedicated servers 集群只能上传镜像UOS会自动完成分配以及创建灵活性就不是那么高了按照open-match的官方教程需要有k8s的环境。但是小公司就是不想要k8s我就想单机部署可以使用docker-compose。open-match本身的镜像build 提供了dockerfile文件。把项目clone到本地然后在 tm中以此使用以下命令构建对用的image
tip:该方案只是启动了 core 部分要求的组件即
搭建步骤
Install with YAML | Open Match 后面的部分需要自行探索了现在也在学习中欢迎交流讨论
先构建一个中间镜像base builder然后一次构建对应的component即可需要修改Dockerfile.cmd中的
FROM open-match-base-build as builder
为目的是指定使用本地的version版本否则会远程拉取镜像网络问题会导致不成功需要开梯子
FROM open-match-base-build:latest as builder
docker build -f .\Dockerfile.base-build -t open-match-base-build .
docker build --build-arg IMAGE_TITLEsynchronizer -f .\Dockerfile.cmd -t open-match-synchronizer .
接着使用docker-compose.yaml 来控制启动过程内如如下
version: 3
services:open-match-backend:image: open-match-backend:latestcontainer_name: open-match-backendvolumes:- ./matchmaker_config_default.yaml:/app/matchmaker_config_default.yaml- ./matchmaker_config_override.yaml:/app/matchmaker_config_override.yamlports:- 50505:50505 # gRPC- 51505:51505 # HTTPenvironment:API_BACKEND_HOSTNAME: open-match-backendAPI_BACKEND_GRPC_PORT: 50505API_BACKEND_HTTP_PORT: 51505REDIS_HOSTNAME: open-match-redisREDIS_PORT: 6379depends_on:- redisopen-match-frontend:image: open-match-frontend:latestcontainer_name: open-match-frontendports:- 50504:50504 # gRPC- 51504:51504 # HTTPvolumes:- ./matchmaker_config_default.yaml:/app/matchmaker_config_default.yaml- ./matchmaker_config_override.yaml:/app/matchmaker_config_override.yamlenvironment:API_FRONTEND_HOSTNAME: open-match-frontendAPI_FRONTEND_GRPC_PORT: 50504API_FRONTEND_HTTP_PORT: 51504REDIS_HOSTNAME: open-match-redisREDIS_PORT: 6379depends_on:- redisopen-match-query:image: open-match-query:latestcontainer_name: open-match-queryports:- 50503:50503 # gRPC- 51503:51503 # HTTPenvironment:API_QUERY_HOSTNAME: open-match-queryAPI_QUERY_GRPC_PORT: 50503API_QUERY_HTTP_PORT: 51503REDIS_HOSTNAME: open-match-redisREDIS_PORT: 6379volumes:- ./matchmaker_config_default.yaml:/app/matchmaker_config_default.yaml- ./matchmaker_config_override.yaml:/app/matchmaker_config_override.yamldepends_on:- redisopen-match-synchronizer:image: open-match-synchronizer:latestcontainer_name: open-match-synchronizervolumes:- ./matchmaker_config_default.yaml:/app/matchmaker_config_default.yaml- ./matchmaker_config_override.yaml:/app/matchmaker_config_override.yamlports:- 50506:50506 # gRPC- 51506:51506 # HTTPenvironment:API_SYNCHRONIZER_HOSTNAME: open-match-synchronizerAPI_SYNCHRONIZER_GRPC_PORT: 50506API_SYNCHRONIZER_HTTP_PORT: 51506REDIS_HOSTNAME: open-match-redisREDIS_PORT: 6379depends_on:- redisopen-match-swaggerui:image: open-match-swaggerui:latestcontainer_name: open-match-swaggeruiports:- 51500:51500 # HTTP for Swagger UIvolumes:- ./matchmaker_config_default.yaml:/app/matchmaker_config_default.yaml- ./matchmaker_config_override.yaml:/app/matchmaker_config_override.yamlenvironment:API_SWAGGERUI_HOSTNAME: open-match-swaggeruiAPI_SWAGGERUI_HTTP_PORT: 51500depends_on:- open-match-backend- open-match-frontend- open-match-query- open-match-synchronizerredis:image: redis:alpinecontainer_name: open-match-redisports:- 6379:6379volumes:- redis-data:/datavolumes:redis-data:matchmaker_config_default.yaml 的内容和 matchmaker_config_override.yaml的内容是一致的目的就是override可以覆盖default中的值猜的这部分内容从k8s的yaml文件中copy过来内容如下
logging:level: debugformat: textrpc: false
# Open Match applies the exponential backoff strategy for its retryable gRPC calls.
# The settings below are the default backoff configuration used in Open Match.
# See https://github.com/cenkalti/backoff/blob/v3/exponential.go for detailed explanations
backoff:# The initial retry interval (in milliseconds)initialInterval: 100ms# maxInterval caps the maximum time elapsed for a retry intervalmaxInterval: 500ms# The next retry interval is multiplied by this multipliermultiplier: 1.5# Randomize the retry intervalrandFactor: 0.5# maxElapsedTime caps the retry time (in milliseconds)maxElapsedTime: 3000msapi:backend:hostname: open-match-backendgrpcport: 50505httpport: 51505frontend:hostname: open-match-frontendgrpcport: 50504httpport: 51504query:hostname: open-match-querygrpcport: 50503httpport: 51503synchronizer:hostname: open-match-synchronizergrpcport: 50506httpport: 51506swaggerui:hostname: open-match-swaggeruihttpport: 51500# Configurations for api.test and api.scale are used for testing.test:hostname: open-match-testgrpcport: 50509httpport: 51509scale:httpport: 51509redis:# Open Matchs default Redis setupshostname: open-match-redis# source value: open-match-core.redis.port 6379port: 6379usePassword: falsepasswordPath: /redis-passwordpool:maxIdle: 200maxActive: 0idleTimeout: 0healthCheckTimeout: 300mstelemetry:reportingPeriod: 1mtraceSamplingFraction: 0.01zpages:enable: trueprometheus:enable: falseendpoint: /metricsserviceDiscovery: truestackdriverMetrics:enable: falsegcpProjectId: replace_with_your_project_idprefix: open_match
然后就可以启动了 运行demo
如果要运行open-match的 demo-first-match还要一个组件
evaluator
该组件的目的是对所有的matches进行评估并返回得分open-match会保留评分最高的组合比如我们以 战力相差的相近为评估规则假定 abc三个玩家的战力分值分配时 10 20 25则abc三人同时匹配在1v1的条件选应当尽可能的选择20 25这个相近的评分评分组件evaluator这个需要开始自行实行通过synchronizer进行调用open-match 提供了一个default实现 即default-evaluator使用以下命令进行构建即可
docker build --build-arg IMAGE_TITLEdefault-evaluator -f .\Dockerfile.cmd -t open-match-default-evaluator .
如果开发环境存在需要平凡需求的情况直接ide环境启动即可但是需要在 matchmaker_config_default.yaml中指明 evaluator的位置信息
api:evaluator:hostname: open-match-default-evaluatorhttpport: 5499grpcport: 5498
接着需要修改几个demo的hostname地址一个是frontend的hostname位置在
open-match/examples/demo/components/clients/clients.go:84
//修改前
conn, err : grpc.Dial(open-match-frontend.open-match.svc.cluster.local:50504, grpc.WithInsecure())//修改后
conn, err : grpc.Dial(localhost:50504, grpc.WithInsecure())
另外一个是 backend的hostname
open-match/examples/demo/components/director/director.go:71
//修改前
conn, err : grpc.Dial(open-match-backend.open-match.svc.cluster.local:50505, grpc.WithInsecure())//修改后
conn, err : grpc.Dial(localhost:50505, grpc.WithInsecure())
然后还需要部署一个组件mmf负责判断给定的组合是否符合要求可以直接启动 cmd/scale-mmf或者build镜像一样的需要修改query的hostname位置信息如下
open-match/examples/scale/mmf/mmf.go:42
//修改前
conn, err : grpc.Dial(open-match-query.open-match.svc.cluster.local:50503, utilTesting.NewGRPCDialOptions(logger)...)//修改后
conn, err : grpc.Dial(localhost:50503, utilTesting.NewGRPCDialOptions(logger)...)
mmf的服务地址是由director在fetchMatches指定的相关的代码位置在
open-match/examples/demo/components/director/director.go:82
不同版本可能会有所变化当前提及的代码内容来源于open-match的最新master代码2024年10月9日
req : pb.FetchMatchesRequest{Config: pb.FunctionConfig{Host: om-function.open-match-demo.svc.cluster.local,Port: 50502,Type: pb.FunctionConfig_GRPC,},Profile: pb.MatchProfile{Name: 1v1,Pools: []*pb.Pool{{Name: Everyone,},},},}所以我们需要改掉这里Host所指定的值修改为mmf的实际地址即可最后更新docker-compose.yaml并执行 docker-compose -f docker-compose.yaml up在cmd/demo-first-match/main.go 文件中运行main函数即可成功运行demo程序
demo程序的执行成功后会返回一个虚拟的链接地址该链接地址由director组件返回可以理解为在director中返回具体的dedicated server的ip地址demo中是随机产生的代码位置在
examples/demo/components/director/director.go:132
如果不正确可以搜索2222作为线索定位 for _, match : range matches {ids : []string{}for _, t : range match.Tickets {ids append(ids, t.Id)}req : pb.AssignTicketsRequest{Assignments: []*pb.AssignmentGroup{{TicketIds: ids,Assignment: pb.Assignment{Connection: fmt.Sprintf(%d.%d.%d.%d:2222, rand.Intn(256), rand.Intn(256), rand.Intn(256), rand.Intn(256)),},},},}resp, err : be.AssignTickets(ds.Ctx, req)if err ! nil {panic(err)}_ resp}
匹配成功后返回的链接地址 open-match对mmf,evaluator,director 提供了多种游戏场景的默认实现可以在亦有模板的基础上结合业务进行开发具体内容可以查看examples/scale/README.md
感觉联机几千人同时在线这种方式应该够够吧先这样散会
补一张open-match 时序图看懂这个业务开发层面知道各个component的职责范围
文章转载自: http://www.morning.qzqjz.cn.gov.cn.qzqjz.cn http://www.morning.llthz.cn.gov.cn.llthz.cn http://www.morning.slkqd.cn.gov.cn.slkqd.cn http://www.morning.zdsdn.cn.gov.cn.zdsdn.cn http://www.morning.krdmn.cn.gov.cn.krdmn.cn http://www.morning.wnjrf.cn.gov.cn.wnjrf.cn http://www.morning.jkmjm.cn.gov.cn.jkmjm.cn http://www.morning.llxyf.cn.gov.cn.llxyf.cn http://www.morning.dhrbj.cn.gov.cn.dhrbj.cn http://www.morning.krdxz.cn.gov.cn.krdxz.cn http://www.morning.mlmwl.cn.gov.cn.mlmwl.cn http://www.morning.cniedu.com.gov.cn.cniedu.com http://www.morning.ykrg.cn.gov.cn.ykrg.cn http://www.morning.rbffj.cn.gov.cn.rbffj.cn http://www.morning.msbmp.cn.gov.cn.msbmp.cn http://www.morning.zbmcz.cn.gov.cn.zbmcz.cn http://www.morning.xphcg.cn.gov.cn.xphcg.cn http://www.morning.ksjnl.cn.gov.cn.ksjnl.cn http://www.morning.nd-test.com.gov.cn.nd-test.com http://www.morning.kxqwg.cn.gov.cn.kxqwg.cn http://www.morning.snnwx.cn.gov.cn.snnwx.cn http://www.morning.rmryl.cn.gov.cn.rmryl.cn http://www.morning.crfyr.cn.gov.cn.crfyr.cn http://www.morning.dcpbk.cn.gov.cn.dcpbk.cn http://www.morning.rfrnc.cn.gov.cn.rfrnc.cn http://www.morning.heleyo.com.gov.cn.heleyo.com http://www.morning.dkqbc.cn.gov.cn.dkqbc.cn http://www.morning.xwzsq.cn.gov.cn.xwzsq.cn http://www.morning.qytby.cn.gov.cn.qytby.cn http://www.morning.mhxlb.cn.gov.cn.mhxlb.cn http://www.morning.rjtmg.cn.gov.cn.rjtmg.cn http://www.morning.bklkt.cn.gov.cn.bklkt.cn http://www.morning.mnnxt.cn.gov.cn.mnnxt.cn http://www.morning.tlfyb.cn.gov.cn.tlfyb.cn http://www.morning.mxtjl.cn.gov.cn.mxtjl.cn http://www.morning.xhjjs.cn.gov.cn.xhjjs.cn http://www.morning.zfgh.cn.gov.cn.zfgh.cn http://www.morning.mhdwp.cn.gov.cn.mhdwp.cn http://www.morning.jmlgk.cn.gov.cn.jmlgk.cn http://www.morning.jqllx.cn.gov.cn.jqllx.cn http://www.morning.lwgsk.cn.gov.cn.lwgsk.cn http://www.morning.plydc.cn.gov.cn.plydc.cn http://www.morning.lffgs.cn.gov.cn.lffgs.cn http://www.morning.qyxnf.cn.gov.cn.qyxnf.cn http://www.morning.rjnm.cn.gov.cn.rjnm.cn http://www.morning.qhfdl.cn.gov.cn.qhfdl.cn http://www.morning.gccrn.cn.gov.cn.gccrn.cn http://www.morning.fbmjl.cn.gov.cn.fbmjl.cn http://www.morning.sxmbk.cn.gov.cn.sxmbk.cn http://www.morning.bztzm.cn.gov.cn.bztzm.cn http://www.morning.dnbhd.cn.gov.cn.dnbhd.cn http://www.morning.ryxbz.cn.gov.cn.ryxbz.cn http://www.morning.krywy.cn.gov.cn.krywy.cn http://www.morning.srgbr.cn.gov.cn.srgbr.cn http://www.morning.dmtwz.cn.gov.cn.dmtwz.cn http://www.morning.fsrtm.cn.gov.cn.fsrtm.cn http://www.morning.yhpq.cn.gov.cn.yhpq.cn http://www.morning.lmfmd.cn.gov.cn.lmfmd.cn http://www.morning.bnygf.cn.gov.cn.bnygf.cn http://www.morning.xlpdm.cn.gov.cn.xlpdm.cn http://www.morning.hptbp.cn.gov.cn.hptbp.cn http://www.morning.4q9h.cn.gov.cn.4q9h.cn http://www.morning.gqcd.cn.gov.cn.gqcd.cn http://www.morning.rftk.cn.gov.cn.rftk.cn http://www.morning.hqrr.cn.gov.cn.hqrr.cn http://www.morning.lqpzb.cn.gov.cn.lqpzb.cn http://www.morning.xkyqq.cn.gov.cn.xkyqq.cn http://www.morning.dhyqg.cn.gov.cn.dhyqg.cn http://www.morning.rfjmy.cn.gov.cn.rfjmy.cn http://www.morning.dhpjq.cn.gov.cn.dhpjq.cn http://www.morning.fsrtm.cn.gov.cn.fsrtm.cn http://www.morning.yhywx.cn.gov.cn.yhywx.cn http://www.morning.qgqck.cn.gov.cn.qgqck.cn http://www.morning.paoers.com.gov.cn.paoers.com http://www.morning.btrfm.cn.gov.cn.btrfm.cn http://www.morning.rhlhk.cn.gov.cn.rhlhk.cn http://www.morning.nlwrg.cn.gov.cn.nlwrg.cn http://www.morning.drswd.cn.gov.cn.drswd.cn http://www.morning.bnfrj.cn.gov.cn.bnfrj.cn http://www.morning.bgrsr.cn.gov.cn.bgrsr.cn