근로자에게 필수 항목을 사용할 수 있습니다.
requirejs.config({
//By default load any module IDs from js/lib
baseUrl: 'js/lib',
//except, if the module ID starts with "app",
//load it from the js/app directory. paths
//config is relative to the baseUrl, and
//never includes a ".js" extension since
//the paths config could be for a directory.
paths: {
app: '../app'
}
});
// Start the main app logic.
requirejs(['jquery', 'canvas', 'app/sub'],
function ($, canvas, sub) {
//jQuery, canvas and the app/sub module are all
//loaded and can be used here now.
});
함께 퍼팅
작업자 : 문서를 필요에 따라 당신이 모듈에 구성 개체를 전달할 수있는 것처럼 당신의 노동자 스크립트에서는
self.importScripts('../path/require.js');
를 호출해야합니다. js
self.importScripts('../path/require.js');
requirejs.config({
//By default load any module IDs from path/lib
baseUrl: 'path/lib',
//except, if the module ID starts with "app",
//load it from the js/app directory. paths
//config is relative to the baseUrl, and
//never includes a ".js" extension since
//the paths config could be for a directory.
paths: {
app: '../app'
}
});
// Start the main app logic.
requirejs(['jquery', 'canvas', 'app/sub'],
function ($, canvas, sub) {
//jQuery, canvas and the app/sub module are all
//loaded and can be used here now.
// now you can post a message back to your callee script to let it know require has loaded
self.postMessage("initialized");
});
self.onmessage = function(message) {
// do cpu intensive work here, this example is not cpu intensive...
if(message.data === 'to process') {
self.postMessage("completed!");
}
}
노드 노동자 전화
var worker = new Worker('Worker.js');
worker.onmessage = function(event) {
var msg = event.data;
if(msg === 'initialized') {
worker.postMessage({data: 'to process'});
}
}
당신이 좀 더 사용 사례를 설명 할 수 있습니까? 여러 개의 URL을 처리 할 때 병렬 처리를 시도하거나 노드 내의 성능을 어떻게 든 향상 시키려고합니까? Node의 라이브러리에 의존 할 때 하위 프로세스를 어떻게 사용 했습니까? 표준 노드 클러스터링이 목록에서 옵션이 아닌 이유는 무엇입니까 (실제로 자식 프로세스 자체에 의존한다는 것을 명심하십시오)? – SylonZero
노드를 서버로 사용하고 있습니다. 함수를 실행하는 데 200ms가 걸리면 아무런 사용자도 200ms 이내에 서버 응답을 얻을 수 없습니다. 서버를 차단하지 않도록 비동기로 만들고 싶습니다. 'child_process'를 사용하여 다른 Node 프로세스를 시작할 수 있습니다. 전에는 노드 클러스터링을 사용 해본 적이 없지만, 각 코어에 대해 서버를 생성한다는 것을 이해했습니다. 'node-unfluff '가 모든 코어에서 실행 중이면 모든 서버가 차단됩니다. –
자, 질문이 명확 해지기 시작했습니다. 그러나 함수의 인스턴스 (node-unfluff 사용)가 동기 적이더라도 Node에 대한 다른 요청의 다른 인스턴스가 실행되는 것을 막지는 않습니다. 따라서 한 명의 사용자가 200ms를 기다려야 할 수도 있지만 일반적으로 다른 * 사용자의 요청을 시작할 수는 없습니다.테스트를 통해이 unluff 모듈을 사용하면 실제로 동시 요청이 차단된다는 것을 알았습니까? – SylonZero