Comparison

plugins/mod_http_file_share.lua @ 11357:8cb2a64b15da

mod_http_file_share: Collect cache hit/miss statistics for downloads
author Kim Alvefur <zash@zash.se>
date Tue, 02 Feb 2021 22:16:20 +0100
parent 11356:43e5429ab355
child 11374:5b8aec0609f0
comparison
equal deleted inserted replaced
11356:43e5429ab355 11357:8cb2a64b15da
272 end 272 end
273 end 273 end
274 274
275 end 275 end
276 276
277 local download_cache_hit = module:measure("download_cache_hit", "rate");
278 local download_cache_miss = module:measure("download_cache_miss", "rate");
279
277 function handle_download(event, path) -- GET /uploads/:slot+filename 280 function handle_download(event, path) -- GET /uploads/:slot+filename
278 local request, response = event.request, event.response; 281 local request, response = event.request, event.response;
279 local slot_id = path:match("^[^/]+"); 282 local slot_id = path:match("^[^/]+");
280 local basename, filetime, filetype, filesize; 283 local basename, filetime, filetype, filesize;
281 local cached = upload_cache:get(slot_id); 284 local cached = upload_cache:get(slot_id);
282 if cached then 285 if cached then
283 module:log("debug", "Cache hit"); 286 module:log("debug", "Cache hit");
284 -- TODO stats (instead of logging?) 287 download_cache_hit();
285 basename = cached.name; 288 basename = cached.name;
286 filesize = cached.size; 289 filesize = cached.size;
287 filetype = cached.type; 290 filetype = cached.type;
288 filetime = cached.time; 291 filetime = cached.time;
289 upload_cache:set(slot_id, cached); 292 upload_cache:set(slot_id, cached);
290 -- TODO cache negative hits? 293 -- TODO cache negative hits?
291 else 294 else
292 module:log("debug", "Cache miss"); 295 module:log("debug", "Cache miss");
296 download_cache_miss();
293 local slot, when = errors.coerce(uploads:get(nil, slot_id)); 297 local slot, when = errors.coerce(uploads:get(nil, slot_id));
294 if not slot then 298 if not slot then
295 module:log("debug", "uploads:get(%q) --> not-found, %s", slot_id, when); 299 module:log("debug", "uploads:get(%q) --> not-found, %s", slot_id, when);
296 else 300 else
297 module:log("debug", "uploads:get(%q) --> %s, %d", slot_id, slot, when); 301 module:log("debug", "uploads:get(%q) --> %s, %d", slot_id, slot, when);