mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-04 00:32:51 -06:00
PGF Service: limit the number of parallel calls to the C run-time parse function to 4 by default
The limit can be changed with the -j flag
This commit is contained in:
@@ -71,11 +71,12 @@ shell opts files = loop opts =<< runSIO (importInEnv emptyGFEnv opts files)
|
|||||||
-- | Run the GF Server (@gf -server@).
|
-- | Run the GF Server (@gf -server@).
|
||||||
-- The 'Int' argument is the port number for the HTTP service.
|
-- The 'Int' argument is the port number for the HTTP service.
|
||||||
mainServerGFI opts0 port files =
|
mainServerGFI opts0 port files =
|
||||||
server port root (execute1 opts)
|
server jobs port root (execute1 opts)
|
||||||
=<< runSIO (importInEnv emptyGFEnv opts files)
|
=<< runSIO (importInEnv emptyGFEnv opts files)
|
||||||
where
|
where
|
||||||
root = flag optDocumentRoot opts
|
root = flag optDocumentRoot opts
|
||||||
opts = beQuiet opts0
|
opts = beQuiet opts0
|
||||||
|
jobs = join (flag optJobs opts)
|
||||||
#else
|
#else
|
||||||
mainServerGFI opts files =
|
mainServerGFI opts files =
|
||||||
error "GF has not been compiled with server mode support"
|
error "GF has not been compiled with server mode support"
|
||||||
|
|||||||
@@ -56,10 +56,10 @@ import URLEncoding(decodeQuery)
|
|||||||
debug s = logPutStrLn s
|
debug s = logPutStrLn s
|
||||||
|
|
||||||
-- | Combined FastCGI and HTTP server
|
-- | Combined FastCGI and HTTP server
|
||||||
server port optroot execute1 state0 =
|
server jobs port optroot execute1 state0 =
|
||||||
do --stderrToFile logFile
|
do --stderrToFile logFile
|
||||||
state <- newMVar M.empty
|
state <- newMVar M.empty
|
||||||
cache <- PS.newPGFCache
|
cache <- PS.newPGFCache jobs
|
||||||
datadir <- getDataDir
|
datadir <- getDataDir
|
||||||
let root = maybe (datadir</>"www") id optroot
|
let root = maybe (datadir</>"www") id optroot
|
||||||
-- debug $ "document root="++root
|
-- debug $ "document root="++root
|
||||||
|
|||||||
@@ -56,21 +56,25 @@ logFile :: FilePath
|
|||||||
logFile = "pgf-error.log"
|
logFile = "pgf-error.log"
|
||||||
|
|
||||||
#ifdef C_RUNTIME
|
#ifdef C_RUNTIME
|
||||||
type Caches = (Cache PGF,Cache (C.PGF,({-MVar ParseCache-})))
|
type Caches = (Cache PGF,(Cache (C.PGF,({-MVar ParseCache-})),QSem))
|
||||||
|
--type Caches = (Cache PGF,Cache (C.PGF,({-MVar ParseCache-})))
|
||||||
--type ParseCache = Map.Map (String,String) (ParseResult,UTCTime)
|
--type ParseCache = Map.Map (String,String) (ParseResult,UTCTime)
|
||||||
--type ParseResult = Either String [(C.Expr,Float)]
|
--type ParseResult = Either String [(C.Expr,Float)]
|
||||||
|
|
||||||
newPGFCache = do pgfCache <- newCache' PGF.readPGF
|
newPGFCache jobs = do pgfCache <- newCache' PGF.readPGF
|
||||||
cCache <- newCache' $ \ path -> do pgf <- C.readPGF path
|
let n = maybe 4 id jobs
|
||||||
--pc <- newMVar Map.empty
|
putStrLn $ "Parallel parsing limit: "++show n
|
||||||
return (pgf,({-pc-}))
|
qsem <- newQSem n
|
||||||
return (pgfCache,cCache)
|
cCache <- newCache' $ \ path -> do pgf <- C.readPGF path
|
||||||
flushPGFCache (c1,c2) = flushCache c1 >> flushCache c2
|
--pc <- newMVar Map.empty
|
||||||
listPGFCache (c1,c2) = (,) # listCache c1 % listCache c2
|
return (pgf,({-pc-}))
|
||||||
|
return (pgfCache,(cCache,qsem))
|
||||||
|
flushPGFCache (c1,(c2,_)) = flushCache c1 >> flushCache c2
|
||||||
|
listPGFCache (c1,(c2,_)) = (,) # listCache c1 % listCache c2
|
||||||
#else
|
#else
|
||||||
type Caches = (Cache PGF,())
|
type Caches = (Cache PGF,())
|
||||||
newPGFCache = do pgfCache <- newCache' PGF.readPGF
|
newPGFCache _ = do pgfCache <- newCache' PGF.readPGF
|
||||||
return (pgfCache,())
|
return (pgfCache,())
|
||||||
flushPGFCache (c1,_) = flushCache c1
|
flushPGFCache (c1,_) = flushCache c1
|
||||||
listPGFCache (c1,_) = (,) # listCache c1 % return []
|
listPGFCache (c1,_) = (,) # listCache c1 % return []
|
||||||
#endif
|
#endif
|
||||||
@@ -100,7 +104,8 @@ cgiMain' cache path =
|
|||||||
"download" -> outputBinary =<< getFile BS.readFile path
|
"download" -> outputBinary =<< getFile BS.readFile path
|
||||||
'c':'-':_ ->
|
'c':'-':_ ->
|
||||||
#ifdef C_RUNTIME
|
#ifdef C_RUNTIME
|
||||||
cpgfMain command =<< getFile (readCache' (snd cache)) path
|
cpgfMain (snd (snd cache)) command
|
||||||
|
=<< getFile (readCache' (fst (snd cache))) path
|
||||||
#else
|
#else
|
||||||
serverError "Server configured without C run-time support" ""
|
serverError "Server configured without C run-time support" ""
|
||||||
#endif
|
#endif
|
||||||
@@ -118,7 +123,7 @@ getFile get path =
|
|||||||
|
|
||||||
#ifdef C_RUNTIME
|
#ifdef C_RUNTIME
|
||||||
--cpgfMain :: String -> (C.PGF,MVar ParseCache) -> CGI CGIResult
|
--cpgfMain :: String -> (C.PGF,MVar ParseCache) -> CGI CGIResult
|
||||||
cpgfMain command (t,(pgf,pc)) =
|
cpgfMain qsem command (t,(pgf,pc)) =
|
||||||
case command of
|
case command of
|
||||||
"c-parse" -> out t=<< join (parse # input % start % limit % trie)
|
"c-parse" -> out t=<< join (parse # input % start % limit % trie)
|
||||||
"c-linearize" -> out t=<< lin # tree % to
|
"c-linearize" -> out t=<< lin # tree % to
|
||||||
@@ -156,8 +161,8 @@ cpgfMain command (t,(pgf,pc)) =
|
|||||||
|
|
||||||
-- Without caching parse results:
|
-- Without caching parse results:
|
||||||
parse' start mlimit ((from,concr),input) =
|
parse' start mlimit ((from,concr),input) =
|
||||||
return $
|
liftIO $ E.bracket_ (waitQSem qsem) (signalQSem qsem)
|
||||||
maybe id take mlimit . drop start # cparse
|
(return $! maybe id take mlimit . drop start # cparse)
|
||||||
where
|
where
|
||||||
--cparse = C.parse concr cat input
|
--cparse = C.parse concr cat input
|
||||||
cparse = C.parseWithHeuristics concr cat input (-1) callbacks
|
cparse = C.parseWithHeuristics concr cat input (-1) callbacks
|
||||||
|
|||||||
Reference in New Issue
Block a user