Stackless Programming Apache

Stuff that don´t fit in the other categories.
Post Reply
User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

Stackless Programming Apache

Post by maboroshi »

So I've been thinking of ideas lately and came up with the idea of a Stackless Apache

Using either C or Python :-)

If you do not know what the stack is here is a lightweight introduction
Every time you call a subroutine, it creates a stack frame. This is the holding area for variables and other information local to the subroutine. In this case, when you call ping() it creates a stack frame that holds information for the subroutine call. Simplistically, the frame says that says ping pinged. When it calls pong(), this creates another stack frame that says pong ponged. The stack frames are chained together, with each subroutine call acting as a link in the chain. In this case, the stack basically says ping pinged so pong ponged. Of course when pong() calls ping() this extends the stack.


Here is a visual representation:

1 ping pinged
2 ping pinged so pong ponged
3 ping pinged so pong ponged so ping pinged
4 ping pinged so pong ponged so ping pinged so pong ponged
Now imagine that the page width represents the memory that your system has allocated to the stack. When you hit the edge of the page, you overflow and the system runs out of memory. Hence the term stack overflow
A stackless Apache would allow for systems with very little memory to run the Apache server

So when a user requests a page apache wouldn't have to spawn process after process

Thus reducing DoS also :-)

Anyway just throwing my ideas around will have to figure out a way to implement it now :-)

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

How it would work

Post by maboroshi »

Also might as well post this as a Demo to my idea

Enter Stackless

Code: Select all

#
# pingpong_stackless.py
#

import stackless

ping_channel = stackless.channel()
pong_channel = stackless.channel()

def ping():
    while ping_channel.receive(): #blocks here
        print "PING"
        pong_channel.send("from ping")

def pong():
    while pong_channel.receive():
        print "PONG"
        ping_channel.send("from pong")



stackless.tasklet(ping)()
stackless.tasklet(pong)()

# we need to 'prime' the game by sending a start message
# if not, both tasklets will block
stackless.tasklet(ping_channel.send)('startup')

stackless.run()
Using stackless python www.stackless.com

You can see by this example how this idea would work :-)

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Post by bad_brain »

I hope developing it as Apache module works, the lowered overhead and RAM usage would make it good for people with small vservers for example... :D

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

Yea

Post by maboroshi »

Yea as an Apache module would be best will have to get a book on writing apache modules :-)

but in the mean time here is a web server using that exact idea

good chance to stress test the concept :D

http://code.suck-o.com/129

:-)

User avatar
Still_Learning
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 1040
Joined: 11 Jun 2008, 16:00
15
Location: Trigger City

Post by Still_Learning »

Code: Select all

http://www.51cnnet.net/ebook/889-writing-apache-modules-with-perl-and-c
maybe that will help? :D

you will need to type in a capcha code for the download of the ebook
Gone

Post Reply