On 21.12.19 17:33, Aleksandar Lazic wrote:

Hi.

Dec 21, 2019 8:40:38 AM Christopher Faulet :

Le 20/12/2019 à 15:53, Aleksandar Lazic a écrit :

Hi.

Luckly that haproxy 2.1 have now the feature of fcgi proto it's now time to move
from nginx to haproxy for the loadbalancing part for me.

There are several features from nginx conf which I would like to port to haproxy
conf therefore I need some help ;-)

nginx offers a quite good caching feature like "fastcgi_cache_path". I know that
haproxy cache is only in memory. Have anyone a suggestion what's the "best" way
to cache the response from the fcgi backend?

http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_cache_path

That's the config values from nginx.

```
fastcgi_cache_path /opt/sde/nginx/fastcgi_cache_www levels=1:2 use_temp_path=off
keys_zone=www:256m max_size=256m;
fastcgi_cache_key "$scheme$host$request_uri$is_args$args";

fastcgi_cache_revalidate on;
fastcgi_cache_valid any 30s;
fastcgi_cache_use_stale error timeout updating http_500 http_503;
fastcgi_cache_lock on;

```

I know that there is nuster but have not yet 2.1 in use.



Hi Aleks,

If the fcgi response is cacheable, you can use the HAProxy cache, just like for
any other HTTP/1.1 response. The fcgi and the cache are two orthogonal feature.
You may use a dedicated cache for fcgi response, with specifics max-age and
max-object-size. About the "best" way to cache fcgi responses, it really depends
on your application. IMHO, it is your scripts responsibility to set the right
"Cache-Control" header.

Thanks for answer.

I would also like to modify the cache key but for now only host and uri is used 
as you can see in the code.

http://git.haproxy.org/?p=haproxy.git;a=blob;f=src/cache.c;h=8e2acd1cb191ef5678efdd776e54df7112d76509;hb=HEAD#l10587
http://git.haproxy.org/?p=haproxy.git;a=blob;f=src/cache.c;h=8e2acd1cb191ef5678efdd776e54df7112d76509;hb=HEAD#l1136

I would like to set such a key.

fastcgi_cache_key "$scheme$host$request_uri$is_args$args";

Okay after reread the 'sha1_hosturi(struct stream *s)' it looks like the default format is what I need. I will give the cache a try.

I think the magic statement is this in the code.

http://git.haproxy.org/?p=haproxy.git;a=blob;f=src/cache.c;h=8e2acd1cb191ef5678efdd776e54df7112d76509;hb=HEAD#l1083

uri = htx_sl_req_uri(sl); // whole uri

I assume it's also the query string in the uri variable.

It's like a feature request for something like this.

option cache_key "%[schema]℅[req.fhdr(host)]℅[url]℅[path]℅[query]"

option cache_key "sdbm(%[schema]℅[req.fhdr(host)]℅[url]℅[path]℅[query])"

option cache_key "%[schema]℅[req.fhdr(host)]℅[url]℅[path]" if ! %[query]

option cache_key "%[schema]℅[req.fhdr(host)]℅[url]℅[path]?℅[query]" if %[query]


Which function can be used to resolve the variables an use it for the key?

I'm not sure if $is_args have a equivalent variable in haproxy.

http://nginx.org/en/docs/http/ngx_http_core_module.html#var_is_args

Maybe the "option cache_key ... " should be able to have a "if/unless" 
possibility.

I could try to implement this ;-)

The idea is to have "option cache_key ..." and in " http_action_req_cache_use " 
check if the option is set if not use the current function else use the variables resolve function 
and make the sha2/xxhash64 hask key from the return of the variables resolve function.

Opinions?

Regards,
--
Christopher Faulet


Regards
Aleks




Reply via email to