Server Lag?

Blitz3D Forums/Blitz3D Programming/Server Lag?

NewtSoup(Posted 2007) [#1]
Hi, I've no played with B3D for quite a while and I remember, a few years ago, someone posted some code which demonstrated a potential problem with server apps written in B3D. I could probably re-create the code but I'm lazy and its easier to ask a question here.

The original:
The code originally posted had an animated circle on the screen which moved in a smooth lazy elipse. This app also worked as a "server" accepting incomming connections. There was also a "client" app that would connect to the server. The behaviour this pair of simple programs demonstrated was that when the client connected to the server the animation paused noticably while the client's connection was dealt with.

The upshot of this was while it wouldnt matter at all for low volume online game which waits for everyone to connect before starting the session it would not be good for an application which allows clients to come and go as they please. This would of course be because if a group of users decided to all connect at once it would tie up the server for a number of seconds and produce a serverwide "lag spike" for everyone already connected.

Now to my question: Is this still the case? (meanwhile I shall fire up B3D and see if I can reproduce the effect)


Bankie(Posted 2007) [#2]
I haven't heard of this problem myself, but on the game I've just finished, players can come and go during play and there are no stutters when this happens. I'm using only UDP (RottNet library), so not sure if this might be a TCP thing.


NewtSoup(Posted 2007) [#3]
I have actually just tested it. I see it as making Murphy's Law work for me. By asking before testing I am guaranteed to be worrying about nothing :).

Seems to run without glitches so I guess everything is fine in the world of B3D serverside apps :)

Ropey code follows, ensure people of a sensitive nature are far from the screen.

tcp_server.bb:
;Really Nasty Server app to test connection lag.
;this app needs tcp_client.bb to run.  Client disconnects are not handled.

Graphics 800,600,32,2
SetBuffer BackBuffer()
Type client
	Field ID
	Field s
End Type


s=CreateTCPServer(8081)
If s<>0 Then
Print "server started"
Else
Print "server failed"
WaitKey
End 
End If
id=0
counter = 0
loop = MilliSecs()
x= 400
dx=200
a=0
While Not KeyHit (1)
	Cls
	Lastloop=loop
	loop=MilliSecs()
	time=time + loop-Lastloop
	txt$="xxxxxx"
	
	a=a+5
	If a>360 Then a=0
	Text x+dx*Sin(a),300+dx*Cos(a)/2,"*"
	conn=AcceptTCPStream(s)
	If conn Then
		id=id+1
		c.client=New client
		c\s=conn
		c\id=id
		WriteLine conn,"Hi there"
	End If

	Delay 10
	
	If time>1000 Then
		time=0
		counter = counter +1
		For c.client = Each client
			WriteLine c\s,txt+": "+counter
			Text 10,15*c\id,"Sending to client "+ c\id
		Next
	End If
	Text 100,100,counter
	Text 100,115,time
	Flip
Wend


tcp_client.bb
;Really NASTY client app to test connection lag.
;there is no clean disconnect here.
Dim svr(19)
Print "Press a key to connect 20"
Print  "clients in rapid succession."
WaitKey

For f=0 To 19
	svr(f)=OpenTCPStream("127.0.0.1",8081)
	If svr(f)<>0 Then
		Print "Client "+f+" Connected successfully."
	Else
		Print "Server failed to connect."
			WaitKey
			End
	End If
Next

;show some text read from the server just to show it's alive.
While Not KeyHit(1)
	For f=0 To 19
		txt$=""
		txt$=ReadLine (svr(f))
		If txt$>"" Then
			Print txt$
		End If
		Delay 10
	Next
Wend



jfk EO-11110(Posted 2007) [#4]
I did't analyze your code, but one thing you have to deal with when using tcp is respond latency. especially webservers may take some seconds until they answer. the trick to prevent pauses is: donīt wait for answers. your game has to be capable of reading the answers of it's requests at a later time.


NewtSoup(Posted 2007) [#5]
Oh quite, the above code was only orginally designed to demonstrate the serverside behaviour while an incomming connection was being processed. The test was run on a LAN where you could expect the usual type of latency to be at a minium.

The only thing I was (past tense) concerned with was Blitz's ability to perform with a constant flow of clients comming and going. Now I know it can.


Vertigo(Posted 2007) [#6]
I am using Blitz3d to run a server for a small mmorpg that I am working on. The server has been running for over 3 weeks straight now. I randomly send it insane packets from multiple external IP's. The server is on a 12meg connection mind you, but its surprisingly stable. I am using UDP however, I do not believe protocol has anything to do with blitz's ability to maintain connections. Believe it or not ive had better response with stability with blitz than I have with C# and .NET's winsocks. I do have one compliant running a blitz server though. The window will after sometime go completely black. I have a console setup to remedy this, so in order to view whats going on, I have to make another call back to graphics x,x,x,x to get the damned window to render... this spikes the server and causes about a 500ms latency with incoming and outgoing messages. One other thing is an issue with blitz windows not rendering under a remote desktop session as they require specific graphics modes to be set on the machine. So expect huge latency when trying to remote in to manage the machine. Also you may want to not how much CPU usage Blitz takes up while running. Put this on a dedicated machine, and dont expect to run TOO many other services on it. I have Blitz, MYSQL,and Apache running on a dual 3.8 xeon with 4gb of ram, and it only has about 70% processing power left to handle server side functions. Other than that, there is no reason why you cannot use blitz to run dedicated server code.


Danny(Posted 2007) [#7]
Hi Vertigo ;)

"running for 3 weeks" - "screen go black after some time"


Could this PERHAPS be related to some use of MILLISECS()?
And the problem that it 'resets' when a computer has been on for 20 days (?) or more (variable not big enough to handle unlimited large number) ???

D.


Danny(Posted 2007) [#8]
[ignore]


Vertigo(Posted 2007) [#9]
No it usually happens when I logout and in as a different user, or I lock the computer. Or I open it from within a remote desktop session... if I turn off the screen saver and stay logged in, it will stay on for atleast 2 days(longest ive tested it).