Codeigniter:太多的ajax调用导致web应用程序超时


Codeigniter: too many ajax calls is causing web application timeout

我有一个web应用程序,其中有一个"投票"按钮。用户可以在40秒内点击"投票"按钮。

每次单击都会创建一个异步ajax请求,将数据插入数据库。这对少数用户来说效果很好。当超过300个用户单击投票按钮时,应用程序无法正确响应,导致超时错误。

请让我知道蚂蚁绕过这个问题的建议。

请注意,CPU使用率几乎为50%。

试试这个代码,将其粘贴到脚本中,然后使用ajax_call而不是$.ajax

$(function(){
    window.queue = $.jqmq({
        delay   : -1,
        batch   : 2,
        callback:function(options){
            $.each(options,function(i,option){
                $.ajax({
                    url         : option.url,
                    type        : option.type,
                    data        : option.data,
                    dataType    : option.dataType,
                    beforeSend  : function(){
                        option.beforeSend();
                    },
                    success     : function(result){
                        option.success(result);
                    },
                    error       : function(xhr,status, error){
                        option.error(xhr,status, error);
                    },
                    complete    : function(){
                        queue.next(false);
                    }
                });
            });
        },
        complete:function() {
            console.log("done");
        }
    });
});
var ajax_call = function(data){
    var _defaults = {
        url         : "",
        data        : {},
        type        : "post",
        dataType    : "",
        beforeSend  : _default_beforeSend,
        success     : _default_success,
        error       : _default_error
    }
    var options = $.extend(_defaults,data);
    if(options.url != ''){
        queue.add(options);
    }
    else{
        alert("Url is not defined in ajax_call");
    }
}
var _default_success = function(){
    alert("Please define 'success' funciton in ajax_call for remove this alert!");
}
var _default_beforeSend = function(){
    alert("Please define 'beforeSend' funciton in ajax_call for remove this alert!");
}
var _default_error = function(){
    alert("Please define 'error' funciton in ajax_call for remove this alert!");
}