photon四种同步方式_Photon——主从服务器负载均衡及策略

Extending Lite 扩展Lite

Persistency is currently not covered in the SDKs we provide. None of our applications saves any data. Every game and application is different and on a high performance server solution, you probably want to control this aspect yourself.

持久性是目前没有包含在我们提供的sdk里。我们没有应用程序要保存任何数据。在高性能服务器解决方案中每个游戏和应用程序都是不同的,你可能想要控制这个方面通过你自己。

You are free to use any of the many professional solutions developed in C#. As example, take a look at:

NHibernate: Mature, open source object-relational mapper for the .NET framework

Membase: Distributed key-value database management system

CSharp-SQLite: SQL database in a local file

Lightspeed: High performance .NET domain modeling and O/R mapping framework

你可以自由的使用任何专业的基于C#的开发解决方案。例如:

NHibernate:成熟的,开放源的对象关系映射器的

Membase:分布式数据库键值管理系统

CSharp-SQLite:SQL数据库在一个本地文件

Lightspeed:高性能建模和O/R映射框架

Trigger Game-Logic In Intervals 在时间间隔触发游戏逻辑

If you want your server application to execute some logic in intervals, add this as method into LiteGame and schedule a message for the room. By using a message, the method call will be in sequence with any operations (avoiding threading issues).In the Lite Lobby Application’s LiteLobbyRoom.cs we used this code:

如果你想让你的服务器应用程序在时间间隔内执行某些逻辑,添加这个方法到LiteGame和安排房间的消息。通过使用一个消息,方法调用将带着任何操作入队 (避免线程问题)。在Lite Lobby应用程序的LiteLobbyRoom.cs中我们使用这些代码:

/// Schedules a broadcast of all changes.

private void SchedulePublishChanges()

{

var message = new RoomMessage((byte)LobbyMessageCode.PublishChangeList);

this.schedule = this.ScheduleMessage(message, LobbySettings.Default.LobbyUpdateIntervalMs);

}

/// Initializes a new instance of the LiteLobbyRoom class.

public LiteLobbyRoom(string lobbyName)

: base(lobbyName)

{

this.roomList = new Hashtable();

this.changedRoomList = new Hashtable();

// schedule sending the change list

this.SchedulePublishChanges();

}

/// Sends the change list to all users in the lobby and then clears it.

private void PublishChangeList()

{

//do something in intervals...

//schedule the next call!

this.SchedulePublishChanges();

}

As you can see, at the end ofPublishChangeListthe next call is scheduled explicitly.

我们可以看到,在PublishChangeList 的最后安排了下一个调用。

Client Connection Handling 客户端连接处理

Client side, Photon is built to give you as much control as possible. This makes sure it integrates well with your game loop.It also requires some attention to avoid inexplicable disconnects (see also “Connections and Timeouts” inBasic Concepts). The following info should enable you to avoid them.

客户端,Photon给予你更多可能的控制。这确保了它很好的集成你的游戏循环。它还需要关注避免一些异常的断开。下面的信息可以帮助你避免他们。

Keep Calling Service 保持调用服务

To include Photon in your client’s game loop, you basically just have to call Service regularly. Regularly means between 10 to 50 times per second (depending on your game / network usage).

在你的游戏客户端中包含Photon,你只需要定期调用服务。大概是每秒10到50次。

Service covers two tasks:

Received events and data are executed. This is done when you can handle the updates. As a sequence order is always kept intact, everything that the client receives is queued and ordered. Service calls DispatchIncomingCommands for this task.

Outgoing data of your client is sent to the server. This includes acknowledgements (created in the background) which are important to keep connection to the server. Service internally calls SendOutgoingCommands to do this task. Controlling the frequency of SendOutgoingCommands calls controls the number of packages you use to send a client’s produced data.

服务涵盖2个任务:

接收被执行的事件和数据,当你处理更新的时候进行。作为一个顺序序列总是保持完好。客户端接收到的所有东西是被排序和队列化的。服务调用DispatchIncomingCommands完成这个任务

你的客户端发送传出数据给服务端。这包括确认保持着服务端的连接。服务在内部调用SendOutgoingCommands 完成这个任务。控制调用SendOutgoingCommands控制发送客户端产生数据包数量的频率

Profiling Service Calls 剖析服务调用

To detect if you called Service regularly, we added a statistics module to the client APIs.

如果你定期调用服务去检测,我们添加了一个模块到客户端API中。

If you encounter disconnects, check these values first:The PhotonPeer.TrafficStatsGameLevel track how often you call DispatchIncomingCommands and SendOutgoingCommands when you turn the stats on (PhotonPeer.TrafficStatsEnabled = true). Check the values of LongestDeltaBetweenSending and LongestDeltaBetweenDispatching.

如果你发生了断开,首先检查这些值:当你打开统计时,TrafficStatsGameLevel 跟踪DispatchIncomingCommands和SendOutgoingCommands的调用,检查LongestDeltaBetweenSending和LongestDeltaBetweenDispatching的值。

This feature is implemented in C# based libraries and Android currently. More platforms will get this soon. PUN has a GUI component for this: PhotonStatsGui.

这个特性是用c#的基础库和Android实现的。更多的平台将很快也能实现这个。PUN有一个GUI组件:PhotonStatsGui。

Platform Specific Info 平台特定的信息

Unity3d and PUN

The Photon Unity Networking package implements the Service calls for you: PhotonHandler.Update calls Service in intervals.However, Unity won’t call Update while it’s loading scenes (or maybe even any assets).

Photon Unity 网络通信包为你实现服务的调用:PhotonHandler.Update定期调用服务。然而,Unity不会调用更新在加载场景的时候。

To keep the connection while loading scenes, you should set PhotonNetwork.IsMessageQueueRunning = false.

在加载场景的时候要保持连接,你必须设置PhotonNetwork.IsMessageQueueRunning为false

Pausing the message queue has two effects:

A background Thread will be used to call SendOutgoingCommands while Update is not called. This keeps the connection alive, sending acknowledgements only but no events or operations (RPCs or sync updates). Incoming data is not executed by this Thread.

All incoming updates are queued. Neither RPCs are called, nor are observed objects updated. While you change the level, this avoids calling RPCs in the previous one.

暂停消息队列有2个效果:

后台线程被用于调用SendOutgoingCommands时更新未被调用。这个保证了连接,发送确认但没有事件或操作。在这个线程里传入数据不被执行。

所有的传入更新被排队。RPCs被调用。也不是查看对象的更新,当你改变了级别时,这避免了调用RPCs在前面一个。

Unity3d

If you use the “plain” from our Unity Client SDKs, you implemented Service most likely in some MonoBehaviour Update method.To make sure Photon’s SendOutgoingCommands is called while you load scenes, implement a background Thread. This Thread should pause 100 or 200 ms between each loop, so it does not take away all performance.

如果你使用了Unity客户端SDK包中的plain,在一些MonoBehaviour Update 方法中你实现服务。去确保在你加载场景的时候Photon的SendOutgoingCommands被调用。现实一个后台线程。这个线程在循环间暂停100或200毫秒,所以它不会影响性能。

Application - LoadBalancing 负载均衡应用

This article explains the server-side implementation of the LoadBalancing application.

本文解释服务端是如何实现LoadBalancing应用程序的。

Content 目录

Concept 概念

Basic Workflow 基本工作流

Master Server 主服务器

Master: Handling Client Peers 处理客户端用户

Master: Handling Game Server Peers 处理游戏服务端用户

Game Server 游戏服务器

Game Server: Handling Client Peers 处理客户端用户

Game Server: Report

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值