nginx-devel Digest, Vol 38, Issue 2

Ruslan Ermilov ru at nginx.com
Tue Dec 4 10:06:25 UTC 2012


On Tue, Dec 04, 2012 at 04:57:32PM +1100, Lawrence Pit wrote:
> >> After I finished this patch I checked the 1.3 branch, and noticed it
> >> already has an $msec http variable defined. But it's output is with a
> >> dot character before the milliseconds part. Why is that?
> >
> > http {
> >  map $msec $s {
> > 	~(?<x>.*)\. $x;
> >  }
> >
> >  map $msec $ms {
> > 	~\.(?<x>.*) $x;
> >  }
> >
> >  server {
> > 	return 200 "msec=$msec usec=${s}${ms}000\n";
> >  }
> > }
> >
> > $ curl http://localhost:8000/
> > msec=1354471012.591 usec=1354471012591000
> 
> That's cool, impressive. Though ugly ;)  If it needs to do that for 
> every request it's relatively expensive compared to what I'd rather do:
> 
>     proxy_set_header X-Queue-Start "${msec}000";
> 
> Is there any objection to not output the dot character starting from the 
> 1.3 release?

We absolutely don't want two different $msec variables, and $msec
was documented to be holding a value in seconds with a milliseconds
resolution for ages.

Log-only variables are there only for historical reasons.  The current
trend seems to be to make most if not all of them generic variables, in
particular to make such manipulations possible, though of course some
of them continue to make sense only when logging (but that is at the
user's discretion).

> My reason for not using the dot character is that it seems like an 
> arbitrary view concern to me and when the value is not used for logging 
> purposes it's most likely to be used for calculations or conversions; in 
> which case not having to parse out the dot character makes things 
> simpler.



More information about the nginx-devel mailing list