Public Group

# Stackless Python, used for a high traffic game server.

This topic is 3789 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Normally, i would write something of the such (a high traffic game server) in C++ (which i currently am, in a different project). But is it very possible in Stackless Python? One would assume that Stackless Python would have a great advantage over C++, as it dosnt use the stack (duh..), and the server is not prone to the stack overflowing and stopping the game. Obviously it is possible to create a server in Stackless Python. :P I should actually ask the question this way. Is it possible to write a fast (by fast i mean by being able to handle a large amount of network traffic and processing of packets without causing alot of lag to the game) and stable server in stackless python. Currently i do know, however, that Eve Online uses quite a large amount of stackless python in there server (no talking game-content-scripting-wise). I would rather write something like the such (a high traffic server) in C++, as i see it more reliable (more or less probably because I have used it along time, and the fact you dont have to leave alot of stuff up to the language/computer to do for you, such as Garbage Cleanup), but using stackless python could save ALOT of development time. Thanks, Lordcorm

##### Share on other sites
You ask if stackless python can be used to create a high traffic server, yet also state that you realise Eve Online uses it?

As for the question of performance versus ease of development, that's a personal choice. I prefer ease of development myself, so I'd use python.

##### Share on other sites
Quote:
 Original post by gharen2As for the question of performance versus ease of development, that's a personal choice. I prefer ease of development myself, so I'd use python.

Stackless Python brings both when it comes to scalability.

The downside is that message based programming is conceptually different and possibly less cohesive. To retain adequately low granularity, long, sequential processes need to be broken down in a sequence of messages.

Quote:
 and the server is not prone to the stack overflowing and stopping the game.

That has nothing to do with what stackless brings. Programming model used is essentially asynchronous messaging with certain rules how messages are propagated. Rather than calling a function by putting parameters on stack, parameters are packed in a message, and put into target object's queue.

The benefit from this model comes from (possibly) no context switching, despite having very concurrent application (thousands, tens of thousands of threads). This model is best suited for applications that require good response. See also fibers/strands, reactor/pro-actor, active objects.

Quote:
 Is it possible to write a fast (by fast i mean by being able to handle a large amount of network traffic and processing of packets without causing alot of lag to the game) and stable server in stackless python.

Yes. That model is perfect for scalable servers. Same design is used for some of the most scalable web servers.

##### Share on other sites
Quote:
Original post by Antheus

Quote:
 and the server is not prone to the stack overflowing and stopping the game.

That has nothing to do with what stackless brings. Programming model used is essentially asynchronous messaging with certain rules how messages are propagated. Rather than calling a function by putting parameters on stack, parameters are packed in a message, and put into target object's queue.

The benefit from this model comes from (possibly) no context switching, despite having very concurrent application (thousands, tens of thousands of threads). This model is best suited for applications that require good response. See also fibers/strands, reactor/pro-actor, active objects.

Lol, run this code, with no parameters being passed, and you will get a StackOverflow.

#include <iostream>void Pong();void Ping(){	printf("Ping!\n");	Pong();}void Pong(){	printf("Pong!\n");	Ping();}int main(){	Ping();}

The stack also stores where you need to return after you finish a function call.

##### Share on other sites
lordcorm, you don't understand how this operates, so why are you trying to correct Antheus when he obviously does? (Function arguments are not the only parameters in a stack frame.)

##### Share on other sites
Quote:
 One would assume that Stackless Python would have a great advantage over C++, as it dosnt use the stack (duh..), and the server is not prone to the stack overflowing and stopping the game.
If stack overflows are what's stopping you from writing a server you've got bigger problems than language choice.

Quote:
 I would rather write something like the such (a high traffic server) in C++, as i see it more reliable (more or less probably because I have used it along time, and the fact you dont have to leave alot of stuff up to the language/computer to do for you, such as Garbage Cleanup), but using stackless python could save ALOT of development time.
So in your little world, manual memory management is MORE RELIABLE than automatic GC? How do you manage to forget to free() or delete() in a GC language?

Quote:
 Lol, run this code, with no parameters being passed, and you will get a StackOverflow.
The lol's on you. Your example showcases the lack of tail call optimization in your C compiler, not anything relating to concurrency at all.

I assume you got it from the stackless tutorial, but the point of the stackless solution seems to have flown right over your head, as your C version is just tail recursive calls with no synchronisation anywhere.

If overflowing the stack is what's worrying you, stackless python is decidedly uglier than a language with builtin TCO like scheme. Here's your C example in scheme: it doesn't overflow the stack and is quite a bit shorter than the stackless code:

(define (ping)	(display "Ping!\n")	(pong))(define (pong)	(display "Pong!\n")	(ping))(ping)

You seem to be fixated on the 'stackless' bit. It's not about the stack, it's about the lightweight threads and the async messaging as opposed to system threads and manual shared memory synchronization.

Stackless python (and erlang, my personal favorite) are about managing concurrency via message passing, not about avoiding stack overflows.

You didn't understand the points Antheus was making.

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
17
5. 5

• 9
• 12
• 9
• 33
• 13
• ### Forum Statistics

• Total Topics
632593
• Total Posts
3007266

×