[nominatim-web] Store cache in redis; limit lat/lon to 6 decimal places
- From: Bartłomiej Piotrowski <bpiotrowski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nominatim-web] Store cache in redis; limit lat/lon to 6 decimal places
- Date: Mon, 25 May 2020 12:18:59 +0000 (UTC)
commit f61263ca58ff962e2414f8bb85ce40e65d24790b
Author: Bartłomiej Piotrowski <bpiotrowski gnome org>
Date: Mon May 25 14:18:33 2020 +0200
Store cache in redis; limit lat/lon to 6 decimal places
nginx.conf | 66 ++++++++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 47 insertions(+), 19 deletions(-)
---
diff --git a/nginx.conf b/nginx.conf
index 29d0901..cd52243 100644
--- a/nginx.conf
+++ b/nginx.conf
@@ -18,7 +18,7 @@ http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
- '"$http_user_agent" "$http_x_forwarded_for" "$upstream_cache_status"';
+ '"$http_user_agent" "$http_x_forwarded_for" "$srcache_fetch_status"';
access_log /usr/local/openresty/nginx/logs/access.log main;
@@ -33,12 +33,10 @@ http {
server nominatim-int.gnome.org:80;
}
- proxy_cache_path /tmp/nominatim keys_zone=nominatim:100m
- levels=1:2 max_size=2g inactive=30d use_temp_path=off;
- proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
- proxy_cache_revalidate on;
- proxy_cache_background_update on;
- proxy_buffering on;
+ upstream redis {
+ server redis.nominatim-web.svc.cluster.local:6379;
+ keepalive 300;
+ }
server {
listen 8080 default_server;
@@ -54,26 +52,56 @@ http {
set $lang $1;
}
+ location /redis-fetch {
+ internal;
+ set_md5 $redis_key $args;
+ redis_pass redis;
+ }
+
+ location /redis-store {
+ internal;
+ set_md5 $key $arg_key;
+ redis2_query set $key $echo_request_body;
+ redis2_query expire $key 2592000;
+ redis2_pass redis;
+ }
+
location = /search {
- proxy_cache nominatim;
- proxy_cache_key search$lang$arg_limit$arg_q$arg_country$arg_state$arg_city$arg_street;
- proxy_cache_valid 200 30d;
- proxy_cache_lock on;
+ set $cache_key search_$lang$arg_limit$arg_q$arg_country$arg_state$arg_city$arg_street;
+ srcache_fetch GET /redis-fetch $cache_key;
+ srcache_store PUT /redis-store key=$cache_key;
+ srcache_store_no_cache on;
+ srcache_response_cache_control off;
proxy_pass http://nominatim/search;
- proxy_set_header Host "nominatim-int.gnome.org";
- add_header X-Cache-Status $upstream_cache_status;
+ proxy_set_header Host "nominatim.gnome.org";
}
location = /reverse {
- proxy_cache nominatim;
- proxy_cache_key reverse$lang$arg_lon$arg_lat;
- proxy_cache_valid 200 30d;
- proxy_cache_lock on;
+ set_by_lua_block $coord {
+ local shorten = function (str)
+ if string.sub(str,1,1) == "-" then
+ return string.sub(str,1,9)
+ else
+ return string.sub(str,1,8)
+ end
+ end
+
+ local args = ngx.req.get_uri_args()
+ local lat = shorten(args["lat"])
+ local lon = shorten(args["lon"])
+
+ return lat .. "x" .. lon
+ }
+
+ set $cache_key reverse_$lang$coord;
+ srcache_fetch GET /redis-fetch $cache_key;
+ srcache_store PUT /redis-store key=$cache_key;
+ srcache_store_no_cache on;
+ srcache_response_cache_control off;
proxy_pass http://nominatim/reverse;
- proxy_set_header Host "nominatim-int.gnome.org";
- add_header X-Cache-Status $upstream_cache_status;
+ proxy_set_header Host "nominatim.gnome.org";
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]