You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Ryan Bloom <rb...@raleigh.ibm.com> on 1999/08/12 16:52:56 UTC
Which thread/process
Okay, we took out the only place in the 2.0 tree where we designated a
unique number for each thread within each process. Namely, the
thread_num/child_num pair in the conn_rec. So how am I now supposed to
get a deterministic value for the exact thread I am running in?
I am re-vamping mod_cgid to correct some of the issues that were brought
up the last time I posted it to the listserv. One of the issues was that
I was creating a big array of named pipes names, to use for the
communication. It was suggested I don't create the array, opting for
re-creating the pipe name when I need it, instead. Without a way to get a
deterministic name, this is not possible. I'm not even sure if the old
method would work without this information. As I said when we were
removing this information, I think we removed it FAR too quickly without
thinking of the implications. I would like to put back the thread_num and
child_num unless somebody else can give me a way to get this information.
For anybody who doesn't remember, mod_cgid is a module that creates a cgi
daemon. It is VERY expensive on most *nix's to fork a threaded process,
because all of the memory for all of the threads is copied, even though
only one thread is active. To get around this problem, mod_cgid creates
it's own cgi daemon at initialization time, and for all cgi's it, it forks
this single-threaded daemon. Before anybody asks this time, this is not
like cgisock. My goal is to keep 100% backward compatability. cgisock
does not do this. cgisock will not run standard cgi's. mod_cgid MUST run
standard cgi's.
Ryan
_______________________________________________________________________
Ryan Bloom rbb@raleigh.ibm.com
4205 S Miami Blvd
RTP, NC 27709 It's a beautiful sight to see good dancers
doing simple steps. It's a painful sight to
see beginners doing complicated patterns.
Re: Which thread/process
Posted by Manoj Kasichainula <ma...@io.com>.
On Thu, Aug 12, 1999 at 07:04:49PM -0400, Ryan Bloom wrote:
>
> Explain to me how the child garauntess that no other child server has the
> same number at the same time, without some sort of child number
> identification. If the child has a child number identification, then this
> whole issue is moot, and somebody just needs to tell me where it is.
In fact, child and thread numbers can (and will) be used to build a
connection ID in all the MPMs currently in the tree. But, calling it a
"connection ID" allows an asynchronous MPM to assign connection IDs in
a completely different way, so that all modules still work.
It is almost just a distinction in terminology. Almost.
> I see three options. 1)Each child uses numbers within a range, but
> where does the child get the range from?
So far, for mpmt_pthread and dexter, connection ID is a long, and will
be set to child_num * HARD_THREAD_LIMIT + thread_num.
> The idea sounds good, now just give me some idea of how to implement it,
> because that's the part I am not seeing.
I'm almost done with an implementation for the Unix MPMs (the dexter
MPM is taking all the time, because it just didn't have the
infrastructure in place to support this).
--
Manoj Kasichainula - manojk at io dot com - http://www.io.com/~manojk/
"If I have trouble installing Linux, something is wrong. Very wrong."
- Linus Torvalds
Re: Which thread/process
Posted by Ryan Bloom <rb...@raleigh.ibm.com>.
Explain to me how the child garauntess that no other child server has the
same number at the same time, without some sort of child number
identification. If the child has a child number identification, then this
whole issue is moot, and somebody just needs to tell me where it is.
I see three options. 1)Each child uses numbers within a range, but
where does the child get the range from? 2)Each child uses their pid to
generate the index, this is no good, because as soon as that child dies,
their numbers can never be repeated. 3)We use some sort of IPC to make
sure that the number desired number is available, this defeats the whole
purpose, because it will be way too slow.
What am I missing?
The idea sounds good, now just give me some idea of how to implement it,
because that's the part I am not seeing.
Ryan
On Thu, 12 Aug 1999, Manoj Kasichainula wrote:
> On Thu, Aug 12, 1999 at 10:52:56AM -0400, Ryan Bloom wrote:
> >
> > Okay, we took out the only place in the 2.0 tree where we designated a
> > unique number for each thread within each process. Namely, the
> > thread_num/child_num pair in the conn_rec. So how am I now supposed to
> > get a deterministic value for the exact thread I am running in?
>
> What you really need isn't a child_num/thread_num pair, but an
> identifier for a connection that is unique at any given point in time
> but repeats as often as possible (to minimize the number of named
> pipes).
>
> I suggest adding an index field to conn_rec. This number is set by
> the MPM after ap_new_connection is called. This way, mod_cgid can work
> properly even in an asynchronous threaded server.
>
> I'm guessing this field would be useful to other modules as well.
> PHP4's TSRM could possibly derive the indices it uses from
> conn_rec->index.
>
> Thoughts?
>
> --
> Manoj Kasichainula - manojk at io dot com - http://www.io.com/~manojk/
> "By 'standie,' I mean those life-sized cardboard figures that stand up. By
> 'pirate,' I mean 'Arrrrr!'" -- Steve Jackson
>
_______________________________________________________________________
Ryan Bloom rbb@raleigh.ibm.com
4205 S Miami Blvd
RTP, NC 27709 It's a beautiful sight to see good dancers
doing simple steps. It's a painful sight to
see beginners doing complicated patterns.
Re: Which thread/process
Posted by Manoj Kasichainula <ma...@io.com>.
I wrote:
> > > I suggest adding an index field to conn_rec. This number is set by
> > > the MPM after ap_new_connection is called. This way, mod_cgid can work
> > > properly even in an asynchronous threaded server.
On Sat, Sep 11, 1999 at 12:13:38PM +0200, Zeev Suraski wrote:
> As far as I recall, that's what Dean wanted to do in the first place.
> Our problem with it remains as it was - we don't have any access to the
> conn_rec structure from TSRM.
I haven't thought about this too much yet, but I think one possibility
in this case is to split the functionality of ts_allocate_id. Right
now, it generates a new ID, and sets aside the space for it. Instead,
let the application supply the new ID. ts_allocate_id would become
more like ts_register_id. PHP proper should be able to dig out the
connection ID and pass it to TSRM pretty easily.
--
Manoj Kasichainula - manojk at io dot com - http://www.io.com/~manojk/
"This letter is clearly the result of too much spinning." -- The Tick
Re: Which thread/process
Posted by Dean Gaudet <dg...@arctic.org>.
On Sat, 11 Sep 1999, Zeev Suraski wrote:
> On Thu, 12 Aug 1999, Rasmus Lerdorf wrote:
>
> > > I suggest adding an index field to conn_rec. This number is set by
> > > the MPM after ap_new_connection is called. This way, mod_cgid can work
> > > properly even in an asynchronous threaded server.
> > >
> > > I'm guessing this field would be useful to other modules as well.
> > > PHP4's TSRM could possibly derive the indices it uses from
> > > conn_rec->index.
> > >
> > > Thoughts?
> >
> > That would work for us.
>
> As far as I recall, that's what Dean wanted to do in the first place.
> Our problem with it remains as it was - we don't have any access to the
> conn_rec structure from TSRM. We'll have to figure out a solution once
> Apache 2.0 materializes a bit more.
>
> Generally, I doubt we'd be able to use anything Apache-specific in TSRM,
> unless Apache will provide a globally-callable function to get a static &
> unique id for the current request. If that doesn't happen, we'll probably
> have to use pthread_self() or something similar, and give up running on
> some of the mpm hybrids.
we could provide you with a hook which gets called whenever the thread
running a connection changes. inside that hook you'll have the conn_rec.
stuff whatever you need into thread-local-memory.
but actually i don't even think that is required. because you get the
request_rec or conn_rec *every time your module is called*. i.e. in your
handler you have it. you may not have it inside your own code, because
you haven't passed the request_rec structure through to all your own
routines. but you've got the data you need at the point control passes
from apache to php... so you can stuff something into thread-local-memory
if you need to.
Dean
Re: Which thread/process
Posted by Zeev Suraski <bo...@netvision.net.il>.
On Thu, 12 Aug 1999, Rasmus Lerdorf wrote:
> > I suggest adding an index field to conn_rec. This number is set by
> > the MPM after ap_new_connection is called. This way, mod_cgid can work
> > properly even in an asynchronous threaded server.
> >
> > I'm guessing this field would be useful to other modules as well.
> > PHP4's TSRM could possibly derive the indices it uses from
> > conn_rec->index.
> >
> > Thoughts?
>
> That would work for us.
As far as I recall, that's what Dean wanted to do in the first place.
Our problem with it remains as it was - we don't have any access to the
conn_rec structure from TSRM. We'll have to figure out a solution once
Apache 2.0 materializes a bit more.
Generally, I doubt we'd be able to use anything Apache-specific in TSRM,
unless Apache will provide a globally-callable function to get a static &
unique id for the current request. If that doesn't happen, we'll probably
have to use pthread_self() or something similar, and give up running on
some of the mpm hybrids.
Zeev
--
-----------------------------------------------------
Zeev Suraski <ze...@zend.com> http://www.zend.com/
For a PGP public key, finger bourbon@netvision.net.il
Re: Which thread/process
Posted by Rasmus Lerdorf <ra...@apache.org>.
> I suggest adding an index field to conn_rec. This number is set by
> the MPM after ap_new_connection is called. This way, mod_cgid can work
> properly even in an asynchronous threaded server.
>
> I'm guessing this field would be useful to other modules as well.
> PHP4's TSRM could possibly derive the indices it uses from
> conn_rec->index.
>
> Thoughts?
That would work for us.
-Rasmus
Re: Which thread/process
Posted by Manoj Kasichainula <ma...@io.com>.
On Thu, Aug 12, 1999 at 10:52:56AM -0400, Ryan Bloom wrote:
>
> Okay, we took out the only place in the 2.0 tree where we designated a
> unique number for each thread within each process. Namely, the
> thread_num/child_num pair in the conn_rec. So how am I now supposed to
> get a deterministic value for the exact thread I am running in?
What you really need isn't a child_num/thread_num pair, but an
identifier for a connection that is unique at any given point in time
but repeats as often as possible (to minimize the number of named
pipes).
I suggest adding an index field to conn_rec. This number is set by
the MPM after ap_new_connection is called. This way, mod_cgid can work
properly even in an asynchronous threaded server.
I'm guessing this field would be useful to other modules as well.
PHP4's TSRM could possibly derive the indices it uses from
conn_rec->index.
Thoughts?
--
Manoj Kasichainula - manojk at io dot com - http://www.io.com/~manojk/
"By 'standie,' I mean those life-sized cardboard figures that stand up. By
'pirate,' I mean 'Arrrrr!'" -- Steve Jackson
Re: Which thread/process
Posted by Dean Gaudet <dg...@arctic.org>.
On Thu, 12 Aug 1999, Ryan Bloom wrote:
>
> > to be honest, i find your zillion of pipes solution to be extremely
> > distasteful.
>
> Why? The only one that are actually open, and the ones that are in use
> currently. When the server dies, they go away, and the purpose is
> performance. If I need to create three named pipes each time I want to
> execute a cgi, that is wasted time. I would much rather just open the
> pipes and execute the cgi.
Why? Your solution requires a priori knowledge of the maximum number of
concurrent requests possible. I don't believe this is knowledge which ANY
module should be privy to -- it requires too much of an intimate
understanding of what each MPM is doing.
What do you do when we can support 10000 concurrent connections? This is
not an impossible scenario, this is reality -- this is the realm that we
will be entering. You're going to have 10000 (or wait, is it 30000?)
named pipes sitting there consuming inodes? Oh are you going to start
putting a filesystem hash structure on them now because a directory with
30k filenames in it has linear lookup issues on most unixes?
I never suggested creating named pipes on the fly. I suggested creating
one during configuration.
You don't need three sockets -- sockets are bi-directional. One would
handle stdin/stdout.
stderr is connected to the log, you don't need it connected back to the
httpd child.
Let me be more explicit:
in httpd during post_config:
create unix domain socket $serverroot/logs/cgisock
fork() and create cgisockd process (actually use the
other_child API)
in httpd during the cgi handler:
fd = open("$serverroot/logs/cgisock", O_RDWR);
fill in a cgisock request structure
write(fd, &cgisock_req, sizeof(cgisock_req));
read/write gets you stdout/stdin of the cgi
in cgisockd:
cgisock = socket();
bind(cgisock, "$serverroot/logs/cgisock");
for(;;) {
fd = accept(cgisock);
if (fork() == 0) {
read(fd, &cgisock_req, sizeof(cgisock_req));
close(0);
close(1);
dup2(fd, 0);
dup2(fd, 1);
close(2);
dup2(lookup_correct_logfd(cgisock_req), 2);
exec(args from cgisock_req);
}
close(fd);
while (waitpid(-1, NULL, WNOHANG) > 0) {
;
}
}
Dean
Re: Which thread/process
Posted by Ryan Bloom <rb...@raleigh.ibm.com>.
> to be honest, i find your zillion of pipes solution to be extremely
> distasteful.
Why? The only one that are actually open, and the ones that are in use
currently. When the server dies, they go away, and the purpose is
performance. If I need to create three named pipes each time I want to
execute a cgi, that is wasted time. I would much rather just open the
pipes and execute the cgi.
>
> am i missing/forgetting something obviously wrong with a single unix
> socket solution? a daemon sitting on the unix socket doing accept() and
> fork()ing for each connection?
That's what we have, except that instead of using a unix socket, I am
using an anonymous pipe for that initial communication. It sounds like
you want the newly fork'ed process to then created three pipes for it's
communication to the child serving the request. That's wasted time.
Everytime a server has to execute a cgi, this would have to be done. It
seems so much more reasonable to just have the pipes available to be used.
Ryan
_______________________________________________________________________
Ryan Bloom rbb@raleigh.ibm.com
4205 S Miami Blvd
RTP, NC 27709 It's a beautiful sight to see good dancers
doing simple steps. It's a painful sight to
see beginners doing complicated patterns.
Re: Which thread/process
Posted by Dean Gaudet <dg...@arctic.org>.
On Thu, 12 Aug 1999, Ryan Bloom wrote:
> method would work without this information. As I said when we were
> removing this information, I think we removed it FAR too quickly without
> thinking of the implications. I would like to put back the thread_num and
> child_num unless somebody else can give me a way to get this information.
um, i've been advocating a connection index, just like manoj just
mentioned, for ages.
> For anybody who doesn't remember, mod_cgid is a module that creates a cgi
> daemon. It is VERY expensive on most *nix's to fork a threaded process,
> because all of the memory for all of the threads is copied, even though
> only one thread is active. To get around this problem, mod_cgid creates
> it's own cgi daemon at initialization time, and for all cgi's it, it forks
> this single-threaded daemon. Before anybody asks this time, this is not
> like cgisock. My goal is to keep 100% backward compatability. cgisock
> does not do this. cgisock will not run standard cgi's. mod_cgid MUST run
> standard cgi's.
to be honest, i find your zillion of pipes solution to be extremely
distasteful.
am i missing/forgetting something obviously wrong with a single unix
socket solution? a daemon sitting on the unix socket doing accept() and
fork()ing for each connection?
Dean