Browse Source

Reduce the number of locks (#5975)

* Reduce the number of locks

* fix

* fix

* fix
vic 5 years ago
parent
commit
0e8fd82b64

+ 1 - 1
frameworks/PHP/one/App/Config/mysql.php

@@ -3,7 +3,7 @@
 return [
     'debug_log' => false, // 是否打印sql日志
     'default'      => [
-        'max_connect_count' => 30,
+        'max_connect_count' => 20,
         'dns'               => env('mysql.default.dns', 'mysql:host=127.0.0.1;dbname=test'),
         'username'          => env('mysql.default.username', 'root'),
         'password'          => env('mysql.default.password', '123456'),

+ 7 - 2
frameworks/PHP/one/App/Controllers/IndexController.php

@@ -53,12 +53,17 @@ class IndexController extends Controller
     {
         $count = max(min(intval($count), 500), 1);
         $list  = [];
-        $updates = [];
+        $updates = ['begin'];
         while ($count--) {
             $row    = World::repeatStatement()->find(mt_rand(1, 10000));
             $list[] = $row;
-            $updates[] = 'update world set randomNumber='.mt_rand(1, 10000).' where id='.$row->id;
+            $old = intval($row->randomNumber);
+            do {
+                $new = mt_rand(1, 10000);
+            } while($old === $new);
+            $updates[] = 'update world set randomNumber='.$new.' where id='.$row->id;
         }
+        $updates[] = 'commit;';
         $row->exec(implode(';',$updates));
         return $this->json($list);
     }