From 7e2ea27e5d56f5cf767a6718a0f5edc28e24af14 Mon Sep 17 00:00:00 2001 From: Armin Le Grand Date: Wed, 16 Mar 2016 15:14:13 +0100 Subject: tdf#93553 limit parallelism at zip save time to useful amount At ODT export time writing and zipping comtained data packages is nicely parallelized, but not limited to an upper bounds of threads to use. Together with memory consumption this makes ressource usage and runtime behaviour bad to crashing (mostly on 32bit). I have now limited the processing dependent on the number of available cores to get a good processing/ressource ratio. The result uses much less memory, is faster and runs on 32bit systems. Change-Id: I8bd516a9a0cefd644f5d7001214bc717f29770ab Reviewed-on: https://gerrit.libreoffice.org/23305 Tested-by: Jenkins Reviewed-by: Noel Grandin --- package/source/zippackage/ZipPackageStream.cxx | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'package/source/zippackage/ZipPackageStream.cxx') diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx index 2fbcfdba19ff..a183cf651796 100644 --- a/package/source/zippackage/ZipPackageStream.cxx +++ b/package/source/zippackage/ZipPackageStream.cxx @@ -54,6 +54,7 @@ #include #include +#include using namespace com::sun::star::packages::zip::ZipConstants; using namespace com::sun::star::packages::zip; @@ -478,6 +479,7 @@ private: deflateZipEntry(mpEntry, mxInStream); mxInStream.clear(); mpEntry->closeBufferFile(); + mpEntry->setFinished(); } catch (const uno::Exception&) { @@ -824,6 +826,13 @@ bool ZipPackageStream::saveChild( if (bParallelDeflate) { + // tdf#93553 limit to a useful amount of threads. Taking number of available + // cores and allow 4-times the amount for having the queue well filled. The + // 2nd pparameter is the time to wait beweeen cleanups in 10th of a second. + // Both values may be added to the configuration settings if needed. + static sal_Int32 nAllowedThreads(std::max(std::thread::hardware_concurrency(), 1U) * 4); + rZipOut.reduceScheduledThreadsToGivenNumberOrLess(nAllowedThreads, 1); + // Start a new thread deflating this zip entry ZipOutputEntry *pZipEntry = new ZipOutputEntry( m_xContext, *pTempEntry, this, bToBeEncrypted); -- cgit