Mgo基于应用程序的代码结构处理连接池和TCP超时。

huangapple go评论89阅读模式
英文:

Mgo-based app code structure dealing with connection pool and tcp timeouts

问题

我很好奇如何使用Go语言和Mgo库来构建JSON REST API服务器。我有几十个相关的集合。我在当前的方法中创建了一个文件结构的示例部分,你可以在gist链接中找到。

这个方法运行得很好,但是偶尔会遇到"read tcp 10.168.30.100:37288: i/o timeout"错误导致的停机时间。我猜想我可能没有正确处理mgo连接池。是否有任何示例展示如何基于mgo创建大型应用程序?

英文:

I'm curious how should I structure JSON REST API server in Go language with Mgo library. I have dozens of collections related with each other. I've created the gist with sample part of file structure in my current approach.

It works great, but from time to time I encounter downtime caused by this error: "read tcp 10.168.30.100:37288: i/o timeout". I suppose that I handle mgo connection pool inapropriately. Are there any examples showing how should I create big applications based on mgo?

答案1

得分: 5

这个错误信息意味着与数据库的往返时间超过了你定义的超时时间。只要增加超时时间就可以解决这个问题,前提是你没有任何导致应用程序运行缓慢的真正问题。

一般来说,这个错误并不意味着你有任何规模上的问题,除非你的某些集合中的数据量在增加,某些查询可能变得过慢,需要重新考虑(索引等)。

也没有必要重新启动应用程序。你可以刷新有问题的会话,或者关闭并重新创建会话(如果你正在使用主会话的副本)。mgo的状态和连接池仍然正常。它只是在提醒你这个特定的会话在传输过程中遇到了问题,所以你必须在会话恢复有效之前确认它。

像往常一样,确保使用最新的版本以避免已经修复的问题(如果有的话)。

英文:

This error message implies a roundtrip to the database took longer than the timeout period you defined. Just increasing that timeout should get rid of the problem, assuming you don't have any real issues that are causing the application to behave in a sluggish manner.

In general, this error doesn't imply you have any kind of scale issues, other than the fact maybe you have an increasing amount of data in some collections and certain queries may be getting too slow and need re-thinking (indexes, etc).

There's also no need to restart the application. You can either Refresh the problematic session, or Close and re-create the session in case you're using copies of a master session. The state of mgo and the pool of connections is still fine. It's just warning you that this specific session observed an issue on the wire, and so you have to acknowledge it before the session will be valid again.

As usual, also make sure to be using the latest release to avoid problems that have already been fixed, if any.

huangapple
  • 本文由 发表于 2013年11月8日 20:01:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/19858664.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定