summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-06-20 21:10:16 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-06-20 22:25:41 -0400
commit1a171303b442351cf2b63038776f856902cce1dd (patch)
tree57fa532de533d111a76b8808253869026aae348e
parenta6914b4761bbedc27a7199a5c05466fdd0edb905 (diff)
assistant: On Linux, the expensive transfer scan is run niced.
This is a compromise. I would like to nice every thread except for the webapp thread, but it's not practical to do so. That would need every thread to run as a bound thread, which could add significant overhead. And any forkIO would escape the nice level.
-rw-r--r--Assistant/Threads/TransferScanner.hs3
-rw-r--r--Utility/Batch.hs40
-rw-r--r--debian/changelog1
-rw-r--r--git-annex.cabal3
4 files changed, 46 insertions, 1 deletions
diff --git a/Assistant/Threads/TransferScanner.hs b/Assistant/Threads/TransferScanner.hs
index 46695469e..5a6871fdb 100644
--- a/Assistant/Threads/TransferScanner.hs
+++ b/Assistant/Threads/TransferScanner.hs
@@ -24,6 +24,7 @@ import qualified Remote
import qualified Types.Remote as Remote
import Utility.ThreadScheduler
import Utility.NotificationBroadcaster
+import Utility.Batch
import qualified Git.LsFiles as LsFiles
import qualified Backend
import Annex.Content
@@ -114,7 +115,7 @@ failedTransferScan r = do
- since we need to look at the locations of all keys anyway.
-}
expensiveScan :: UrlRenderer -> [Remote] -> Assistant ()
-expensiveScan urlrenderer rs = unless onlyweb $ do
+expensiveScan urlrenderer rs = unless onlyweb $ batch <~> do
debug ["starting scan of", show visiblers]
unwantedrs <- liftAnnex $ S.fromList
diff --git a/Utility/Batch.hs b/Utility/Batch.hs
new file mode 100644
index 000000000..38b588b34
--- /dev/null
+++ b/Utility/Batch.hs
@@ -0,0 +1,40 @@
+{- Running a long or expensive batch operation niced.
+ -
+ - Copyright 2013 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+{-# LANGUAGE CPP #-}
+
+module Utility.Batch where
+
+#if defined(__LINUX__) || defined(__ANDROID__)
+import Control.Concurrent.Async
+import System.Posix.Process
+#endif
+
+{- Runs an operation, at batch priority.
+ -
+ - This is done by running it in a bound thread, which on Linux can be set
+ - to have a different nice level than the rest of the program. Note that
+ - due to running in a bound thread, some operations may be more expensive
+ - to perform. Also note that if the action calls forkIO or forkOS itself,
+ - that will make a new thread that does not have the batch priority.
+ -
+ - POSIX threads do not support separate nice levels, so on other operating
+ - systems, the action is simply ran.
+ -}
+batch :: IO a -> IO a
+#if defined(__LINUX__) || defined(__ANDROID__)
+batch a = wait =<< batchthread
+ where
+ batchthread = asyncBound $ do
+ setProcessPriority 0 maxNice
+ a
+#else
+batch a = a
+#endif
+
+maxNice :: Int
+maxNice = 19
diff --git a/debian/changelog b/debian/changelog
index d907b6ed3..81d28087c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -35,6 +35,7 @@ git-annex (4.20130602) UNRELEASED; urgency=low
git-annex branch.
* Windows: The test suite now passes on Windows (a few broken parts are
disabled).
+ * assistant: On Linux, the expensive transfer scan is run niced.
-- Joey Hess <joeyh@debian.org> Mon, 10 Jun 2013 12:52:44 -0400
diff --git a/git-annex.cabal b/git-annex.cabal
index 210b64b01..5ac4d0f0b 100644
--- a/git-annex.cabal
+++ b/git-annex.cabal
@@ -115,6 +115,9 @@ Executable git-annex
Build-Depends: data-endian
CPP-Options: -D__ANDROID__
+ if os(linux)
+ CPP-Options: -D__LINUX__
+
if os(linux) && flag(Inotify)
Build-Depends: hinotify
CPP-Options: -DWITH_INOTIFY