Node.js/线程:修订间差异
来自康健生活
| (未显示同一用户的2个中间版本) | |||
| 第180行: | 第180行: | ||
* 工作进程负载均衡 | * 工作进程负载均衡 | ||
* 工作进程状态共享 | * 工作进程状态共享 | ||
== 多线程 == | |||
* [https://github.com/xk/node-threads-a-gogo threads_a_gogo] | |||
==== threads_a_gogo ==== | |||
版本需求: >=0.5.1 <=6.9.2。 | |||
部分 api。 | |||
<syntaxhighlight lang="javascript"> | |||
const threadsAGogo = require('threads_a_gogo'); | |||
const threadObject = threadsAGogo.create(/* no arguments */); | |||
const threadPool = threadsAGogo.createPool(/* set thread pool number */); | |||
threadObject.load("test.js").eval("testFun()").emit("go").on("event", cb); | |||
</syntaxhighlight> | |||
=== 多线程下载原理 === | |||
多线程下载首先要获取整个文件的大小,然后开多个线程来下载这个文件的不同部分。 | |||
=== 断点下载 === | |||
技术点: | |||
* Range | |||
: <syntaxhighlight lang="javascript"> | |||
response.setHeader('Accept-Ranges', 'bytes');</syntaxhighlight> | |||
* 链式流(管道流) | |||
版本支持: | |||
* HTTP/1.1 | |||
=== 参考 === | |||
* [https://zhuanlan.zhihu.com/p/361133130 Node.js断点下载和多线程下载原理] | |||