Examples (iOS)
Examples (Android)

 

» The SmartFoxServer 2X client-server protocol

SmartFoxServer 2X uses a highly effiecient binary protocol that makes the server performance outstanding under different aspects. Messages are light on the bandwidth and fast to parse by the client and server engine. Additional on-the-fly compression allows for extra size reduction without impacting the general performance.

This is an example of object transmission using the XML-based SmartFoxServer 1.x protocol and the SmartFoxServer 2X binary protocol:

» SmartFoxServer 1.x

var testObj:Object = {}
testObj.smallInt = 15
testObj.medInt = 120700
testObj.bigInt = 10900800700
testObj.doubleVal = Math.PI
testObj.muppetNames = ["Kermit", "Fozzy", "Piggy", "Animal", "Gonzo"]
testObj.fruits = [
	  	{name:"Apple", color:"red", inStock:true, price:1.50},
	  	{name:"Lemon", color:"yellow", inStock:false, price:0.80},
	  	{name:"Apricoat", color:"orange", inStock:true, price:1.90},
	  	{name:"Kiwi", color:"green", inStock:true, price:2.30}
]

This is the message dump, which takes 1027 bytes:

<msg t='sys'><body action='asObj' r='1'><![CDATA[<dataObj><var n='smallInt' t='n'>15</var><var n='medInt' t='n'>120700</var><obj t='a' o='fruits'><obj t='o' o='0'><var n='inStock' t='b'>1</var><var n='color' t='s'>red</var><var n='price' t='n'>1.5</var><var n='name' t='s'>Apple</var></obj><obj t='o' o='1'><var n='inStock' t='b'>0</var><var n='color' t='s'>yellow</var><var n='price' t='n'>0.8</var><var n='name' t='s'>Lemon</var></obj><obj t='o' o='2'><var n='inStock' t='b'>1</var><var n='color' t='s'>orange</var><var n='price' t='n'>1.9</var><var n='name' t='s'>Apricoat</var></obj><obj t='o' o='3'><var n='inStock' t='b'>1</var><var n='color' t='s'>green</var><var n='price' t='n'>2.3</var><var n='name' t='s'>Kiwi</var></obj></obj><var n='bigInt' t='n'>10900800700</var><obj t='a' o='muppetNames'><var n='0' t='s'>Kermit</var><var n='1' t='s'>Fozzy</var><var n='2' t='s'>Piggy</var><var n='3' t='s'>Animal</var><var n='4' t='s'>Gonzo</var></obj><var n='doubleVal' t='n'>3.141592653589793</var></dataObj>]]></body></msg>

» SmartFoxServer 2X

This is the message dump, binary protocol, no compression. Size is 351 bytes, almost 1/3 of the XML version.

Binary Size: 351
12 00 06 00 09 64 6F 75 62 6C 65 56 61 6C 07 40 	.....doubleVal.@
09 21 FB 54 44 2D 18 00 06 66 72 75 69 74 73 11 	.!.TD-...fruits.
00 04 12 00 04 00 04 6E 61 6D 65 08 00 05 41 70 	.......name...Ap
70 6C 65 00 05 63 6F 6C 6F 72 08 00 03 72 65 64 	ple..color...red
00 07 69 6E 53 74 6F 63 6B 01 01 00 05 70 72 69 	..inStock....pri
63 65 06 3F C0 00 00 12 00 04 00 04 6E 61 6D 65 	ce.?........name
08 00 05 4C 65 6D 6F 6E 00 05 63 6F 6C 6F 72 08 	...Lemon..color.
00 06 79 65 6C 6C 6F 77 00 07 69 6E 53 74 6F 63 	..yellow..inStoc
6B 01 00 00 05 70 72 69 63 65 06 3F 4C CC CD 12 	k....price.?L...
00 04 00 04 6E 61 6D 65 08 00 08 41 70 72 69 63 	....name...Apric
6F 61 74 00 05 63 6F 6C 6F 72 08 00 06 6F 72 61 	oat..color...ora
6E 67 65 00 07 69 6E 53 74 6F 63 6B 01 01 00 05 	nge..inStock....
70 72 69 63 65 06 3F F3 33 33 12 00 04 00 04 6E 	price.?.33.....n
61 6D 65 08 00 04 4B 69 77 69 00 05 63 6F 6C 6F 	ame...Kiwi..colo
72 08 00 05 67 72 65 65 6E 00 07 69 6E 53 74 6F 	r...green..inSto
63 6B 01 01 00 05 70 72 69 63 65 06 40 13 33 33 	ck....price.@.33
00 08 73 6D 61 6C 6C 49 6E 74 02 0F 00 06 6D 65 	..smallInt....me
64 49 6E 74 04 00 01 D7 7C 00 0B 6D 75 70 70 65 	dInt....|..muppe
74 4E 61 6D 65 73 10 00 05 00 06 4B 65 72 6D 69 	tNames.....Kermi
74 00 05 46 6F 7A 7A 79 00 05 50 69 67 67 79 00 	t..Fozzy..Piggy.
06 41 6E 69 6D 61 6C 00 05 47 6F 6E 7A 6F 00 06 	.Animal..Gonzo..
62 69 67 49 6E 74 05 00 00 00 02 89 BD 04 BC    	bigInt.........	

