Created
January 19, 2018 00:29
-
-
Save eminetto/06224f221ef9972019a628dda026b95d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"os" | |
"time" | |
"github.com/joho/godotenv" | |
"github.com/juju/mgosession" | |
"github.com/thecodenation/stamp/pkg/elog" | |
"github.com/thecodenation/stamp/pkg/position" | |
mgo "gopkg.in/mgo.v2" | |
"gopkg.in/mgo.v2/bson" | |
) | |
func main() { | |
env := os.Getenv("CODENATION_ENV") | |
err := godotenv.Load("config/" + env + ".env") | |
if err != nil { | |
log.Fatal("Error loading .env file") | |
elog.Error(err) | |
} | |
session, err := mgo.Dial(os.Getenv("MONGODB_HOST")) | |
if err != nil { | |
log.Fatal("Error conecting to mongodb") | |
elog.Error(err) | |
} | |
defer session.Close() | |
p := mgosession.NewPool(nil, session, 3) | |
defer p.Close() | |
echoAll(p) | |
time.Sleep(180000 * time.Millisecond) | |
echoAll(p) | |
time.Sleep(180000 * time.Millisecond) | |
} | |
func echoAll(p *mgosession.Pool) { | |
for i := 0; i < 50; i++ { | |
go echo(p.Session(nil)) | |
} | |
time.Sleep(1000 * time.Millisecond) | |
for i := 0; i < 50; i++ { | |
go echo(p.Session(nil)) | |
} | |
time.Sleep(1000 * time.Millisecond) | |
for i := 0; i < 50; i++ { | |
go echo(p.Session(nil)) | |
} | |
} | |
func echo(s *mgo.Session) { | |
var d []*position.Position | |
coll := s.DB("codenation").C("position") | |
err := coll.Find(bson.M{"company._id": bson.ObjectIdHex("5a5c9cdd47a9250562288cb5")}).All(&d) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(d[0].ID.Hex()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment