[Tutor] running a game server
Steven D'Aprano
steve at pearwood.info
Sun Jan 6 18:41:19 EST 2019
On Sun, Jan 06, 2019 at 02:14:10PM +0000, nathan tech wrote:
> My question is, is python really the way to go for game servers?
*shrug*
Do game servers have unique requirements that are different from (say)
mailing list servers and other servers? That's not a rhetorical
question. I don't know the answer.
My home server runs at least three long-running Python processes (hpssd,
whatever that is, fail2ban, and mailman), and I frequently run
interactive Python sessions which stay open for a week at a time. It has
been up for 62 days now, and the only reason that uptime isn't three
times that is because I had a power failure. Now admittedly it is a home
server with two users, not a public game server with 100,000 users, but
still, this is evidence that Python does not leak memory.
You might consider that Stackless is used as the game scripting engine
for "Eve Online", and they do have hundreds of thousands of users.
(Stackless is a version of Python that avoids the C stack.)
> I remember, long ago, running a script that went along the lines of:
>
> import shutil
> import time
> while 1:
> f=open("backup.count_file.txt","r");
> num=int(f.read())
> f.close()
> f=open("backup/count_file.txt","w");
> f.write(str(num+1));
> f.close()
> shutil.copy("my_file.txt", "my_file.txt.backup."+str(num))
> time.sleep(900)
>
>
> After running for a day, this had to be killed because it sucked up more
> memory than anything I'd ever seen before.
As Alan says, it is hard to debug code that may or may not be the actual
code you ran, and there's no obvious reason why your code should leak.
The first improvement I would make (aside from fixing the obvious typos,
removing unnecessary semicolons, etc) is that there's no need to read
the count from a file on every backup. You only need to read it once,
when the script starts:
import shutil
import time
f = open("backup.count_file.txt", "r")
num = int(f.read() or '0')
f.close()
while True:
num += 1
f = open("backup.count_file.txt", "w")
f.write(str(num))
f.close()
shutil.copy("my_file.txt", "my_file.txt.backup." + str(num))
time.sleep(900)
I suppose it is possible that shutil.copy has, or had, a memory leak,
but without knowing the actual code you used, the version of Python,
and the platform, I don't propose trying to investigate any further.
[...]
> I don't mind too much if its using a bit of memory, but, if python is
> just going to leak all over the place and I'm better off learning c or c
> sharp or something, then I'd like to know!
So you're a game developer, but you don't know Python, C, C# or
"something". What language(s) do you know?
P.S. please reply to the mailing list, not me personally.
--
Steve
More information about the Tutor
mailing list