The next dump is with compression enabled: size is 239 bytes, an extra 32% reduction. Larger message can benefit a lot more than this, especially those containing lots of String data or complex nested objects. In that case the size reduction can be in the order of 2-300%.

In total the SFS2X request is 4.2 times smaller than the previous version and it is safe to assume that in general that new protocol provides a bandwidth reduction in the order of 3-6x.

Binary Size: 239
78 DA 6D CE 41 4A C3 40 14 C6 F1 2F 75 66 9A E2 	x.m.AJ.@.../uf..
42 AD 1B B7 1E C0 55 0E 60 03 A2 48 8B 08 15 F7 	B.....U.`..H....
69 F2 1C 06 67 E6 85 49 42 49 F0 02 DE 49 C1 03 	i...g..IBI...I..
E8 DA 83 B8 74 63 DC A4 59 74 F7 78 F0 FB BF 37 	....tc..Yt.x...7
87 C2 AC E0 66 63 E9 31 B3 D3 C5 EC FC F7 E1 EA 	....fc.1........
E2 0C EA 29 34 A6 AE 4E 20 E6 10 10 3E 73 14 43 	...)4..N....>s.C
A6 65 69 09 32 67 CB 21 C6 41 A0 02 53 E3 D7 35 	.ei.2g.!.A..S..5
E7 CF 51 04 59 06 93 93 BA FC 00 C6 68 45 8E FD 	..Q.Y.......hE..
80 54 4B D6 F2 76 E7 30 B8 D5 E7 D7 C8 C5 E9 FF 	.TK..v.0........
9A B3 7A 47 39 64 5E D3 BE 93 3F 49 32 A2 62 69 	..zG9d^...?I2.bi
B6 66 60 52 07 22 BF 47 2D 4E 93 04 71 E5 32 6B 	.f`R.".G-N..q.2k
6F 7D 3D 39 82 72 54 F4 93 40 F4 FD 82 43 D7 94 	o}=9.rT..@...C..
25 D5 77 7D B1 3A 86 84 5A 52 70 A6 FF E6 9A BB 	%.w}.:..ZRp.....
AE 85 BC 37 5A B7 50 A9 37 7D 00 F2 86 7D C7 50 	...7Z.P.7}...}.P
1B A3 FB 82 04 30 79 7D 17 6F 7F 32 D5 5E 7D    	.....0y}.o.2.^}

» Protocol performance

The overall performance of the protocol parsing is also significantly improved in version 2X on both the server and client. Especially on the server side this has a notable effect. We have benchmarked the amount of messages per second that can be parsed with the old text protocol versus the new one.

SmartFoxServer Text Protocol:
Protocol Type Fragmentation Req/sec
Text No 11819
Text Average 11767
Text High 10676

SmartFoxServer Binary Protocol:
Protocol Type Fragmentation Req/sec
Binary No 68591
Binary Average 68204
Binary High 55286

The improvements are in the order of 5-6x increase in message parsing. The fragmentation parameter introduced in the table indicates how much fragmented is the message. In other words during the benchmark test we simulated various levels of packet fragmentation to see how this influence the performance during the data aggregation phase.

An average fragmentation level uses 6-10 fragments, while a high level uses 20-25 fragments. The original message was 350 bytes long.

» Compression

The compression feature is activated by the client and server when a message is larger than the configured amount.
The algorithm employed is the inflate/deflate technique from GZip/Zip formats which is very fast and supported by all common platforms (Flash, Java, .Net, etc).

Performance-wise the algorithm can decompress over 10K messages/sec and compress around 5K messages/sec on any dual core machine. This also means that on the client-side the effects of data compression is negligible.