我正在写一个快速写入MongoDB的应用程序。 mongodb和mgo处理太快。我的问题是,有没有办法让我确定mongo无法跟上并开始阻止?但我也不想不必要地阻止。 这里是模拟问题的代码示例:Golang Mgo步调
package main
import (
"labix.org/v2/mgo"
"time"
"fmt"
)
// in database name is a string and age is an int
type Dog struct{
Breed string "breed"
}
type Person struct{
Name string "name"
Pet Dog `bson:",inline"`
Ts time.Time
}
func insert(session *mgo.Session, bob Person){
err := session.DB("db_log").C("people").Insert(&bob)
if err != nil {
panic("Could not insert into database")
}
}
func main() {
session, _ := mgo.Dial("localhost:27017")
bob := Person{Name : "Robert", Pet : Dog{}}
i := 0
for {
time.Sleep(time.Duration(1) * time.Microsecond)
i++
go insert(session, bob)
}
}
我经常得到这样的错误:
panic: Could not insert into database
或
panic: write tcp 127.0.0.1:27017: i/o timeout
@EvanShaw你推荐什么呢? – thwd
如果不知道有关应用程序的问题,很难提出建议,但PostgreSQL通常是一个很好的默认选择。 –
如果写意见很酷,那么我会对@EvanShaw提出相反的意见。我们在生产中使用Mongo并喜欢它。我们得到了很好的表现。不要让仇恨与你混淆。我还没有听到反对蒙戈的争论,这是无法抵抗的。服务器密度部门的David Mytton在一年半之前写道[非常好的对应点](https://blog.serverdensity.com/does-everyone-hate-mongodb/),我推荐阅读。 – Tyson