R中的MySQL odbc超时
我正在使用 R 使用 RODBC 包从 MySQL 数据库读取一些数据。然后处理数据并将一些结果发送回数据库。问题是服务器在大约一分钟后由于不活动而关闭连接,这是本地处理数据所需的时间。它是共享服务器,因此主机不会增加超时时间。
我认为有两种可能性可以解决这个问题:
- 在每个数据库事务之前打开一个连接,并在之后立即关闭它
- 每 30 秒左右向服务器发送一些小的“ping”命令,让服务器知道我仍然在那里。
我可以相当容易地实现第一个,但不断打开和关闭连接似乎相当慢。有谁知道第二个有效的命令?或者是一个更好的方法?
I'm using R to read some data from a MySQL database using the RODBC package. The data is then processed and some results are sent back to the database. The problem is that the server closes the connection after about a minute due to inactivity, which is the time needed to process the data locally. It's a shared server, so the host won't bump up the timeout time.
I think there are two possibilities to get around this:
- Open a connection before every database transaction and close it immediately after
- Send some small 'ping' command to the server every 30 seconds or so to let the server know that I'm still there.
I can implement the first fairly easily, but it seems pretty slow to constantly open and close connections. Does anyone know an efficient command for the second? Or is a better way altogether?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个解决方案是我更喜欢的。使用像 R 这样的单线程程序来完成后者确实很困难。如果 R 正忙于运行分析,那么它就无法处理 ping。除非您正在进行数百次读/写,否则打开和关闭连接的方法不应引入大量开销。
The first solution is the one I prefer. It's really hard to do the latter with a single threaded program like R. If R is busy running analysis there's no way for it to handle the ping. Unless you are doing hundreds of reads/writes the method of opening and closing the connection should not introduce an extreme amount of overhead.