FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

MiniD State objects

 
Post new topic   Reply to topic     Forum Index -> MiniD
View previous topic :: View next topic  
Author Message
Roosmaa



Joined: 05 Nov 2006
Posts: 9
Location: Estonia

PostPosted: Sun Nov 05, 2006 4:35 am    Post subject: MiniD State objects Reply with quote

As Jarret probably already knows, I'm working on an experimental Apache2 module to run MD scripts.

Now in order to use the write/f/ln functions to send data to the client, I need to override them in my Apache module. That would be much easier if there was just one place the data from those functions could go (eg. stdout), but for each request there usually is a different client waiting the data.

So, I decided that the best way to actually implement all the apache-specific extensions for MD would be to put them inside a library. I was hoping it would be somehow possible to clone the global state (in which all the other libraries would have been already loaded) and then just add my library to that cloned state, but as far as I can tell, it isn't possible.

Did I miss something and it is possible to clone the MDState object somehow? What would I break if I would ignore the MDGlobalState singleton and create my own state objects for each request (I know, it would be bad for performance, but atleast I wouldn't have to wait untill the other scripts running in different threads would finish)? Maybe any other suggestions on how to solve that problem?
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Sun Nov 05, 2006 12:10 pm    Post subject: Reply with quote

Quote:
I was hoping it would be somehow possible to clone the global state (in which all the other libraries would have been already loaded) and then just add my library to that cloned state, but as far as I can tell, it isn't possible.


You're right -- there isn't a method to do that now, though it wouldn't be hard to do, so I'll do that. However, why couldn't you load your Apache library into the original state?

Quote:
What would I break if I would ignore the MDGlobalState singleton and create my own state objects for each request (I know, it would be bad for performance, but atleast I wouldn't have to wait untill the other scripts running in different threads would finish)?


As of now the MDGlobalState doesn't do much. It's there to manage multiple states once coroutines (cooperative multithreading) get put in, but since that's not done yet, you can go right around it. Besides, once I do get coroutines in, you should still be able to create MDStates and it should manage all that for you, so you shouldn't have to worry about your code getting broken in the future.

Now, are you planning to have your host application be multithreaded with maybe one state per thread? That might be a problem, because having had no experience with multithreaded programming, I haven't made any concessions for it in the library.. it might work, or it might do something terrible. Confused
Back to top
View user's profile Send private message
Roosmaa



Joined: 05 Nov 2006
Posts: 9
Location: Estonia

PostPosted: Sun Nov 05, 2006 12:40 pm    Post subject: Reply with quote

JarrettBillingsley wrote:
You're right -- there isn't a method to do that now, though it wouldn't be hard to do, so I'll do that. However, why couldn't you load your Apache library into the original state?


Because that library needs a structure from Apache, so it can send the data from write/f/ln to the right client, set the environment (GET, POST, etc) thingys, etc.

I'm guessing that Apache child processes do use threading to handle multiple connections simuntainously, that's why I can't just have a variable with that Apache struct in my Apache lib, as it might change whenever another client requests something from that child process.

And the reason I can't be sure if Apache child processes actually do use threading is because Apache has almost no documentation what so ever regarding module writing.

JarrettBillingsley wrote:
As of now the MDGlobalState doesn't do much. It's there to manage multiple states once coroutines (cooperative multithreading) get put in, but since that's not done yet, you can go right around it. Besides, once I do get coroutines in, you should still be able to create MDStates and it should manage all that for you, so you shouldn't have to worry about your code getting broken in the future.

Now, are you planning to have your host application be multithreaded with maybe one state per thread? That might be a problem, because having had no experience with multithreaded programming, I haven't made any concessions for it in the library.. it might work, or it might do something terrible. Confused


I was hoping to clone the global state as it's much easier than initializing a separate state for each request (on my side). But now to think about it, it might be quite the same regarding performance. Cloning might be slightly faster as there are fewer function calls.

Anyhow, good to know that ignoring MDGlobalState will not break anything.
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Sun Nov 05, 2006 2:27 pm    Post subject: Reply with quote

Quote:
I'm guessing that Apache child processes do use threading to handle multiple connections simuntainously, that's why I can't just have a variable with that Apache struct in my Apache lib, as it might change whenever another client requests something from that child process.


Ohhh, OK, I see now.

Quote:
I was hoping to clone the global state as it's much easier than initializing a separate state for each request (on my side). But now to think about it, it might be quite the same regarding performance. Cloning might be slightly faster as there are fewer function calls.


Hmm. Thinking of ways to solve this..

Well in terms of executing many requests at once, I don't think there's any other way than to create multiple states. It shouldn't be too expensive, though -- creating a new state only requires a little bit of stack space and some bookkeeping stuff, and the new state will have the same global table as the state that it was duplicated from.

Basically any solution involving doing stuff with MiniD would require duplicating the globals table for the new state and reloading your Apache lib into it. That would be feasible, but I'm not sure it would be the best performance. Would there be any way for your host code to determine which instance of this Apache struct to use based on which host request thread is running? I.e. you'd associate an instance of this Apache struct with each host thread, and when you call some Apache function in MiniD, your host code would get the correct Apache struct based on the thread that called it.
Back to top
View user's profile Send private message
Roosmaa



Joined: 05 Nov 2006
Posts: 9
Location: Estonia

PostPosted: Sun Nov 05, 2006 2:37 pm    Post subject: Reply with quote

JarrettBillingsley wrote:
Basically any solution involving doing stuff with MiniD would require duplicating the globals table for the new state and reloading your Apache lib into it. That would be feasible, but I'm not sure it would be the best performance. Would there be any way for your host code to determine which instance of this Apache struct to use based on which host request thread is running? I.e. you'd associate an instance of this Apache struct with each host thread, and when you call some Apache function in MiniD, your host code would get the correct Apache struct based on the thread that called it.


No, I can't predict the content of that struct as it contains all the reqest data from the client and stuff like that.

Anyhow, I'll just do the new state magic then and update it to a better version when it actually is running and performance is affected by it... (or something like that)

Thanks anyway Smile
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> MiniD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group