0

何らかの理由で、この新しいチャットメッセージのチェックにより、予想よりも多くのブラウザ(およびある程度のサーバー)の負荷が発生します。負荷を軽減するために、私がそれをより効率的にすることができる方法を誰かが見ていますか?

// Begin the cycle of refreshing the mini chat after the standard delay.
function startRefreshingMinichat(){
    var secs = 30; // Chat checking frequency.
    setTimeout(function (){
        checkForNewChats();
        startRefreshingMinichat(); // Loop the check for refresh.
    }, secs*1000);
}

// Check for the latest chat and update if it's different.
function checkForNewChats(){
    // Check whether the latest chat doesn't match the latest displayed chat.
    // NOTE THAT THIS CALLBACK DOES NOT TRIGGER IMMEDIATELY.
    $.getJSON('api.php?type=latest_chat_id&jsoncallback=?', function(data){
        var newChats = false;
        // Update global data stores if an update is needed.
        if(updateDataStore(data.latest_chat_id, 'chat_id', 'latestChatId', 'chat_id')){
            newChats = true;
        }
        if(newChats){ // there are new chats to show.
            refreshMinichat(null, 50); // loads new chat content.
        }
        // Since this callback isn't immediate, any feedback has to occur whenever the callback finishes.
 }); // End of getJSON function call.
}
4

2 に答える 2

1

このプッシュエンジンをチェックアウトして、新しいデータをポーリングする必要がないようにすることができます。それをチェックしてください、それは本当にクールです。

于 2010-05-06T13:06:06.067 に答える
1

CometDをチェックしてください。これは、jQueryと統合された単純なチャットシステムである程度の成功を収めて使用したjsロングポーリングシステムです。(前回調べたとき、jQuery固有の実装がいくつかありましたが、私にとって十分に堅牢な実装は見つかりませんでした。)

于 2010-05-06T13:18:29.300 に答える