Sign In Register

How can we help you today?

Start a new topic
Answered

.AuthenticatedConnectRequest slows down game

Note: my implementation is in Cocos2d-x with the Cocos2d-x SDK.


Since implementing GameSparks, I've noticed that the initial connection process causes a noticeable lag in the title screen of the game. Even if I don't implement my own authentication logic and just follow the SDK example in applicationDidFinishLaunching(), the initial handshake and authentication causes the screen to freeze for about a half second. Since the title screen is animated, it causes a distracting effect. This is reproducible every time, and always happens at the same point in the debug output:


 

Connected to: wss://preview.gamesparks.net/ws/M298830ESq3m
[GameSparks]: WebSocket callback: {"@class": ".AuthenticatedConnectResponse","connectUrl": "wss://gsp-aeu000-se06.gamesparks.net/ws/M298830ESq3m","requestId": "0"}
[GameSparks]: Received new connection url from gamesparks backend. Establishing new connection now.
[GameSparks]: Create new connection
easywsclient: connecting: host=gsp-aeu000-se06.gamesparks.net port=443 path=/ws/M298830ESq3m
[GameSparks]: Handle authentication connect response with immediate handshake
Connected to: wss://gsp-aeu000-se06.gamesparks.net/ws/M298830ESq3m
[GameSparks]: WebSocket callback: {"@class":".AuthenticatedConnectResponse","nonce":"39438132-9e7d-4652-9c62-fee90869005b","requestId":"0"}
[GameSparks]: Handle authentication connect response with immediate handshake
/*NOTE: The lag/freeze always happens right here. */
[GameSparks]: Send immediate request: {
	"@class":	".AuthenticatedConnectRequest",
	"hmac":	"atRWZux9JI9koeaWtR5OHhv8j1nUf3jk/NK47FkTFOE=",
	"os":	"IOS",
	"platform":	"IOS",
	"deviceId":	"8F16C40A-DD34-4140-A58F-57A94EF85EB5",
	"authToken":	"adc4a654-bed5-4604-ba86-90a876e91c3f"
}
[GameSparks]: Handshake request sent
[GameSparks]: WebSocket callback: {"@class":".AuthenticatedConnectResponse","authToken":"3c248c3b-ff5c-4342-9d7b-c153319b1c91","requestId":"0","sessionId":"39438132-9e7d-4652-9c62-fee90869005b","userId":"5746604ef528a1ccf4a4d21f"}
[GameSparks]: Received auth token
[GameSparks]: Handle authentication connect response with immediate handshake

 

I marked the spot where the output freezes (along with the screen) before resuming.


Because this function appears to be internally called by the SDK (I think...I don't really understand this part, it assigns a userID but I guess it's independent of the IDs that I see in my player database?), I don't know if there's any way to assign this process to another thread, is there? I know the SDK isn't thread safe, and I can't find a safe way to isolate this specific call. 


Does anyone have any thoughts or input? Is a lag during the initial authentication normal?


Best Answer

Hi Matthew,


I've been looking into this issue for you but haven't been able to replicate the lag just yet.


You mentioned that you included the authentication in the AppDelegate class, in the same way that it's done in the Sample. Might I suggest some alternatives while I investigate this issue further?


1 - Separate the GameSparks connection and authentication into it's own object or layer, Initialize the first connection between a loading screen or during a non-visual intensive part of the game.

2 - Don't show your graphics until GameSparks has connected for the first time. If you still find you're getting significant lag through normal requests, then I'll get onto the tech team here and try to dig deeper into the issue.


Hopefully I can get back to you with some more information, but see if any of those work for you.


-Pádraig


Hi Matthew,


We'll investigate this issue for you.


Thanks,


Oisin

Answer

Hi Matthew,


I've been looking into this issue for you but haven't been able to replicate the lag just yet.


You mentioned that you included the authentication in the AppDelegate class, in the same way that it's done in the Sample. Might I suggest some alternatives while I investigate this issue further?


1 - Separate the GameSparks connection and authentication into it's own object or layer, Initialize the first connection between a loading screen or during a non-visual intensive part of the game.

2 - Don't show your graphics until GameSparks has connected for the first time. If you still find you're getting significant lag through normal requests, then I'll get onto the tech team here and try to dig deeper into the issue.


Hopefully I can get back to you with some more information, but see if any of those work for you.


-Pádraig

Pádraig,


Thanks very much for this advice. I already figured I would need to do this. During normal requests, there is no lag at all and the service performs at an amazing level. It's only upon initial connect at app launch (or app resume) that there's a brief lag. It may be more noticeable for me because my title screen features a lot of animation, so I'll work on implementing some form of loading screen that will disappear whenever the connection is completed. 

Hi Matthew,


Glad to hear. It's hard to get 100% away from lag but luckily Gamesparks uses Websockets which means that there is only one connection needed, that will be kept open throughout the game session (instead of constantly having to connect, authenticate and send/recieve data like REST ).


If you have any more questions feel free to let me know.


-Pádraig

Login to post a comment