わかりました、これを説明するのは簡単ではありませんが、最善を尽くします..
ファイル共有ソリューションを提供しています (小さな画像から大きな 3D 図面/ビデオ (++5-10GB) まで) を奇妙なネットワーク設定 (IT セキュリティ要求) で実行しています。
NODE.js サーバーを含む内部ゾーン (LAN) があります。
- バックエンド (Windows Server 2008 2x2.60Ghz 16GB RAM および最大 122 MB/秒の読み取りのディスク転送速度)。0.8.22 (一部の MSNodeSQL のものは新しい Node バージョンを使用できない.. TDS に変換中
次に、プロキシと Web サーバーが存在する外部ゾーン ( DMZ ) を作成します。
- プロキシ (Ubuntu 12.10 1x2.60Ghz 32GB RAM レストは上記と同じ) ノード 0.8.22。Proxy は LAN にアクセスできる唯一のサーバーですが、開いているポートは 1 つだけであり、バックエンドによって初期化する必要があります。
- Web (Windows Server 2008 8x2.60Ghz 16GB RAM およびその他は上記と同じ) ノード 0.10.12
そのため、Web サーバーに接続されたクライアントにファイルを転送する必要があります。私が現在使用しているライブラリは BinaryJS ですが、転送速度が約 12MB/秒と非常に遅く、新しいクライアントが接続されると速度が低下します (通常は約 4 ~ 6MB/秒)。
リクエスト フロー: - クライアント (ブラウザ) -> https 経由の Web サーバー
- Web サーバー -> BinaryJS 経由のプロキシ
- プロキシ -> BinaryJS CreateStream 経由のバックエンド。
- バックエンド -> Web サーバー ソケットにパイプされたストリーム オブジェクトを使用したプロキシ。
- パイプ経由の Web サーバーへのプロキシ (元の要求)
- Web-Server -> Client (Browser) binaryStream.pipe(res) res は ExpressJS の応答です。
テストの結果、通過する各サーバー (バックエンド、プロキシ、Web) の転送速度が 50% 低下しているように見えますが、その理由はわかりません. ギガビット接続クライアントの最大速度を得るのに十分な帯域幅とディスク速度があります。 . また、メモリとCPUはそれほどハードに機能していません。
コード: バックエンド (BASIC) - DB クエリのファイルパスなどは削除されます:
client = BinaryClient('wss://'+config.proxy+':'+config.port+'/binary');
client.on('stream', function(msgStream, msgMeta){
console.log("Got stream with meta: ", msgMeta);
var stream = require('fs').createReadStream(msgMeta.filepath);
stream.pipe(msgStream);
msgStream.on('error', function(e){
console.log("Bin stream failed: ", e);
});
msgStream.on('close', function(){
console.log("Stream closed")
});
stream.on('end', function(){
console.log("Ending file stream of file: ", msgMeta.meta.itemID);
msgStream.end();
});
}
})
プロキシー:
var binServer = BinaryServer({port:8001});
binServer.on('connection', function(client){
client.on('stream', function(stream, meta){
if(meta.register == true){
if(meta.who == "master"){
config.masterBinary = client;
}
} else {
// Its a stream request.
if(meta.what == "GET"){
config.masterBinary.createStream(meta).pipe(stream).on('close', function(){
console.log("CLOSED");
}).on('end', function(){
console.log("ENDED");
});
}
}
})
});
ウェブサーバー:
client = binaryClient('wss://'+config.proxy+':'+config.port+'/binary');
client.on('open', function(){
ready = true;
})
client.on('close', function(){
ready = false;
})
exports.get = function(file, res, cb){
// This get called from the Express request.. Client will wait for the stream to start
console.log("Sending request to backend: ", file);
if(file.itemID || file.requestID){
client.createStream({filepath:"C:/SomePathToAFile", register:false, what:"GET"}).pipe(res);
} else {
cb("Parameter not present", false);
}
}
私たちがやろうとしていることによりよく適合するように、独自のTCPサーバーとクライアントを作成しようとする必要があるかどうか疑問に思っていました..残念ながら、私はノードにまったく慣れておらず、EventEmitterをTCPに実装する方法を理解していません。識別のためにメタ付きのデータを送信できます。
より良い方法はありますか、それとも BinaryJS サーバーを完全に誤解していますか?
読んでくれてありがとう!