Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell MongoDB驱动程序可能出现死锁_Mongodb_Haskell_Concurrency_Database Connection - Fatal编程技术网

Haskell MongoDB驱动程序可能出现死锁

Haskell MongoDB驱动程序可能出现死锁,mongodb,haskell,concurrency,database-connection,Mongodb,Haskell,Concurrency,Database Connection,从ghc 7.4升级到ghc 7.6后,我注意到我的一些数据库调用速度降低了40倍。为了调查,我写了一些简单的测试,我的代码基本上是: timeFetch :: Pipe -> UUID.UUID -> IO () timeFetch pipe uuid' = do lrResult <- access pipe master "MyDB" $ (findOne (select ["uid" =: ["$in" =: [(uuidToBUUID uuid')]]] "uid

从ghc 7.4升级到ghc 7.6后,我注意到我的一些数据库调用速度降低了40倍。为了调查,我写了一些简单的测试,我的代码基本上是:

timeFetch :: Pipe -> UUID.UUID -> IO ()
timeFetch pipe uuid' = do
  lrResult <- access pipe master "MyDB" $ (findOne (select ["uid" =: ["$in" =: [(uuidToBUUID uuid')]]] "uidCollection") :: Action IO (Maybe Document))
  case lrResult of
    Right _ -> do
      printCrntTm "Right has result"
      timeFetch pipe uuid'
    Left _  -> printCrntTm "Left err"
但在GHC 7.4中,我看到:

2013-12-09 09:36:38.109144 UTC Right has result
2013-12-09 09:36:38.110297 UTC Right has result
2013-12-09 09:36:38.111248 UTC Right has result
2013-12-09 09:36:38.112398 UTC Right has result
2013-12-09 09:36:38.113185 UTC Right has result
2013-12-09 09:36:38.114248 UTC Right has result
这相当于1ms vs 40ms!!!我还需要提到的是,7.6版本有一次,我得到了:
***异常:在MVar操作中线程被无限期阻塞
(但不再是),这就引出了我的主要问题

我仔细研究了一下,不知道中的这些代码行是否是罪魁祸首:

newCursor :: (MonadIO m, MonadBaseControl IO m) => Database -> Collection -> BatchSize -> DelayedBatch -> Action m Cursor
-- ^ Create new cursor. If you don't read all results then close it. Cursor will be closed automatically when all results are read from it or when eventually garbage collected.
newCursor db col batchSize dBatch = do
    var <- newMVar dBatch
    let cursor = Cursor (db <.> col) batchSize var
    mkWeakMVar var (closeCursor cursor)
    return cursor
#if !MIN_VERSION_base(4,6,0)
  where mkWeakMVar = addMVarFinalizer
#endif
newCursor::(MonadIO m,MonadBaseControl IO m)=>Database->Collection->BatchSize->DelayedBatch->Action m Cursor
--^创建新光标。如果没有读取所有结果,请关闭它。当从游标中读取所有结果或最终进行垃圾回收时,游标将自动关闭。
newCursor db col batchSize dBatch=do

varMongoDB驱动程序肯定非常慢。可能有很多低挂果实,使其更快,就像只是删除管道连接系统

newCursor :: (MonadIO m, MonadBaseControl IO m) => Database -> Collection -> BatchSize -> DelayedBatch -> Action m Cursor
-- ^ Create new cursor. If you don't read all results then close it. Cursor will be closed automatically when all results are read from it or when eventually garbage collected.
newCursor db col batchSize dBatch = do
    var <- newMVar dBatch
    let cursor = Cursor (db <.> col) batchSize var
    mkWeakMVar var (closeCursor cursor)
    return cursor
#if !MIN_VERSION_base(4,6,0)
  where mkWeakMVar = addMVarFinalizer
#endif