On Fri, Apr 10, 2020 at 2:36 PM Christopher Schultz
<ch...@christopherschultz.net> wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> All,
>
> First-time httpd hacker, here. I'm looking at:
> https://bz.apache.org/bugzilla/show_bug.cgi?id=64338
>
> I've found that around line 637 of mod_proxy_balancer.c it looks like
> I just need to poke a value into the r->subprocess_env like this:
>
>         apt_table_setn(r->subprocess_env,
>                        "BALANCER_WORKER_STATUS", XXX);
>
> The question is what "XXX" should be. I need to convert
> (*worker)->s->status (an unsigned int) into a char*.
>
> I can manually malloc a char*, stick it in there, and deallocate it
> each time back through, but that will leak memory when the pool is
> recycled and I don't get a chance to free my char*.
>
> I can use apt_table_set instead of apt_table_setn but that will make
> performance suck even more than a single allocation each time
> mod_proxy handles a request.
>
> I can also use something like apr_itoa/apr_ltoa which will allocate
> from the pool which presumably will be cleaned-up at some point,
> but... when? I don't know anything about how APR/httpd handle memory
> management and I'm afraid I'll much it all up if I don't ask this
> question.
>
> So ... what's the right way to do this?
>
> A performance optimization is likely to be that most workers (a) have
> all the same "everything is fine" status and (b) the status doesn't
> change very often. So maybe having a table of predefined status
> strings sitting around wouldn't be the worth possible thing in the
> world; that would avoid many needless memory (re)allocations.

Hi Chris.  You have access to a request_rec then you can allocate from r->pool.
Allocations from there are automatically returned at the end of the request.

You could also just test the value in that status field and "setn" the
variable to a constant character or string.

Note: If you move to r->notes (also a table) you can use
apr_table_setn to pass a casted pointer and retrieve the pointer on
the other side.  But this is probably a last resort.

Reply via email to