Browse Source

fasthttp-postgresql: optimize 'update' benchmark

Aliaksandr Valialkin 9 years ago
parent
commit
6ae6ebe698
1 changed files with 16 additions and 1 deletions
  1. 16 1
      frameworks/Go/fasthttp-postgresql/src/hello/hello.go

+ 16 - 1
frameworks/Go/fasthttp-postgresql/src/hello/hello.go

@@ -167,9 +167,24 @@ func updateHandler(ctx *fasthttp.RequestCtx) {
 		log.Fatalf("Error starting transaction: %s", err)
 		log.Fatalf("Error starting transaction: %s", err)
 	}
 	}
 
 
+	// Disable synchronous commit for the current transaction
+	// as a performance optimization.
+	// See http://www.postgresql.org/docs/current/static/runtime-config-wal.html for details.
+	// Below is the relevant quote from the docs:
+	//
+	// > It is therefore possible, and useful, to have some transactions
+	// > commit synchronously and others asynchronously. For example,
+	// > to make a single multistatement transaction commit asynchronously
+	// > when the default is the opposite, issue
+	// >     SET LOCAL synchronous_commit TO OFF
+	// > within the transaction.
+	if _, err = txn.Exec("SET LOCAL synchronous_commit TO OFF"); err != nil {
+		log.Fatalf("Error when disabling synchronous commit")
+	}
+
 	for i := 0; i < n; i++ {
 	for i := 0; i < n; i++ {
 		w := &worlds[i]
 		w := &worlds[i]
-		if _, err := txn.Exec("worldUpdateStmt", w.RandomNumber, w.Id); err != nil {
+		if _, err = txn.Exec("worldUpdateStmt", w.RandomNumber, w.Id); err != nil {
 			log.Fatalf("Error updating world row %d: %s", i, err)
 			log.Fatalf("Error updating world row %d: %s", i, err)
 		}
 		}
 	}
 	}