소스 검색

Merge pull request #313 from robfig/fix

Fix: pick different rows for concurrent reqs
Patrick Falls 12 년 전
부모
커밋
3da943d3e0
1개의 변경된 파일2개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 1
      revel/src/benchmark/app/controllers/app.go

+ 2 - 1
revel/src/benchmark/app/controllers/app.go

@@ -62,8 +62,8 @@ func (c App) Json() revel.Result {
 }
 }
 
 
 func (c App) Db(queries int) revel.Result {
 func (c App) Db(queries int) revel.Result {
-	rowNum := rand.Intn(WorldRowCount) + 1
 	if queries <= 1 {
 	if queries <= 1 {
+		rowNum := rand.Intn(WorldRowCount) + 1
 		var w World
 		var w World
 		worldStatement.QueryRow(rowNum).Scan(&w.Id, &w.RandomNumber)
 		worldStatement.QueryRow(rowNum).Scan(&w.Id, &w.RandomNumber)
 		return c.RenderJson(w)
 		return c.RenderJson(w)
@@ -74,6 +74,7 @@ func (c App) Db(queries int) revel.Result {
 	wg.Add(queries)
 	wg.Add(queries)
 	for i := 0; i < queries; i++ {
 	for i := 0; i < queries; i++ {
 		go func(i int) {
 		go func(i int) {
+			rowNum := rand.Intn(WorldRowCount) + 1
 			err := worldStatement.QueryRow(rowNum).Scan(&ww[i].Id, &ww[i].RandomNumber)
 			err := worldStatement.QueryRow(rowNum).Scan(&ww[i].Id, &ww[i].RandomNumber)
 			if err != nil {
 			if err != nil {
 				revel.ERROR.Fatalf("Error scanning world row: %v", err)
 				revel.ERROR.Fatalf("Error scanning world row: %v", err)