草庐IT

world-high-performance-mongo-db-o

全部标签

http - 为什么我的 Hello World go 服务器被 ApacheBench 压垮了?

packagemainimport("io""net/http")funchello(whttp.ResponseWriter,r*http.Request){io.WriteString(w,"Helloworld!\n")}funcmain(){http.HandleFunc("/",hello)http.ListenAndServe(":8000",nil)}我有几个非常基本的HTTP服务器,它们都出现了这个问题。$ab-c1000-n10000http://127.0.0.1:8000/ThisisApacheBench,Version2.3Copyright1996AdamT

http - 为什么我的 Hello World go 服务器被 ApacheBench 压垮了?

packagemainimport("io""net/http")funchello(whttp.ResponseWriter,r*http.Request){io.WriteString(w,"Helloworld!\n")}funcmain(){http.HandleFunc("/",hello)http.ListenAndServe(":8000",nil)}我有几个非常基本的HTTP服务器,它们都出现了这个问题。$ab-c1000-n10000http://127.0.0.1:8000/ThisisApacheBench,Version2.3Copyright1996AdamT

mongodb - 按给定示例中的字段名称更新 mongo 事务

我正在使用labix作为驱动程序,我想对几个集合进行交易,我找到了链接http://blog.labix.org/2012/08/22/multi-doc-transactions-for-mongodb我想更新集合Owner和Employer不是通过Id而是通过集合中的Name字段。我怎样才能做到这一点(简单的切换Id和Name不起作用)。runner:=txn.NewRunner(tcollection)ops:=[]txn.Op{{C:"accounts",Id:"aram",//NameAssert:M{"balance":M{"$gte":100}},Update:M{"$i

mongodb - 我如何将 bson.M 元素列表组合成单个 bson.M 在 golang 的 mongo 中?

lstMap:=make([]interface{},0)lstMap=mongoOps.AddToBsonMap(lstMap,bson.M{"$inc":bson.M{"Google.ab.Value":1}})lstMap=mongoOps.AddToBsonMap(lstMap,bson.M{"$inc":bson.M{"Google.ab1.Value1":1}})func(o*MongoOps)AddToBsonMap(lstMap[]interface{},valueinterface{})(result[]interface{}){lstMap=append(lstMa

go - 无法在 go lang 中分配 *gorm.DB

我正在尝试从gorm.Open()返回一个实例,返回它我收到以下错误controllers/db.go:34:cannotassign*gorm.DBtodc.DB(typegorm.DB)inmultipleassignment这是db.goControllerpackagecontrollersimport(//"fmt"_"github.com/go-sql-driver/mysql"//v"github.com/spf13/viper""github.com/jinzhu/gorm")typeDBControllerstruct{DBgorm.DB}func(dc*DBCont

Go 查询 (db2) 不提供表中的所有字符 (utf-8)

表达我的问题很复杂,我尝试:我有一个DB2表(内部代码页CP850)createtablecodes(codecharacter(2))使用utf-8字符的数据集insertintocodesvalues('ÖÖ')在linux下,db2-clientsselect*fromcodes交付codeÖÖ正如预期的那样。现在对于Go部分,这是有问题的。我的模型看起来像packagecodestypeCodestruct{Codedb.NullString`json:"code"sql:"code"`}typeCodes[]*Code我的查询看起来像packagecodesfuncFindA

performance - golang json/gob/xml 中的序列化性能

转到标准库,Json序列化性能问题...JSON比XML和GOB慢,而json大小小于xml文件大小?请帮忙指出有什么错误吗?docker@dockhost:~/go/projects/wiki$gorunencoding.go2016/05/2400:52:16SerializationbyJSONelapsed:2152195us2016/05/2400:52:16students.json191777822016/05/2400:52:17SerializationbyGOBelapsed:748867us2016/05/2400:52:17students.gob9305166

mongodb - 使用 gopkg.in/mgo.v2 检查 mongo 中的对象是否存在

我正在寻找一种方便的方法来检查对象是否已存在于集合中。目前我找到的唯一方法是typeresultinterface{}varresresulterr:=col.Find(bson.M{"title":"title1"}).One(&res)iferr!=nil{iferr.Error()=="notfound"{log.Println("Nosuchdocument")}else{log.Println("erroccured",err)}}我不想创建变量res,如果对象存在,它可能是包含很多字段的非常重的文档。我希望有另一种方法,一些Check()函数只返回bool值..基本上我只需

performance - 戈朗 : right way to store map structure in lru cache

我有一个像这样的结构:map[key]value,我想通过一个字符串将它存储在"github.com/golang/groupcache/lru"中键,例如cacheKey。这是我的问题:我发现每当我想更新缓存项时,我都需要先获取:item:=cache.Get(cacheKey)ifv,ok:=item[key];ok{item[key]=new_valuecache.Add(cacheKey,item)}这样做是否正确?或者,正如一些人所建议的,我需要重新设计我的结构,以确保我可以在任何时候更新它时执行cache.Add(cacheKey,item)。或者,我什至应该使用像cach

postgresql - 如何在 Go 应用程序中处理打开/关闭 Db 连接?

我的WebAPI应用程序中有一组函数。他们对Postgres数据库中的数据执行一些操作。funcCreateUser(){db,err:=sql.Open("postgres","user=postgrespassword=passworddbname=api_devsslmode=disable")//Dosomedboperationshere}我想函数应该相互独立地与db一起工作,所以现在我在每个函数中都有sql.Open(...)。我不知道这是否是管理数据库连接的正确方法。我是否应该在应用程序启动后在某个地方打开它,并将db作为参数传递给相应的函数,而不是在每个函数中打开连接?