mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-12-03 19:06:16 +02:00
make multi threaded compression configurable and use single threaded
by default.
This commit is contained in:
parent
163e39547a
commit
55ecdfe2a8
4 changed files with 31 additions and 20 deletions
|
@ -149,7 +149,7 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, const ref<std::str
|
||||||
/* Compress the NAR. */
|
/* Compress the NAR. */
|
||||||
narInfo->compression = compression;
|
narInfo->compression = compression;
|
||||||
auto now1 = std::chrono::steady_clock::now();
|
auto now1 = std::chrono::steady_clock::now();
|
||||||
auto narCompressed = compress(compression, *nar);
|
auto narCompressed = compress(compression, *nar, settings.parallelCompression);
|
||||||
auto now2 = std::chrono::steady_clock::now();
|
auto now2 = std::chrono::steady_clock::now();
|
||||||
narInfo->fileHash = hashString(htSHA256, *narCompressed);
|
narInfo->fileHash = hashString(htSHA256, *narCompressed);
|
||||||
narInfo->fileSize = narCompressed->size();
|
narInfo->fileSize = narCompressed->size();
|
||||||
|
|
|
@ -174,6 +174,9 @@ public:
|
||||||
"Whether to compress logs.",
|
"Whether to compress logs.",
|
||||||
{"build-compress-log"}};
|
{"build-compress-log"}};
|
||||||
|
|
||||||
|
Setting<bool> parallelCompression{this, false, "parallel-compression",
|
||||||
|
"Whether to enable parallel compression, only supported with xz currently"};
|
||||||
|
|
||||||
Setting<unsigned long> maxLogSize{this, 0, "max-build-log-size",
|
Setting<unsigned long> maxLogSize{this, 0, "max-build-log-size",
|
||||||
"Maximum number of bytes a builder can write to stdout/stderr "
|
"Maximum number of bytes a builder can write to stdout/stderr "
|
||||||
"before being killed (0 means no limit).",
|
"before being killed (0 means no limit).",
|
||||||
|
|
|
@ -151,10 +151,10 @@ static ref<std::string> decompressBrotli(const std::string & in)
|
||||||
#endif // HAVE_BROTLI
|
#endif // HAVE_BROTLI
|
||||||
}
|
}
|
||||||
|
|
||||||
ref<std::string> compress(const std::string & method, const std::string & in)
|
ref<std::string> compress(const std::string & method, const std::string & in, const bool parallel)
|
||||||
{
|
{
|
||||||
StringSink ssink;
|
StringSink ssink;
|
||||||
auto sink = makeCompressionSink(method, ssink);
|
auto sink = makeCompressionSink(method, ssink, parallel);
|
||||||
(*sink)(in);
|
(*sink)(in);
|
||||||
sink->finish();
|
sink->finish();
|
||||||
return ssink.s;
|
return ssink.s;
|
||||||
|
@ -189,20 +189,28 @@ struct XzSink : CompressionSink
|
||||||
lzma_stream strm = LZMA_STREAM_INIT;
|
lzma_stream strm = LZMA_STREAM_INIT;
|
||||||
bool finished = false;
|
bool finished = false;
|
||||||
|
|
||||||
XzSink(Sink & nextSink) : nextSink(nextSink)
|
XzSink(Sink & nextSink, const bool parallel) : nextSink(nextSink)
|
||||||
{
|
{
|
||||||
lzma_mt mt_options = {};
|
lzma_ret ret;
|
||||||
mt_options.flags = 0;
|
if (parallel) {
|
||||||
mt_options.timeout = 300; // Using the same setting as the xz cmd line
|
lzma_mt mt_options = {};
|
||||||
mt_options.check = LZMA_CHECK_CRC64;
|
mt_options.flags = 0;
|
||||||
mt_options.threads = lzma_cputhreads();
|
mt_options.timeout = 300; // Using the same setting as the xz cmd line
|
||||||
mt_options.block_size = 0;
|
mt_options.preset = LZMA_PRESET_DEFAULT;
|
||||||
if (mt_options.threads == 0)
|
mt_options.filters = NULL;
|
||||||
mt_options.threads = 1;
|
mt_options.check = LZMA_CHECK_CRC64;
|
||||||
// FIXME: maybe use lzma_stream_encoder_mt_memusage() to control the
|
mt_options.threads = lzma_cputhreads();
|
||||||
// number of threads.
|
mt_options.block_size = 0;
|
||||||
lzma_ret ret = lzma_stream_encoder_mt(
|
if (mt_options.threads == 0)
|
||||||
&strm, &mt_options);
|
mt_options.threads = 1;
|
||||||
|
// FIXME: maybe use lzma_stream_encoder_mt_memusage() to control the
|
||||||
|
// number of threads.
|
||||||
|
ret = lzma_stream_encoder_mt(
|
||||||
|
&strm, &mt_options);
|
||||||
|
} else
|
||||||
|
ret = lzma_easy_encoder(
|
||||||
|
&strm, 6, LZMA_CHECK_CRC64);
|
||||||
|
|
||||||
if (ret != LZMA_OK)
|
if (ret != LZMA_OK)
|
||||||
throw CompressionError("unable to initialise lzma encoder");
|
throw CompressionError("unable to initialise lzma encoder");
|
||||||
// FIXME: apply the x86 BCJ filter?
|
// FIXME: apply the x86 BCJ filter?
|
||||||
|
@ -459,12 +467,12 @@ struct BrotliSink : CompressionSink
|
||||||
};
|
};
|
||||||
#endif // HAVE_BROTLI
|
#endif // HAVE_BROTLI
|
||||||
|
|
||||||
ref<CompressionSink> makeCompressionSink(const std::string & method, Sink & nextSink)
|
ref<CompressionSink> makeCompressionSink(const std::string & method, Sink & nextSink, const bool parallel)
|
||||||
{
|
{
|
||||||
if (method == "none")
|
if (method == "none")
|
||||||
return make_ref<NoneSink>(nextSink);
|
return make_ref<NoneSink>(nextSink);
|
||||||
else if (method == "xz")
|
else if (method == "xz")
|
||||||
return make_ref<XzSink>(nextSink);
|
return make_ref<XzSink>(nextSink, parallel);
|
||||||
else if (method == "bzip2")
|
else if (method == "bzip2")
|
||||||
return make_ref<BzipSink>(nextSink);
|
return make_ref<BzipSink>(nextSink);
|
||||||
else if (method == "br")
|
else if (method == "br")
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
ref<std::string> compress(const std::string & method, const std::string & in);
|
ref<std::string> compress(const std::string & method, const std::string & in, const bool parallel = false);
|
||||||
|
|
||||||
ref<std::string> decompress(const std::string & method, const std::string & in);
|
ref<std::string> decompress(const std::string & method, const std::string & in);
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ struct CompressionSink : BufferedSink
|
||||||
virtual void finish() = 0;
|
virtual void finish() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
ref<CompressionSink> makeCompressionSink(const std::string & method, Sink & nextSink);
|
ref<CompressionSink> makeCompressionSink(const std::string & method, Sink & nextSink, const bool parallel = false);
|
||||||
|
|
||||||
MakeError(UnknownCompressionMethod, Error);
|
MakeError(UnknownCompressionMethod, Error);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue