Delay of message in the queue
Options
I just begin using Photon, and built a simple server-client program, in which the client is a console and only send message from user input to the server, and the server send the exact content back to client. The client then display the message received from the server.
I used the queue to send the message:
Like below:
Thanks!
I used the queue to send the message:
this.fiber.Enqueue(() => this.peer.OpCustom((byte)OperationCode.LoginOperation, parameter, true));and also the server:
this.fiber.Enqueue(() => this.PhotonPeer.SendEvent(eventData));but seems there is a delay (my guess) in receiving the message?
Like below:
PeerStatusCallBack:Connect :>1 :>2 :>3 Received(0):1 :>4 Received(0):2 Received(0):3 :>5 Received(0):4 :>I only got "Received(0):1" after I have already sent the 3rd message "3". Is it because some message are temperately stored in the buffer queue?
Thanks!
0
Comments
-
IMHO, it can be because of 2 separate reasons:
1. Photon does not send requests/responses immediately. Instead, they are combined in a packet and sent afterwards as a whole. This helps saving bandwidth. So if you send requests quite fast, you will get response after a while. Take a look for following lines in PhotonServer.config file:EnablePerformanceCounters = "true" DataSendingDelayMilliseconds="50" AckSendingDelayMilliseconds="50" MinimumTimeout="5000" MaximumTimeout="10000" ProduceDumps="true" MaxMessageSize="512000" MaxQueuedDataPerPeer="512000" PerPeerMaxReliableDataInTransit="51200" PerPeerTransmitRateLimitKBSec="256" PerPeerTransmitRatePeriodMilliseconds="200"
2. Network latency.0 -
Sergiy wrote:IMHO, it can be because of 2 separate reasons:
1. Photon does not send requests/responses immediately. Instead, they are combined in a packet and sent afterwards as a whole. This helps saving bandwidth. So if you send requests quite fast, you will get response after a while. Take a look for following lines in PhotonServer.config file:EnablePerformanceCounters = "true" DataSendingDelayMilliseconds="50" AckSendingDelayMilliseconds="50" MinimumTimeout="5000" MaximumTimeout="10000" ProduceDumps="true" MaxMessageSize="512000" MaxQueuedDataPerPeer="512000" PerPeerMaxReliableDataInTransit="51200" PerPeerTransmitRateLimitKBSec="256" PerPeerTransmitRatePeriodMilliseconds="200"
2. Network latency.
Thanks for your advice, but I think the 2rd reason may be unlikely, as I test it on the localhost, and what's more, the previous message would not be received and displayed in the console until I send a next message and press enter.
I send the message using the interfacethis.fiber.Enqueue(() => this.peer.OpCustom((byte)OperationCode.ChatOperation, parameter, true)); Console.WriteLine("Msg sent:i={0}",++i);
And receive the message in the event call back functionpublic void EventAction(byte eventCode, System.Collections.Hashtable photonEvent) { ...... String msg = (string)photonEvent[(byte)1]; Console.WriteLine("Received({0}):{1}", i, msg); }
Where i is a global variable to trace the sequence of sending and receiving message. The console information is::>1 Msg sent:i=1 :>2 Msg sent:i=2 :>3 Msg sent:i=3 Received(3):1 Received(3):2 :>4 Msg sent:i=4 Received(4):3 :>5 Msg sent:i=5 Received(5):4 :>
Looks like the receive function "EventAction" is called immediately after the sending function, but it receives the old message instead of what I just input.
Is it because of the queue that cause this asynchronism?
Thanks!0 -
You should call Service() about 10 times/sec in order to allow photon to dispatch incoming/outgoing messages. Are you doing it?0
-
Sergiy wrote:You should call Service() about 10 times/sec in order to allow photon to dispatch incoming/outgoing messages. Are you doing it?0
-
Exactly. Service() should be called constantly during whole lifetime of the application. A good solution would be to use system.timers.timer class with interval of 5-10 ms. That would probably solve your case0
-
Sergiy wrote:Exactly. Service() should be called constantly during whole lifetime of the application. A good solution would be to use system.timers.timer class with interval of 5-10 ms. That would probably solve your case0
-
Make sure to avoid concurrent usage of the peer by multiple threads! Operations and Service calls should never done concurrently.0
-
that means that any code interacting with Photon has to run on the same thread.0
-
Ie. Do this: http://blog.csharplearners.com/tag/locking/0