Browse Source

Fix: pick different rows for concurrent reqs

Rob Figueiredo 12 years ago
parent
commit
cf2a2495dc
1 changed files with 4 additions and 2 deletions
  1. 4 2
      revel/src/benchmark/app/controllers/app.go

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

@@ -67,8 +67,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)
@@ -79,6 +79,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)
@@ -91,8 +92,8 @@ func (c App) Db(queries int) revel.Result {
 }
 }
 
 
 func (c App) Update(queries int) revel.Result {
 func (c App) Update(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)
 		w.RandomNumber = uint16(rand.Intn(WorldRowCount) + 1)
 		w.RandomNumber = uint16(rand.Intn(WorldRowCount) + 1)
@@ -107,6 +108,7 @@ func (c App) Update(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)