problems using SFS in a pure C# setting

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

smkptn
Posts: 2
Joined: 27 Sep 2016, 10:32

problems using SFS in a pure C# setting

Postby smkptn » 27 Sep 2016, 10:46

Hello,

We're trying to use SFS2X for a multi-player game.
As we're a C# shop, we're trying to avoid any Java if we possibly can, particularly if we can avoid the whole extensions approach.
We've been able to send our message objects from clients to server and back using SFSObjects and ObjectMessageRequests.
At the moment we're testing with a small number of clients (up to the 99 limit of the Community Edition) with what we think is quite a moderate volume of messages: 2 updates per second from the server to each client (about 1-2 KB each) and 2 request per second from each client to the server (about 500 bytes each).
The problem is some of the packets get dropped, particularly ones being sent from the server to clients, which kind of makes sense as this channel is the busiest, but we don't think we're having enough clients or producing enough traffic to justify the problem - aren't there games using SmartFox with many thousands of concurrent clients and much higher data rate?
We've ruled out the network bandwidth problem, as the same happens when all the clients, the server and SFS are on the same LAN.

One suspicion we have is that as far as SFS is concerned, the server is just another client, only busier - is there a special way of designating a particular connected party as the server and not just one of the clients (and thus allocating it more bandwidth and/or higher priority)?
Are we correct to think that we can't use ISFSObject.PutClass without entering the extensions (and hence Java) realm?
Are we doing something horribly wrong?
Could it be because we're currently using the Community Edition? Or maybe because we're avoiding using extensions?

We're using SmartFoxServer2X v2.9.0 and C# client API v1.6.5.

Thank you in advance,
Sasha
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: problems using SFS in a pure C# setting

Postby Lapo » 27 Sep 2016, 14:03

Hello,

Code: Select all

The problem is some of the packets get dropped, particularly ones being sent from the server to clients, which kind of makes sense as this channel is the busiest, but we don't think we're having enough clients or producing enough traffic to justify the problem - aren't there games using SmartFox with many thousands of concurrent clients and much higher data rate?

Yes.
Dropped packets depend solely on the conditions of the network. It sounds particularly strange that you're loosing packets in a LAN, unless you're testing with a poor WiFi setup.

You said you're sending 2 req/second. But are these request broadcast type? If they are sent to every other user in the Room then you have a larger packet rate going from server to client and this can lead to dropped packets if the server is producing more data than what clients can consume,

Can you provide more details about your test?

One suspicion we have is that as far as SFS is concerned, the server is just another client, only busier - is there a special way of designating a particular connected party as the server and not just one of the clients (and thus allocating it more bandwidth and/or higher priority)?

Sorry this is incomprehensible.
SmartFoxServer 2X only supports a client-server model of communication. There is no client that acts as a server. There is an actual server :)

Are we correct to think that we can't use ISFSObject.PutClass without entering the extensions (and hence Java) realm?

No, you could use PutClass.
It can be used to serialize objects other than the basic types supported by SFSObject.

Could it be because we're currently using the Community Edition? Or maybe because we're avoiding using extensions?

No and no.
The only limit with Community Edition is the number of CCU.
Avoiding Extensions won't make your network work faster either.

We just need more details to understand what your test does.
Also, how did you build the client? Are you running multiple client connections in the same client app?

thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
smkptn
Posts: 2
Joined: 27 Sep 2016, 10:32

Re: problems using SFS in a pure C# setting

Postby smkptn » 27 Sep 2016, 15:45

Hi Lapo,

Thank you for your speedy response.
I'll try to clarify my questions.

My understanding is that the standard architecture to use with SmartFox is to put all your game-server logic into extension(s), plug them into the SFS and then there are only clients that connect to SFS. Since we're trying to avoid Java (mainly due to timescale limitations) and prefer having our server logic in C# if we can, we're trying to use SFS "merely" as a reliable means of communication between the clients and our C# server executable.
Our server connects to SFS the same way our clients do and is distinguishable mainly by the username it connects to SFS with. Both sides send ObjectMessageRequests (to a single targetRoom and currently to a single recipient) using SmartFox.Send and listen to SFSEvent.OBJECT_MESSAGEs.

