Big probems. Inconsistent connection issues

Post here your questions about the Objective-C API for SFS2X

Moderators: Lapo, Bax

clam61
Posts: 125
Joined: 12 Sep 2007, 02:00

Big probems. Inconsistent connection issues

Postby clam61 » 02 Feb 2014, 23:31

I am having some real issues with SFS2x

1. A lot of disconnects for users even if they are on wifi.
2. What seems like dropped messages between server and user.

Both of these are random and inconsistent.

I am thinking that maybe...it has something to do with how I am handling connects and disconnects when the app goes into the background.

My first method was to disconnect from the server when the app goes into the background and connect as it comes into the foreground.
I created a new SFS2x Client API object on each connection attempt.

My next method was to create the client api object once and use that each time.

With each method, I experienced both problems listed above, but with each method I experienced more problems, unique to each method. With the first method I would SOMETIMES get into a situation where I would get a connection lost event after a successful connection. Checking the server, I was actually still connected. I am thinking the old client api object still existed in memory and was calling the listener function.

With the second method I get into a situation where I sometimes cannot connect or cannot login to the server.

Looking at the logs I don't see any error messages.
clam61
Posts: 125
Joined: 12 Sep 2007, 02:00

Re: Big probems. Inconsistent connection issues

Postby clam61 » 02 Feb 2014, 23:45

Update. With the second method, when I am not able to connect this is what I see in the server logs (DEBUG mode)

02 Feb 2014 | 15:06:06,708 | INFO | SocketReader | bitswarm.sessions.DefaultSessionManager | | Session created: { Id: 9, Type: DEFAULT, Logged: No, IP: 198.72.142.142:53571 } on Server port: 80 <---> 53571
02 Feb 2014 | 15:06:41,386 | INFO | Scheduler1-thread-1 | bitswarm.sessions.DefaultSessionManager | | Session removed: { Id: 9, Type: DEFAULT, Logged: No, IP: 198.72.142.142:53571 }

First I see the "session created". Client side, nothing is happening. No events are fired in the api.
Then I see "session removed" server side.
User avatar
Lapo
Site Admin
Posts: 19607
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Big probems. Inconsistent connection issues

Postby Lapo » 03 Feb 2014, 14:28

Connection instability is to be expected with mobile phones, especially with 3G connections. On wifi it's should be less frequent unless the radio signal is poor.

As regards background applications. What happens when you put the application in bg mode and then you resume it after say 30 seconds. Are you still able to send and receive messages? Do you get a disconnection?
Do you get the same behavior with wifi, and 3G connections?

Recreating the connection object is necessary when the connection is lost, regardless of the cause.

thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
clam61
Posts: 125
Joined: 12 Sep 2007, 02:00

Re: Big probems. Inconsistent connection issues

Postby clam61 » 03 Feb 2014, 19:51

Hi Lapo

I have had the problems of what seems like dropped messages, iphone running wifi at my home, where the signal strength is great. i have also had it running on on a desktop pc with flash. not just myself but other players as well in the same situation. Looking at the logs, the message looks like it is sent from the server without a problem but nothing shows up on the client side.

regarding connection issues:

"As regards background applications. What happens when you put the application in bg mode and then you resume it after say 30 seconds. Are you still able to send and receive messages? Do you get a disconnection?
Do you get the same behavior with wifi, and 3G connections?


When the application is put into the background i manually disconnect. when it comes back into the foreground I connect again.
The problem does seem to occur if I manually disconnect and then connect to the server again within a short timeframe. what happens after 30 seconds?
Same behavior regardless of wifi or 3g

Recreating the connection object is necessary when the connection is lost, regardless of the cause."


You mean I have to use a new instance of a SmartFox2xClient object, each time a connection is lost?
clam61
Posts: 125
Joined: 12 Sep 2007, 02:00

Re: Big probems. Inconsistent connection issues

Postby clam61 » 04 Feb 2014, 02:39

there is a big problem here.

its very very inconsistent. i just opened the app. now i have it coded so that it creates a new SFS2xClient Api object each time on connection.

it has probably been over an hour since my last connection to the server.

i am able to connect, but the server is not able to send any messages to my client on iphone. more specifically my extension cannot send anything successfully to the client. or maybe the client api is not reading it.


no errors shown in the logs. i am not sure what is the cause.
User avatar
Lapo
Site Admin
Posts: 19607
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Big probems. Inconsistent connection issues

Postby Lapo » 04 Feb 2014, 09:28

There seem to be several things going on at the same time. We will have to tackle them one by one starting from the most basic.
For starters I would like to understand if you're using the latest API available, version 1.3.0:
http://www.smartfoxserver.com/download/sfs2x#p=client

Let's start from this.
I have had the problems of what seems like dropped messages, iphone running wifi at my home, where the signal strength is great.

It seems? Or it is ... dropped messages. You just need to check the server's AdminTool > Dashboard to see the stats on dropped messages.

With a home wifi connection with a strong signal loosing messages is not expected unless you're sending too many.
Can you please explain what kind of messages you're sending, at which rate and which messages do you think are getting lost?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
clam61
Posts: 125
Joined: 12 Sep 2007, 02:00

Re: Big probems. Inconsistent connection issues

Postby clam61 » 04 Feb 2014, 19:17

Yes I am using the latest API 1.3.0

Right now my server says

Dropped packets Out: 53 (1%) In: 0 (0%)

The type of messages I am sending are extension messages in response to a player's extension message. In other words, Player 1 sends a message to Extension A, Extension A does some database stuff, then Extension A sends a response to Player 1. These messages are just JSON strings.

I am not sending many messages from server to client. It is only being sent in response to a user submitting some turns, which in this case is probably once every 2 seconds for 3 times maximum. There is a max of 2 users online as shown by the dashboard.

By the way, I just opened my app, so it went from background to foreground and so it connected to the server. It has been at least 10 hours since I last connected to the server. I ran into the situation where I see the logs confirming the message arriving at the server, things process with no exceptions or errors, but I do not see the extension response on the client side, no onExtensionResponse being called.

I then killed my app, so it is a fresh launch, and tried the same action. Failed again. Cannot reproduce the behavior consistently.


UPDATE

Ok I think I isolated the problem of dropped messages. I had been logging in as a test user with over 1000 temporary buddies added to the buddy list. This is when the dropped messages became much more consistent. As soon as I used a different user with a "normal" amount of temporary buddies added to his buddy list, this problem went away.

I will have to say, that I did experience this "dropped" message problem and the "random disconnect" problem even before I logged in as the test user, but it was less frequent AND I was using the API prior to the latest.
User avatar
Lapo
Site Admin
Posts: 19607
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Big probems. Inconsistent connection issues

Postby Lapo » 05 Feb 2014, 09:16

Thanks for the update, it makes sense.
The problem with dropped messages is all about the network capacity and the client connection. In other words the server does everything in its power to send data to the client. When this is not possible because the socket is already full (due to a slow network or a slow client in reading from the socket) the server starts to pile up data inside the User's queue until it reaches the limit. That's when messages are dropped.

You can adjust the size of the User's queue, but in general the default settings is already pretty large and adding more room there is simply going to postpone the problem but won't eliminate it.

---

As regards the issue of waking up the application in bg and not being able to send data it seems like the TCP connection is in an "inconsistent" state. In order to further investigate this you should be able to run a "netstat" on both your client and server and see exactly in which state the connection is from both sides. You can do that on the server but on the client (iOS) I don't think such thing exists. I suspect you would see two different states which is the cause of the problem.
Lapo

--

gotoAndPlay()

...addicted to flash games
clam61
Posts: 125
Joined: 12 Sep 2007, 02:00

Re: Big probems. Inconsistent connection issues

Postby clam61 » 05 Feb 2014, 19:56

I had three issues originally:

1. Cannot receive data from extension
2. Sometimes cannot login at all to server upon restart (resolved by following your advice to create a new SFS2xClient object upon connect)
3. Connection too frequently dropped from server (have not seen it since using latest API)

Problem #1 occurred very frequently when using the test user with over 1000 users. It occurred less frequently when using a normal user. I definitely don't think we are sending that much data back and forth, although I dont know the actual network capacity limit so I cannot say. Is this network capacity limited to the SFS client or overall?

