Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

javascript - Node.js中的zip多线程(Multi-threading for zip in nodejs)

Can zip and unzip operation be made-multithreaded in nodejs ?

(可以在nodejs中对zip和unzip操作进行多线程处理吗?)

There are a bunch of modules like yauzl, but neither uses multiple threads, and you can't start multiple threads yourself with node-cluster or something like that, because each zip file must be handled in a single thread

(有很多模块,例如yauzl,但是都不使用多个线程,并且您不能使用node-cluster或类似的东西自己启动多个线程,因为每个zip文件必须在单个线程中处理)

  ask by Alex translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

According to Zlib documentation

(根据Zlib文档)

Threadpool Usage: All zlib APIs, except those that are explicitly synchronous, use libuv's threadpool.

(线程池用法:除明确同步的zlib API外,所有zlib API均使用libuv的线程池。)

This can lead to surprising effects in some applications, such as subpar performance (which can be mitigated by adjusting the pool size) and/or unrecoverable and catastrophic memory fragmentation.

(这可能会在某些应用程序中产生令人惊讶的效果,例如性能不佳(可以通过调整池大小来降低性能)和/或无法恢复的灾难性内存碎片。)

https://nodejs.org/api/zlib.html#zlib_threadpool_usage

(https://nodejs.org/api/zlib.html#zlib_threadpool_usage)

According to libuv's threadpool you can change the environment variable UV_THREADPOOL_SIZE to change the maximum size

(根据libuv的线程池,您可以更改环境变量UV_THREADPOOL_SIZE来更改最大大小)

If you instead wish to be compressing many small files at the same time you can use Worker Threads https://nodejs.org/api/worker_threads.html

(如果您希望同时压缩许多小文件,则可以使用工作线程https://nodejs.org/api/worker_threads.html)

On reading your question again it seems like you want multiple files.

(在再次阅读您的问题时,您似乎想要多个文件。)

Use Worker Threads, these will not block your main thread and you can get the output back from them via promises.

(使用辅助线程,它们不会阻塞您的主线程,您可以通过promise从它们返回输出。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...