Code: Select all

_smartFoxServer.Send(new ObjectMessageRequest(privateMessage.ToISFSObject(), _targetRoom, privateMessage.GetRecipient()));

and

Code: Select all

_smartFoxServer.AddEventListener(SFSEvent.OBJECT_MESSAGE, OnMessage);



The requests (for the testing stage) are all to a single recipient (either from a client to our server or vice versa) and not only are within the same LAN (no WiFi involved) but having all 3 components (SFS, our server exe and the load-testing exe) run on the same machine. The load-testing app is a single executable with each simulated client being a separate thread, using a separate instance of SmartFox class to communicate to SFS. It does mean that a single connection between our server and SFS has to cope with the traffic of all clients, so with our current testing scenario that's 2 messages in and 2 out every second, times the number of clients.

At first we were simply serializing our messages to strings and just sending those (using PrivateMessageRequest). Now we're using the much-more-efficient SFSObject approach. So the data rate dropped significantly, but the maximum number of clients before packets start dropping remained roughly the same (about 60-70).

No, you could use PutClass.

We tried using PutClass with our message classes, but couldn't find a way to handle arrays of ints (or even ArrayLists), let alone arrays of reference types. But even with simple dummy classes containing only ints, bools, doubles and strings (and implementing SerializableSFSType) it complained about not having a corresponding Java class (presumably in the extensions realm).

Thank you again,
Sasha
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: problems using SFS in a pure C# setting

Postby Lapo » 27 Sep 2016, 17:25

My understanding is that the standard architecture to use with SmartFox is to put all your game-server logic into extension(s), plug them into the SFS and then there are only clients that connect to SFS. Since we're trying to avoid Java (mainly due to timescale limitations) and prefer having our server logic in C# if we can, we're trying to use SFS "merely" as a reliable means of communication between the clients and our C# server executable.

There's a better way to put this :)
SmartFox provides you 2 levels of API. The client side API allow you do many things, the server side API allow you to do all the rest :)
An additional bonus is that server side code is more secure and allows for more control and more advanced behaviors. Still you can entirely skip the server side thing, if you don't need it.

In fact many games can be built purely from client side logic and they will work just as fine.

Our server connects to SFS the same way our clients do and is distinguishable mainly by the username it connects to SFS with. Both sides send ObjectMessageRequests (to a single targetRoom and currently to a single recipient) using SmartFox.Send and listen to SFSEvent.OBJECT_MESSAGEs.

It would be less confusing if we continued to use server for the actual server and maybe called the "special client" the master or master client or something like that? Ok?

The master client is still connected to the server and does not act as a server, so it makes things very ambiguous :)

At first we were simply serializing our messages to strings and just sending those (using PrivateMessageRequest). Now we're using the much-more-efficient SFSObject approach. So the data rate dropped significantly, but the maximum number of clients before packets start dropping remained roughly the same (about 60-70).

So the master is sending 2 messages/sec to 60 clients separately?
It's not broadcasting to the whole Room, correct?

The issue with dropped packets is that your test is evidently creating a bottleneck on the client side. SmartFox doesn't drop packets if not for one reason, because the underlying TCP stack is saying that the client's channel is full and no more data can be written unless the client starts reading packets from its side.

Even in that case SFS2X starts queuing up messages before dropping, in hope that while the queue builds up the client will remove some packet from its end. If that doesn't happen, then packets are dropped.

For more details see here:
http://docs2x.smartfoxserver.com/Gettin ... g#section4

Where the bottleneck is I can't say, as I don't know all the details but I can suggest the two usual main suspects:

1- Network, which you have already excluded
2- Client machine resources (e.g. the client app is struggling reading data from all clients)

If the #2 is true, it should be pretty evident by the CPU consumption of the process.

By the way, in the title of this thread you're talking about "pure C# setting". Are you targeting .Net? Windows Universal? Something else?

Just to understand.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 37 guests