我有一个在本地网络上使用Microsoft SQL 2008 Server的网站。有时,SQL Server计算机会重新启动,因此网站无法连接到数据库。如果机器运行起来,它会迅速作出反应。如果出现故障,则无需等待15秒。3秒还可以。
当数据库不可访问时,我想在网站上表示歉意,并希望尽快做到。但是Connection Timeout=3在连接字符串中设置似乎无效。该页面花了22秒钟等待,然后再SqlException继续SqlConnection.Open();。
它出什么问题了?难道它是一个覆盖了超时的隐藏配置?
目前,我的连接字符串是
Data Source=...;
Initial Catalog=...;
Integrated Security=True;
Connection Timeout=3
Run Code Online (Sandbox Code Playgroud)
如果我将其设置为...;ConnectionTimeout=3(无空格),
System.ArgumentException: Keyword not supported: 'connectiontimeout'.
Run Code Online (Sandbox Code Playgroud)
被抛出(奇怪的是,MSDN文档指示我们可以同时使用两个字符串)。
来自 Netty API 文档
connectTimeoutMillis = "以毫秒为单位的连接超时。如果禁用,则为 0。"
和
ReadTimeoutHandler = 在一段时间内没有读取数据时引发 ReadTimeoutException。
从客户的角度来看,我对上述内容的解释是否正确?
客户端将尝试连接到主机最多“connectTimeoutMillis”。如果建立了连接,并且未将 ReadTimeoutHandler 添加到管道中,则通道可以无限期地等待响应。如果将 ReadTimeoutHandler 添加到管道中,则一旦 timeoutSeconds 过去,将引发 ReadTimeoutException。
一般来说,我只想尝试连接到主机最多 'x' 秒,但如果通过网络发送请求,我想等待最多 'y' 秒的响应。如果它影响/影响答案,则客户端是 Netty,但服务器不是。
跟进:ReadTimeoutHandler 上的 timeoutSeconds 是读取连续字节之间的超时,还是整个请求/响应的超时?示例:如果 timeoutSeconds 是 60,并且每 59 秒读取一个字节(总共 1024 个字节),那么整个响应会在 60416 秒内成功读取,还是会因为总经过时间超过 60 秒而失败?
我们有一个带有C#客户端,C#WCF Web服务层和SQL Server数据库的3层应用程序.Web服务使用ADO.NET连接到数据库.我们所有的C#代码都使用.NET Framework 2.0.
最近,客户对我们的应用程序进行了压力测试.在测试期间,Web服务器生成了许多错误,如下所示:
无法连接到数据库以获取连接字符串'...'.超时已过期.操作完成之前经过的超时时间或服务器没有响应.
我知道有些方法可以在连接池已满时捕获连接错误并尝试获取连接池外部的连接.我们还发现了一些需要调整的查询,但它们并不能解释Web服务器连接超时.
我们试图弄清楚为什么Web服务器超时连接到数据库.我已经设置了Web服务器以启用所有ADO.NET性能计数器.但是,我没有看到任何与连接或连接超时等所需时间相关的内容.理想情况下,我们可以perfmon在其他ADO.NET计数器旁边绘制连接时间图.
有没有办法监控ADO.NET在获取连接时的性能?
我想我们可以通过尝试打开连接来创建我们自己的"平均连接开放时间"性能计数器,但我宁愿使用已经存在的东西.
我有一个使用MySQL的Tomcat应用程序和用于ORM的Hibernate.我们的应用程序的性质要求我们必须从NoSQL存储中为每个请求提取和聚合大量分析数据,因此我们将每个请求的提取和聚合分成几个任务,并将这些数据委托给线程池执行服务.
当每个线程执行任务时,它需要查询/更新MySQL有关某些事情,所以它借用了C3P0(我们用于连接池)的Hibernate会话.
基本配置:
<property name="current_session_context_class">thread</property>
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.connection.shutdown">true</property>
<property name="hibernate.use_sql_comments">false</property>
<!-- C3p0 Performance Improvements -->
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">300</property>
<property name="hibernate.c3p0.maxConnectionAge">3600</property>
<property name="hibernate.c3p0.timeout">120</property>
<property name="hibernate.c3p0.max_size">300</property>
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.preferredTestQuery">select 1;</property>
Run Code Online (Sandbox Code Playgroud)
问题是Hibernate请求在8小时后导致MySQL/JDBC连接超时错误(我们配置的MySQL的wait_timeout参数值是默认值,即8小时).我通过将wait_timeout设置为11分钟来复制这个,但是对于8小时的wait_timeout,结果也是相同的:
2013-01-27 20:08:00,088 ERROR [Thread-0] (JDBCExceptionReporter.java:234) - Communications link failure
The last packet successfully received from the server was 665,943 milliseconds ago. The last packet sent successfully to the server was 6 milliseconds ago.
org.hibernate.exception.JDBCConnectionException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2536)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276) …Run Code Online (Sandbox Code Playgroud) 我看到 JDBC MySQL 驱动程序在 10 秒后始终无法连接到已停止的 MySQL,但我想更改该超时。
我尝试将 ?connectTimeout=2000&socketTimeout=2000 添加到连接 URI,但这并没有什么区别。
有没有办法自定义驱动程序在连接到 MySQL 时返回超时所需的时间?
我无法使用以下代码将Apache HttpClient(4.3)发布请求置于超时状态:
RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(4000).setConnectTimeout(4000)
.setSocketTimeout(4000).build();
CloseableHttpClient client = HttpClients.custom().setSslcontext(sslContext)
.setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)
.setDefaultRequestConfig(requestConfig).build();
HttpPost post = new HttpPost("https://localhost:" + connection.getLocalPort() + "/API/webservice.asmx");
StringEntity stringE = new StringEntity(REQUEST);
post.setEntity(stringE);
CloseableHttpResponse response = client.execute(post);
Run Code Online (Sandbox Code Playgroud)
我通过专有API获得连接和端口.当一切顺利时,这有效(但由于我认为连接不良)代码永远挂在client.execute(post).在实现超时或其他方法使我的调用超时时,我在做错了什么,所以我不会无限期地陷入困境.
我正在开发一个连接到MySQL服务器的node.js应用程序。但是,以下内容可能不是特定于node.js的。
当前,我的代码在应用程序启动时初始化一个MySQL连接,然后在每次需要查询时都使用该连接。
我的方法面临的问题是,连接会在一段时间后趋于关闭。我不确定该时间段有多长,但似乎至少需要几个小时。我也不确定是否是由于不活动引起的。
无论如何,我想知道哪种方法可以更好地长期管理MySQL连接。在可能的方法中,我考虑了:
只需在每个查询之前检查一下连接是否仍然有效。如果不是,请在执行查询之前重新连接。
池化MySQL连接。对于一个相当小的应用程序,这会过分杀伤力吗?
定期(每个小时左右)执行查询,以防由于不活动而发生查询。但是,这不能解决由于非活动导致的可能情况。
查询之前/之后连接和断开连接。不好的主意,因为涉及的开销。
如您所想,我倾向于使用前两个选项之一。哪个选项最可靠,最有效?
我在笔记本电脑的浏览器上使用ipython笔记本,它连接到我办公室的远程ipython笔记本电脑服务器.问题是如果网络停机的时间很短,连接将被关闭.然后重新连接到服务器,我"只是"需要刷新浏览器,但如果笔记本电脑的大小很大,这实际上非常烦人.
问题是我可以增加连接超时(就像ssh-server的这些选项一样),这样即使网络短时间停机,连接也不会丢失.
我去了文档,发现了这些#空闲连接将自动关闭的时间。# 设置为infinite完全禁用空闲连接超时。空闲超时 = 10 秒
# Defines the default time period within which the application has to
# produce an HttpResponse for any given HttpRequest it received.
# The timeout begins to run when the *end* of the request has been
# received, so even potentially long uploads can have a short timeout.
# Set to `infinite` to completely disable request timeout checking.
#
# If this setting is not `infinite` the HTTP server layer attaches a
# …Run Code Online (Sandbox Code Playgroud) 我在 VS code 中进行了 python 调试。以下是launch.json文件:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"python": "${command:python.interpreterPath}",
"program": "${file}",
"cwd": "${workspaceFolder}",
"env": {},
"envFile": "${workspaceFolder}/.env",
"debugOptions":[
"RedirectOutput"
],
"console": "integratedTerminal"
}
]
}
Run Code Online (Sandbox Code Playgroud)
以下是settings.json文件:
{
"python.pythonPath": "c:\\Users\\susan\\Documents\\PythonScripts\\venv\\Scripts\\python.exe",
// to fix 'Timeout waiting for debugger connections'
"python.terminal.activateEnvironment" : false
}
Run Code Online (Sandbox Code Playgroud)
当我在 VS …