When I am loading the user with over 1000 friends in the buddy list, and the buddy list is initialized, I get an SFSException onDataRead thrown due to over 1000 onAddBuddy events. Presumably what you are talking about is happening with network capacity. This is in the simulator but I presume it would happen with the device too.

When this happens, I get the exception I can send messages to the server but cannot receive.

Can I catch this exception in any way?
User avatar
Lapo
Site Admin
Posts: 19607
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Big probems. Inconsistent connection issues

Postby Lapo » 06 Feb 2014, 10:55

Problem #1 occurred very frequently when using the test user with over 1000 users. It occurred less frequently when using a normal user. I definitely don't think we are sending that much data back and forth, although I dont know the actual network capacity limit so I cannot say. Is this network capacity limited to the SFS client or overall?

Dropped messages can explain the the extension responses not getting back to clients.
What does it mean that it occurs less frequently with a normal user? You mean a non-mobile client?

SFS does not limit your network at all. The main problem is how much data you are sending, how saturated is the outgoing bandwidth and how saturated is the single client channel. If you are sending more data than the client can actually consume you will end up with problems such as dropped packets. This is because the server is forced to keep the outgoing data in a server side queue and wait for the client to "drain" the socket from its messages. If the client queue overflows the server is forced to drop message to protect itself.


When I am loading the user with over 1000 friends in the buddy list, and the buddy list is initialized, I get an SFSException onDataRead thrown due to over 1000 onAddBuddy events.

Which client API is giving you that error? I would expect only the mobile client to do that. This is because mobile OSes are configured with smaller buffers and have a harder time handling tons of data.

In general a 1000 friends is a lot. In practical terms it seems a bit unusable because it's pretty hard to be able to find buddies in such a long list. It would be more sensible to put a limit of a few couple of hundreds. Especially for mobile users.

When this happens, I get the exception I can send messages to the server but cannot receive.

No, that's the sign you have overloaded the client. You should limit the amount of buddies.
Lapo

--

gotoAndPlay()

...addicted to flash games
clam61
Posts: 125
Joined: 12 Sep 2007, 02:00

Re: Big probems. Inconsistent connection issues

Postby clam61 » 06 Feb 2014, 18:24

What does it mean that it occurs less frequently with a normal user? You mean a non-mobile client?


normal user meaning a user with 10-20 in his buddy list. with the 1000+ temp buddies in buddy list, i run into this issue probably 4/5 times.

i am definitely not sending too much data between the extension and the client. messages are small json messages, and actually I run into this problem the very first time the extension tries to send a message to the client.

the problem definitely is in the client side. when loading the buddy list, I see the exception being thrown internally in the client during the numerous onAddBuddy messages. after this, the client cant seem to recover and is not able to read data from the socket anymore.

i wish the client threw the exception so it could be handled instead of just failing internally.
User avatar
Lapo
Site Admin
Posts: 19607
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Big probems. Inconsistent connection issues

Postby Lapo » 06 Feb 2014, 20:14

clam61 wrote:What does it mean that it occurs less frequently with a normal user? You mean a non-mobile client?

normal user meaning a user with 10-20 in his buddy list. with the 1000+ temp buddies in buddy list, i run into this issue probably 4/5 times.

You could find a reasonable amount between 10-20 and thousands, no?
What's the point of having 1000+, Is it usable at all? You'd have to at least introduce a search feature and in general you wouldn't be able to keep track of everyone, especially on a mobile device.

i am definitely not sending too much data between the extension and the client. messages are small json messages, and actually I run into this problem the very first time the extension tries to send a message to the client.

That's good.

the problem definitely is in the client side. when loading the buddy list, I see the exception being thrown internally in the client during the numerous onAddBuddy messages. after this, the client cant seem to recover and is not able to read data from the socket anymore.

i wish the client threw the exception so it could be handled instead of just failing internally.

If it's a socket issue there's not much you would be able to do to recover the situation. It's got to do with the limits of the device and resources.
In any case you haven't told us exactly what the error is.
Can you please provide the full stack trace?

Thnx
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X iPhone / iPad / OSX API”

Who is online

Users browsing this forum: No registered users and 1 guest