我继承了一个应用程序(我的公司内部),它使用在Internet Explorer中运行的javascript,它使Ajax调用在WebLogic Server v10中运行的基于Struts的应用程序.
系统中的某些服务器端操作花费的时间超过3分钟.用户始终注意到Ajax调用在3分钟标记处返回503错误.我的用户可以等待超过3分钟,但503错误会中断他们的工作.
此应用程序需要进行性能调整,但我们非常需要一个临时的解决方法来延长返回503错误之前可以发生的时间.
目前的理论是IE XMLHttpRequest对象引发了503错误.一组假想的WebLogic专家倾注了我们的代码和WebLogic日志,并声明服务器端没有发生超时.但我有疑虑.
我的问题是,哪一个软件负责引发503错误:浏览器,Ajax javascript或服务器?这个超时期限可以改变吗?
是否可以使用jQuery的get速记设置ajax timeout参数?如果没有,用速记发送的请求是否会超时?
jQuery.get(
url,
[ data ],
[ callback(data, textStatus, XMLHttpRequest) ],
[ dataType ]
)
Run Code Online (Sandbox Code Playgroud)
谢谢.
我有一个Game框架,其中有一个实现IBotInterface的Bots列表.这些机器人是由用户定制的,唯一的限制是它们必须实现接口.
然后游戏调用机器人中的方法(希望并行),用于各种事件,如yourTurn和roundStart.我希望机器人在被迫退出计算之前只花费有限的时间来处理这些事件.
我正在尝试的一种例子是:(其中NewGame是代表)
Parallel.ForEach(Bots, delegate(IBot bot)
{
NewGame del = bot.NewGame;
IAsyncResult r = del.BeginInvoke(Info, null, null);
WaitHandle h = r.AsyncWaitHandle;
h.WaitOne(RoundLimit);
if (!r.IsCompleted)
{
del.EndInvoke(r);
}
}
);
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我被迫运行可能不会终止的EndInvoke().我想不出一种干净地中止线程的方法.
如果有某种形式的话会很棒
try {
bot.NewGame(Info);
} catch (TimeOutException) {
// Tell bot off.
} finally {
// Compute things.
}
Run Code Online (Sandbox Code Playgroud)
但我不认为有可能制作这样的结构.
这样做的目的是优雅地处理具有偶然无限循环或需要很长时间计算的AI.
解决这个问题的另一种可能方法就是拥有这样的东西(更多的c#和更少的伪代码)
Class ActionThread {
pulbic Thread thread { get; set; }
public Queue<Action> queue { get; set; }
public void Run() {
while (true) {
queue.WaitOne();
Act a = …Run Code Online (Sandbox Code Playgroud) 当打电话给雅虎网络服务(http://boss.yahooapis.com/ysearch)以返回数据集时,是否可以设置超时并在程序结束后退出例程?
jQuery.getJSON("http://boss.yahooapis.com/ysearch/...etc",
function (data) {
//result set here
});
Run Code Online (Sandbox Code Playgroud) 在从大型表上查询数据时,我遇到了脚本超时的问题.
该表有9,521,457行.
我正在尝试预先形成的查询是:
SELECT *
FROM `dialhistory`
WHERE `customerId` IN (22606536, 22707251, 41598836);
Run Code Online (Sandbox Code Playgroud)
此查询在HeidiSQL上运行没有问题,大约需要171秒并返回434行.
但是当我运行我的C#脚本时,它会在161行之后超时.
16:54:55: Row 1
...
16:54:55: Row 161
16:55:32: Error -> Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
Run Code Online (Sandbox Code Playgroud)
这是代码
public MySqlDatabase(string server, string database, string username, string password)
{
ConnectionString = "SERVER=" + server + ";DATABASE=" + database + ";UID=" + username + ";PASSWORD=" + password + ";";
}
public IQueryable<DailHistory> GetHistory(IList<int> customerIds)
{
IList<DailHistory> …Run Code Online (Sandbox Code Playgroud) 如果在PHP中花费太长时间,有没有办法可以中止一段代码?也许是这样的:
//Set the max time to 2 seconds
$time = new TimeOut(2);
$time->startTime();
sleep(3)
$time->endTime();
if ($time->timeExpired()){
echo 'This function took too long to execute and was aborted.';
}
Run Code Online (Sandbox Code Playgroud)
它不一定完全像上面那样,但有没有任何本机PHP函数或类做这样的事情?
编辑:Ben Lee的答案pcnt_fork将是完美的解决方案,除了它不适用于Windows.有没有其他方法可以使用适用于Windows和Linux的PHP实现此目的,但不需要外部库?
编辑2:XzKto的解决方案可在某些情况下,但不是一致,我似乎无法捕获异常,不管我怎么努力.用例是检测单元测试的超时.如果测试超时,我想终止它,然后继续下一个测试.
我需要让MySQL服务器在客户端断开连接后立即回滚事务,因为每个客户端同时工作.问题可以像这些一样重复(使用innodb表类型)
在客户端A上:
START TRANSACTION;
SELECT MAX(ID) FROM tblone FOR UPDATE;
#... then disconnect your connection to the server
Run Code Online (Sandbox Code Playgroud)
在客户B上:
START TRANSACTION;
SELECT MAX(ID) FROM tblone FOR UPDATE;
#... lock wait time out will occur here
Run Code Online (Sandbox Code Playgroud)
我设置了MySQL的服务器选项,innodb_rollback_on_timeout并mysql --skip-reconnect在两个客户端上使用mysql的客户端.我在网络上尝试使用一台服务器和两台客户端.我在SELECT ... FOR UPDATE;线路后物理断开网络(拔掉电缆).我需要让其他客户端能够立即使用tblone事务(锁定它,更新它),并且为了实现这一点,我认为服务器应该在客户端A断开连接之后回滚客户端A的事务.
我正在使用文件描述符和posix/unix read()函数从C++中的串口读取字节.在这个例子中,我从串口读取1个字节(为了清楚起见,省略了波特率设置和类似内容):
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>
int main(void)
{
int fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY);
char buf[1];
int bytesRead = read(fd, buf, 1);
close(fd);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果连接到/ dev/ttyS0的设备未发送任何信息,程序将挂起.如何设置超时?
我试过像这样设置一个时间:
struct termios options;
tcgetattr(fd, &options);
options.c_cc[VMIN] = 0;
options.c_cc[VTIME] = 10;
tcsetattr(fd, TCSANOW, &options);
Run Code Online (Sandbox Code Playgroud)
我认为它应该给1秒超时,但它没有任何区别.我想我误解了VMIN和VTIME.什么是VMIN和VTIME用于?
然后我搜索了网络,发现有人在谈论select()函数.这是解决方案,如果是这样,如何将其应用于上面的程序以使1秒超时?
任何帮助表示赞赏.提前致谢 :-)
当我使用以下方法执行查询时,我得到超时.
所以我的问题是:如何将超时设置为180秒?
我正在使用连接来使用queryresult填充dataSet.
internal static DataSet executeQuery(string queryString)
{
// #connection
DataSet dataSet = new DataSet();
string connectionString = Connection.connectionStringSQL01NavProvider();
OleDbConnection connection = new OleDbConnection(connectionString);
OleDbDataAdapter adapter = new OleDbDataAdapter(queryString, connectionString);
// Open the connection and fill the DataSet.
connection.Open();
try
{
adapter.Fill(dataSet);
DataTable dt = new DataTable();
dt = dataSet.Tables[0];
DataRow dr;
try
{
dr = dt.Rows[0];
}
catch
{
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
System.Windows.Forms.MessageBox.Show("Error executeQuery().! " + ex.Message);
}
return dataSet;
}
Run Code Online (Sandbox Code Playgroud) 我有这个简单的描述实例函数,我试图通过AWS Lambda在nodejs中运行:
var AWS = require('aws-sdk');
AWS.config.region = 'us-east-1';
exports.handler = function(event, context) {
console.log("\n\nLoading handler\n\n");
var ec2 = new AWS.EC2();
ec2.describeInstances(function(err, data) {
console.log("\nIn describe instances:\n");
if (err) {
console.log(err, err.stack);
context.done(null, 'Function Finished from error!'); // an error occurred
}else {
console.log("\n\n" + data + "\n\n");
context.done(null, 'Function Finished with data!'); // successful response
}
});
};
Run Code Online (Sandbox Code Playgroud)
这不会给我带来任何错误,CloudWatch中唯一的输出是:
2016-03-21T17:01:59.085Z xxxxxxx-xx.... Task timed out after 3.00 seconds
Run Code Online (Sandbox Code Playgroud)
任何人都知道可能是什么问题?
timeout ×10
c# ×3
ajax ×2
jquery ×2
mysql ×2
amazon-ec2 ×1
aws-lambda ×1
c ×1
disconnect ×1
getjson ×1
http ×1
javascript ×1
node.js ×1
php ×1
rollback ×1
sql-server ×1
transactions ×1
tty ×1
unix ×1
weblogic ×1