これは、質問が問題を絞り込むのに十分な詳細情報を提供していないため、回答よりも多くの、またはテストヘルパーです。
Pleziを使用して簡単なテストアプリケーションを作成しました。私はプレッツィの作家であるため、あなたのスタックを学ぶよりも私にとっては簡単でした。
私のコンピュータでは、79Mバイト〜3Mバイトのファイルで完全に動作します。
Herokuのに〜3Mbの往復は3秒私のシステムを取って、TCP/IPのウォームアップが完了した後にダウン〜2.5秒に行きました...
...しかし、私のインターネットの速度は、おそらく(テストを行ういます私のレセプションは現時点では低いので、遅くなる可能性があります)。
問題を再現できるかどうかは不明ですが、この回答のコードを使用してサーバーをテストできます。
ラウンドトリップに10秒以上かかる場合は、EC2スタックかもしれません。私は〜500Kbのために10秒が合理的とは思わない。
一方、往復時間が短い場合は、アプリケーションまたはRubyスタックをテストした方法かもしれません。その場合は解決策がplezi(またはiodine native websocket design)に切り替えることが考えられます。
あなたは(あなたもplezi
宝石、おそらくGemfile.lock
と宝石のファイルが必要になります覚えておいてください)config.ru
に次のコードを貼り付けることができます:
# The roundtrip html client
ROUNDTRIP_CLIENT = <<CLIENT_EFO
<html>
<head>
<script src = '/client.js'></script>
</head>
<body>
<input type='file' id='test_f' lable='file to upload'></input>
<button id='test_b'>run test</button>
<div id='output'></div>
<script>
var client;
window.onload = function (e) {
client = new PleziClient();
client.autoreconnect = true;
client.roundtrip = (e) => {
var d = new Date();
e.completed_at = d.getTime();
console.log(e);
document.getElementById('output').innerHTML += "<p>Test for " +
"<a href='" + e.data + "' target='_blank'>" + Math.round(e.data.length/1024)+ "Kb encoded file</a>" +
" completed in " + (e.completed_at - e.time) + "ms</p>";
}
client.onopen = (e) => console.log("Websocket client open", e);
}
function run_test(e) {
console.log("File submitted.");
reader = new FileReader();
reader.onloadend = function(e)
{
console.log("File loaded, " + e.target.result.length + "bytes... starting test.")
var d = new Date();
client.emit({event: "roundtrip", data: e.target.result, time: d.getTime() });
}
reader.readAsDataURL(document.getElementById('test_f').files[0]);
return false;
}
document.getElementById('test_b').onclick = run_test;
</script>
</body>
</html>
CLIENT_EFO
# require plezi
require 'plezi'
# For security, Iodine limists websocket messages.
# We update the default limit from ~250Kb to ~4Mb.
# This replaces the commandline option: iodine -v -maxms 4194304
Iodine::Rack.max_msg_size = 4194304
# the roundtrip controller... quite simple.
class RoundTrip
# return the roundtrip client.
def index
ROUNDTRIP_CLIENT
end
# echo back the websocket message - we're just testing the round trip.
def on_message data
write data
end
end
# Set the plezi root route to the RoundTrip controller
Plezi.route '/', RoundTrip
# Set the client javascript route - I'm using it as a heler.
Plezi.route '/client.js', :client
# Set Rack to run the Plezi application
run Plezi.app
端末からコードを実行するには、iodine
を使用コマンド(それはPleziが必要ですiodine
サーバーを起動します。
EDIT
(コメント内の)git-repoへのリンクから、私はJSONがサーバーによって解析されてから再発行されることに気付きました。
これをエミュレートするために、サンプルコードを更新しました。
これは、JSONの解析と再フォーマットがメモリの割り当てとCPU時間を必要とするデータのコピーを作成するので、レポのコードが行うように見えるはずです。 。
コードの唯一の変更はRoundTrip
コントローラクラスにありますが、コピー+貼り付けの利便性のためにすべてを貼り付けています。
置き、あなたのapp.rb
ファイルに次のコードは、(plezi
宝石をインストールするinstall.sh
を編集することを忘れないでください):
# The roundtrip html client
ROUNDTRIP_CLIENT = <<CLIENT_EFO
<html>
<head>
<script src = '/client.js'></script>
</head>
<body>
<input type='file' id='test_f' lable='file to upload'></input>
<button id='test_b'>run test</button>
<div id='output'></div>
<script>
var client;
window.onload = function (e) {
client = new PleziClient();
client.autoreconnect = true;
client.roundtrip = (e) => {
var d = new Date();
e.completed_at = d.getTime();
console.log(e);
document.getElementById('output').innerHTML += "<p>Test for " +
"<a href='" + e.data + "' target='_blank'>" + Math.round(e.data.length/1024)+ "Kb encoded file</a>" +
" completed in " + (e.completed_at - e.time) + "ms</p>";
}
client.onopen = (e) => console.log("Websocket client open", e);
}
function run_test(e) {
console.log("File submitted.");
reader = new FileReader();
reader.onloadend = function(e)
{
console.log("File loaded, " + e.target.result.length + "bytes... starting test.")
var d = new Date();
client.emit({event: "roundtrip", data: e.target.result, time: d.getTime() });
}
reader.readAsDataURL(document.getElementById('test_f').files[0]);
return false;
}
document.getElementById('test_b').onclick = run_test;
</script>
</body>
</html>
CLIENT_EFO
# require plezi
require 'plezi'
# For security, Iodine limists websocket messages.
# We update the default limit from ~250Kb to ~4Mb.
# This replaces the commandline option: iodine -v -maxms 4194304
Iodine::Rack.max_msg_size = 4194304
# the roundtirp controller... quite simple.
class RoundTrip
@auto_dispatch = true
# return the roundtrip client.
def index
ROUNDTRIP_CLIENT
end
# Using Auto-Dispatch, the JSON is parsed and this event is invoked.
def roundtrip msg
# Hash results are automatically converted into JSON and emitted
msg
end
end
# Set the plezi root route to the RoundTrip controller
Plezi.route '/', RoundTrip
# Set the client javascript route - I'm using it as a heler.
Plezi.route '/client.js', :client
# Plezi will start automatically when the script exits
は、あなたのレポでの場合と同様に同じruby app.rb
コマンドを使用し、端末からのコードを実行するには既存のアプリ。
古い単に提供するコードと「エコー」レスポンス、新しいコード(ほぼ同じに見えます)、さらにいくつかのステップがありますが:
自動ディスパッチを使用して
、Pleziフレームワークが自動的に解析し、 JSONを呼び出し、コントローラーのメソッド(roundtrip
)のイベント(「ラウンドトリップ」)をルーティングします。
このメソッドは、解析されたデータでHashを受け取り、そのハッシュをPleziに返します。
フレームワークでは、このリポジトリの動作と同様である...、ハッシュを収集JSONオブジェクトをフォーマットし、その結果をバック放出する(非文字列やハッシュ結果は無視される)...
。
どのサーバーを使用しているのかわかりません...開発サーバーとEC2インスタンスの違いは何ですか? ...ルーティングスタック(アプリサーバーの前)は何ですか? ...また、私はネイティブのC Websocketサーバー(例えば、「iodine」宝石)でRubyを使用しても、アプリケーションロジックや処理量に関連した減速を経験するでしょうルーティング、同時負荷などが必要です。 – Myst
私の開発サーバーはローカルです。したがって、ネットワークの待ち時間が存在しないため、速度は驚くべきことではありません。 私のアプリケーションのロジックが分かれば、このような分離されたケースは単純に次のようになります。 クライアント - > 400kbを64base符号化したimgをサーバーに送信 - >シン・サーバーがイメージを受信 - >サーバーは、 – Mark