Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Przemyslaw Kaminski
haskell-gargantext
Commits
a0bc6f1e
Commit
a0bc6f1e
authored
Mar 02, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[OPTIM] concurrent threads (fix mem leaks)
parent
5859a1e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
8 deletions
+42
-8
New.hs
src/Gargantext/API/Corpus/New.hs
+27
-2
API.hs
src/Gargantext/Viz/Graph/API.hs
+15
-6
No files found.
src/Gargantext/API/Corpus/New.hs
View file @
a0bc6f1e
...
@@ -27,6 +27,7 @@ module Gargantext.API.Corpus.New
...
@@ -27,6 +27,7 @@ module Gargantext.API.Corpus.New
--import Gargantext.Text.Corpus.Parsers (parseFile, FileFormat(..))
--import Gargantext.Text.Corpus.Parsers (parseFile, FileFormat(..))
import
Control.Lens
hiding
(
elements
)
import
Control.Lens
hiding
(
elements
)
import
Control.Monad.IO.Class
(
liftIO
)
import
Control.Monad.IO.Class
(
liftIO
)
import
Control.Concurrent
import
Data.Aeson
import
Data.Aeson
import
Data.Aeson.TH
(
deriveJSON
)
import
Data.Aeson.TH
(
deriveJSON
)
import
Data.Maybe
(
fromMaybe
)
import
Data.Maybe
(
fromMaybe
)
...
@@ -218,6 +219,23 @@ addToCorpusWithFile cid input filetype logStatus = do
...
@@ -218,6 +219,23 @@ addToCorpusWithFile cid input filetype logStatus = do
,
_scst_events
=
Just
[]
,
_scst_events
=
Just
[]
}
}
{- | Model to fork the flow
-- This is not really optimized since it increases the need RAM
-- and freezes the whole system
-- This is mainly for documentation (see a better solution in the function below)
-- Each process has to be tailored
addToCorpusWithForm' :: FlowCmdM env err m
=> CorpusId
-> WithForm
-> (ScraperStatus -> m ())
-> m ScraperStatus
addToCorpusWithForm' cid (WithForm ft d l) logStatus = do
newStatus <- liftIO newEmptyMVar
s <- addToCorpusWithForm cid (WithForm ft d l) logStatus
_ <- liftIO $ forkIO $ putMVar newStatus s
s' <- liftIO $ takeMVar newStatus
pure s'
-}
addToCorpusWithForm
::
FlowCmdM
env
err
m
addToCorpusWithForm
::
FlowCmdM
env
err
m
=>
CorpusId
=>
CorpusId
->
WithForm
->
WithForm
...
@@ -234,22 +252,29 @@ addToCorpusWithForm cid (WithForm ft d l) logStatus = do
...
@@ -234,22 +252,29 @@ addToCorpusWithForm cid (WithForm ft d l) logStatus = do
WOS
->
Parser
.
parseFormat
Parser
.
WOS
WOS
->
Parser
.
parseFormat
Parser
.
WOS
PresseRIS
->
Parser
.
parseFormat
Parser
.
RisPresse
PresseRIS
->
Parser
.
parseFormat
Parser
.
RisPresse
newDocs
<-
liftIO
newEmptyMVar
docs
<-
liftIO
docs
<-
liftIO
$
splitEvery
500
$
splitEvery
500
<$>
take
1000000
<$>
take
1000000
<$>
parse
(
cs
d
)
<$>
parse
(
cs
d
)
_
<-
liftIO
$
forkIO
$
putMVar
newDocs
docs
logStatus
ScraperStatus
{
_scst_succeeded
=
Just
1
logStatus
ScraperStatus
{
_scst_succeeded
=
Just
1
,
_scst_failed
=
Just
0
,
_scst_failed
=
Just
0
,
_scst_remaining
=
Just
1
,
_scst_remaining
=
Just
1
,
_scst_events
=
Just
[]
,
_scst_events
=
Just
[]
}
}
docs'
<-
liftIO
$
takeMVar
newDocs
newCid
<-
liftIO
newEmptyMVar
cid'
<-
flowCorpus
"user1"
cid'
<-
flowCorpus
"user1"
(
Right
[
cid
])
(
Right
[
cid
])
(
Multi
$
fromMaybe
EN
l
)
(
Multi
$
fromMaybe
EN
l
)
(
map
(
map
toHyperdataDocument
)
docs
)
(
map
(
map
toHyperdataDocument
)
docs'
)
_
<-
liftIO
$
forkIO
$
putMVar
newCid
cid'
printDebug
"cid'"
cid'
cid''
<-
liftIO
$
takeMVar
newCid
printDebug
"cid'"
cid''
pure
ScraperStatus
{
_scst_succeeded
=
Just
2
pure
ScraperStatus
{
_scst_succeeded
=
Just
2
,
_scst_failed
=
Just
0
,
_scst_failed
=
Just
0
...
...
src/Gargantext/Viz/Graph/API.hs
View file @
a0bc6f1e
...
@@ -62,16 +62,22 @@ graphAPI u n = getGraph u n
...
@@ -62,16 +62,22 @@ graphAPI u n = getGraph u n
:<|>
putGraph
n
:<|>
putGraph
n
------------------------------------------------------------------------
------------------------------------------------------------------------
getGraph
::
UserId
->
NodeId
->
GargServer
(
Get
'[
J
SON
]
Graph
)
getGraph
u
n
=
do
{- Model to fork Graph Computation
-- This is not really optimized since it increases the need RAM
-- and freezes the whole system
-- This is mainly for documentation (see a better solution in the function below)
-- Each process has to be tailored
getGraph' :: UserId -> NodeId -> GargServer (Get '[JSON] Graph)
getGraph' u n = do
newGraph <- liftIO newEmptyMVar
newGraph <- liftIO newEmptyMVar
g <- getGraph u n
g <- getGraph u n
_ <- liftIO $ forkIO $ putMVar newGraph g
_ <- liftIO $ forkIO $ putMVar newGraph g
g' <- liftIO $ takeMVar newGraph
g' <- liftIO $ takeMVar newGraph
pure g'
pure g'
-}
getGraph
'
::
UserId
->
NodeId
->
GargNoServer
Graph
getGraph
::
UserId
->
NodeId
->
GargNoServer
Graph
getGraph
'
uId
nId
=
do
getGraph
uId
nId
=
do
nodeGraph
<-
getNodeWith
nId
HyperdataGraph
nodeGraph
<-
getNodeWith
nId
HyperdataGraph
let
graph
=
nodeGraph
^.
node_hyperdata
.
hyperdataGraph
let
graph
=
nodeGraph
^.
node_hyperdata
.
hyperdataGraph
let
listVersion
=
graph
^?
_Just
let
listVersion
=
graph
^?
_Just
...
@@ -90,6 +96,7 @@ getGraph' uId nId = do
...
@@ -90,6 +96,7 @@ getGraph' uId nId = do
identity
identity
$
nodeGraph
^.
node_parentId
$
nodeGraph
^.
node_parentId
newGraph
<-
liftIO
newEmptyMVar
g
<-
case
graph
of
g
<-
case
graph
of
Nothing
->
do
Nothing
->
do
graph'
<-
computeGraph
cId
NgramsTerms
repo
graph'
<-
computeGraph
cId
NgramsTerms
repo
...
@@ -102,7 +109,9 @@ getGraph' uId nId = do
...
@@ -102,7 +109,9 @@ getGraph' uId nId = do
graph''
<-
computeGraph
cId
NgramsTerms
repo
graph''
<-
computeGraph
cId
NgramsTerms
repo
_
<-
updateHyperdata
nId
(
HyperdataGraph
$
Just
graph''
)
_
<-
updateHyperdata
nId
(
HyperdataGraph
$
Just
graph''
)
pure
graph''
pure
graph''
pure
{- $ trace (show g) $ -}
g
_
<-
liftIO
$
forkIO
$
putMVar
newGraph
g
g'
<-
liftIO
$
takeMVar
newGraph
pure
{- $ trace (show g) $ -}
g'
-- TODO use Database Monad only here ?
-- TODO use Database Monad only here ?
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment