我想用Redis的Node.js和Socket.io來部署一個應用到Heroku。我已經設置了Socket.io來使用XHR長輪詢作爲specified by Heroku,並且如果我只有一個動態碼,它會很好地工作,但是當我縮放它以使用多個動態碼時它不起作用。用Node.js在Heroku上使用Socket.io和Redis
最初我是在Socket.io使用MemoryStore的,當我縮放它使用「的Heroku PS:網絡規模= 2」,它開始工作間歇,並在客戶端給這個錯誤:
Uncaught TypeError: Property 'open' of object #<Transport> is not a function
我在Socket.io documentation是「如果你想擴展至多個過程和/或多個服務器,你可以使用我們的RedisStore它使用Redis的的NoSQL數據庫作爲中間人」
所以,我創建了一個發現RedisStore:
var newRedisStore = new RedisStore({
redisPub : pub,
redisSub : sub,
redisClient : client
});
和配置Socket.io使用它:
//set up Web Socket Server
io.configure(function() {
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
io.set('store', newRedisStore);
});
而這一切都完美的作品在當地,並在Heroku的一個網絡賽道。但是,只要我將其擴展到多個進程,它就會間歇性地開始不再工作,儘管現在我不再有錯誤了。所以,我不確定該從哪裏出發。
這些都是我從Heroku的掌握2個處理日誌:
2012-06-16T15:36:12+00:00 app[web.2]: debug: setting poll timeout
2012-06-16T15:36:12+00:00 app[web.2]: debug: clearing poll timeout
2012-06-16T15:36:12+00:00 app[web.2]: debug: xhr-polling writing
7:::1+0 2012-06-16T15:36:12+00:00 app[web.2]: warn: client not
handshaken client should reconnect 2012-06-16T15:36:12+00:00
app[web.2]: debug: set close timeout for client 15718037491002932534
2012-06-16T15:36:12+00:00 app[web.2]: debug: cleared close timeout for
client 15718037491002932534 2012-06-16T15:36:12+00:00 app[web.2]:
info: transport end (error) 2012-06-16T15:36:12+00:00 app[web.2]:
debug: discarding transport
謝謝。我覺得這是朝着正確的方向發展,但我似乎無法得到它的工作。當我使用集羣時,Socket.io在發出時保持錯誤。 – tomgersic
嘗試增加[超時](https://devcenter.heroku.com/articles/request-timeout#longpolling_and_streaming_responses)並讓我知道。你也可以發佈你的代碼,所以我可以分析它,使用pastebin.com或類。 –