Commit f11cbb7f authored by Camil Staps's avatar Camil Staps 🚀

Reload cache without forking

This will cause a longer timeout when updating, but the fork apparently
causes performances issues
parent c8dc44d5
Pipeline #17222 passed with stage
in 14 minutes and 34 seconds
...@@ -194,7 +194,8 @@ Start w ...@@ -194,7 +194,8 @@ Start w
# (ok,f,w) = fopen (fromJust opts.test_file) FReadText w # (ok,f,w) = fopen (fromJust opts.test_file) FReadText w
| not ok = errexit "Could not open test file\n" -1 w | not ok = errexit "Could not open test file\n" -1 w
= test opts.test_options f db w = test opts.test_options f db w
#! (db,w) = if opts.reload_cache (doInBackground reloadCache) id (db,w) | opts.reload_cache
= reloadCache db w
= serve = serve
{ handler = handle { handler = handle
, logger = Just log , logger = Just log
...@@ -284,26 +285,19 @@ where ...@@ -284,26 +285,19 @@ where
} }
(give,keep) = splitAt MAX_RESULTS results (give,keep) = splitAt MAX_RESULTS results
reloadCache :: !*(!*CloogleDB, !*World) -> *(!*CloogleDB, !*World) reloadCache :: !*CloogleDB !*World -> *World
reloadCache (db,w) reloadCache db w
# (ks,w) = allCacheKeys LongTerm w # (ks,w) = allCacheKeys LongTerm w
= loop ks db w = loop ks db w
where where
loop :: ![RequestCacheKey] !*CloogleDB !*World -> *(!*CloogleDB, !*World) loop :: ![RequestCacheKey] !*CloogleDB !*World -> *World
loop [] db w = (db,w) loop [] _ w = w
loop [k:ks] db w loop [k:ks] db w
# w = removeFromCache LongTerm k w # w = removeFromCache LongTerm k w
# (_,_,db,w) = handle (Just $ fromRequestCacheKey k) db w # (_,_,db,w) = handle (Just $ fromRequestCacheKey k) db w
# db = resetDB db # db = resetDB db
= loop ks db w = loop ks db w
doInBackground :: (*a -> *a) *a -> *a
doInBackground f w
#! (pid,w) = fork w
| pid < 0 = abort "fork failed\n"
| pid > 0 = w // Parent: return directly
| otherwise = snd $ exit 0 $ f w // Child: do function
test :: ![TestOption] !*File !*CloogleDB !*World -> *World test :: ![TestOption] !*File !*CloogleDB !*World -> *World
test opts queries db w test opts queries db w
# (e,queries) = fend queries # (e,queries) = fend queries
......
#!/bin/sh #!/bin/sh
mkdir -p ./cache/lt ./cache/brief mkdir -p ./cache/lt ./cache/brief
RELOAD="--reload-cache" stdbuf -i0 -o0 -e0 ./CloogleServer --reload-cache | tee -a cloogle.log
while : while :
do do
stdbuf -i0 -o0 -e0 ./CloogleServer -p 31215 $RELOAD | tee -a cloogle.log stdbuf -i0 -o0 -e0 ./CloogleServer -p 31215 | tee -a cloogle.log
RELOAD=""
done done
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment