pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

      <bdo id='opGoo'></bdo><ul id='opGoo'></ul>

      <tfoot id='opGoo'></tfoot>

    1. <small id='opGoo'></small><noframes id='opGoo'>

    2. <legend id='opGoo'><style id='opGoo'><dir id='opGoo'><q id='opGoo'></q></dir></style></legend>
      <i id='opGoo'><tr id='opGoo'><dt id='opGoo'><q id='opGoo'><span id='opGoo'><b id='opGoo'><form id='opGoo'><ins id='opGoo'></ins><ul id='opGoo'></ul><sub id='opGoo'></sub></form><legend id='opGoo'></legend><bdo id='opGoo'><pre id='opGoo'><center id='opGoo'></center></pre></bdo></b><th id='opGoo'></th></span></q></dt></tr></i><div class="v77r5rf" id='opGoo'><tfoot id='opGoo'></tfoot><dl id='opGoo'><fieldset id='opGoo'></fieldset></dl></div>

    3. MySql 性能慢

      Slow performance MySql(MySql 性能慢)
      <legend id='KKjtg'><style id='KKjtg'><dir id='KKjtg'><q id='KKjtg'></q></dir></style></legend>
          <tbody id='KKjtg'></tbody>
          <tfoot id='KKjtg'></tfoot>
            <bdo id='KKjtg'></bdo><ul id='KKjtg'></ul>

              <small id='KKjtg'></small><noframes id='KKjtg'>

              <i id='KKjtg'><tr id='KKjtg'><dt id='KKjtg'><q id='KKjtg'><span id='KKjtg'><b id='KKjtg'><form id='KKjtg'><ins id='KKjtg'></ins><ul id='KKjtg'></ul><sub id='KKjtg'></sub></form><legend id='KKjtg'></legend><bdo id='KKjtg'><pre id='KKjtg'><center id='KKjtg'></center></pre></bdo></b><th id='KKjtg'></th></span></q></dt></tr></i><div class="znt5tnp" id='KKjtg'><tfoot id='KKjtg'></tfoot><dl id='KKjtg'><fieldset id='KKjtg'></fieldset></dl></div>

                本文介紹了MySql 性能慢的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在測試我正在構建的系統的性能,它真的很慢,而且我不知道為什么或者是否應該這么慢.我正在測試的是我可以對數據庫執行多少次 INSERT,每秒大約 22 次.這聽起來真的很慢,當我嘗試插入時,我可以在大約 0.5 秒內插入 30000 條記錄.在現實生活中,插入是由系統中的不同用戶進行的,因此連接、發送查詢、解析查詢等的開銷將始終存在.到目前為止我嘗試過的:

                I'm trying out performance of a system I'm building, and it's really slow, and I don't know why or if it should be this slow. What I'm testing is how many single INSERT I can do to the database and I get around 22 per second. That sounds really slow and when I tried to do the inserts i a singel big SQL-query I can insert 30000 records in about 0.5 seconds. In real life the inserts is made by different users in the system so the overhead of connecting, sending the query, parsing the query etc. will always be there. What I have tried so far:

                • 用盡可能少的代碼編寫mysqli.= 每秒 22 次插入
                • 使用盡可能少的代碼的 PDO.= 每秒 22 次插入
                • 將連接主機從本地主機更改為 127.0.0.1 = 每秒 22 次插入
                • 沒有語句對象的 mysqli 并檢查 SQL 注入 = 每秒 22 次插入

                所以這里似乎有問題.

                系統規格:

                • 英特爾 i5
                • 16 公制內存
                • 7200 rpm 磁盤驅動器

                軟件:

                • Windows 10
                • XAMPP,MariaDB 相當新
                • 數據庫引擎 innoDB.

                我用來做測試的代碼:

                $amountToInsert = 1000;
                //$fakeData is an array with randomly generated emails 
                $fakeData = getFakeData($amountToInsert); 
                $db = new DatabaseHandler();
                for ($i = 0; $i < $amountToInsert; $i++) {
                    $db->insertUser($fakeUsers[$i]);
                }
                $db->closeConnection();
                

                調用數據庫的類:

                class DatabaseHandler {
                    private $DBHOST = 'localhost';
                    private $DBUSERNAME = 'username';
                    private $DBPASSWORD = 'password';
                    private $DBNAME = 'dbname';
                    private $DBPORT = 3306;
                
                    private $mDb;
                
                    private $isConnected = false;
                
                    public function __construct() {
                        $this->mDb = new mysqli($this->DBHOST, $this->DBUSERNAME
                                              , $this->DBPASSWORD, $this->DBNAME
                                              , $this->DBPORT);
                        $this->isConnected = true;
                    }
                
                    public function closeConnection() {
                        if ($this->isConnected) {
                            $threadId = $this->mDb->thread_id;
                            $this->mDb->kill($threadId);
                            $this->mDb->close();
                            $this->isConnected = false;
                        }
                    }
                
                    public function insertUser($user) {
                        $this->mDb->autocommit(true);
                        $queryString = 'INSERT INTO `users`(`email`, `company_id`) '
                                        .'VALUES (?, 1)';
                        $stmt = $this->mDb->prepare($queryString);
                        $stmt->bind_param('s', $user);
                        if ($stmt->execute()) {
                            $stmt->close();
                            return 1;
                        } else {
                            $stmt->close();
                            return 0;
                        }
                    }
                }
                

                user"表有 4 列,結構如下:

                The "user" table has 4 columns with the following structure:

                • id INT 無符號主鍵
                • 電子郵件 VARCHAR(60)
                • company_id INT 無符號索引
                • 引導文本

                我在這里不知所措,真的不知道下一步該往哪里看.任何在正確方向上的幫助將不勝感激.

                I'm at a loss here and don't really know where to look next. Any help in the right direction would be very much appreciated.

                推薦答案

                就像評論中解釋的那樣,這應該歸咎于 InnoDB.默認情況下,此引擎過于謹慎,不使用磁盤緩存,以確保數據確實已寫入磁盤,然后再向您返回成功消息.所以你基本上有兩個選擇.

                Like it's explained in the comments, it's InnoDB to blame. By default this engine is too cautious and doesn't utilize the disk cache, to make sure that data indeed has been written on disk, before returning you a success message. So you basically have two options.

                1. 大多數時候你只是不關心確認的寫入.因此,您可以通過將此 mysql 選項設置為零來配置 mysql:

                1. Most of time you just don't care for the confirmed write. So you can configure mysql by setting this mysql option to zero:

                innodb_flush_log_at_trx_commit = 0
                

                只要這樣設置,你的 InnoDB 寫入幾乎和 MyISAM 一樣快.

                as long as it's set this way, your InnoDB writes will be almost as fast as MyISAM.

                另一種選擇是將您的所有寫入都包裝在一個事務中.由于它只需要對所有寫入進行一次確認,因此速度也相當快.

                Another option is wrapping all your writes in a single transaction. As it will require only single confirmation from all the writes, it will be reasonable fast too.

                當然,通過多次插入只準備一次查詢是明智的,但與上述問題相比,速度增益可以忽略不計.因此,它既不能作為對此類問題的解釋,也不能作為補救措施.

                Of course, it's just sane to prepare your query only once with multiple inserts but the speed gain is negligible compared to the issue above. So it doesn't count neither as an explanation nor as a remedy for such an issue.

                這篇關于MySql 性能慢的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                store_result() and get_result() in mysql returns false(mysql 中的 store_result() 和 get_result() 返回 false)
                Call to undefined function mysqli_result::num_rows()(調用未定義的函數 mysqli_result::num_rows())
                PHP Prepared Statement Problems(PHP 準備好的語句問題)
                mysqli_fetch_array returning only one result(mysqli_fetch_array 只返回一個結果)
                PHP MySQLi Multiple Inserts(PHP MySQLi 多次插入)
                How do I make sure that values from MySQL keep their type in PHP?(如何確保 MySQL 中的值在 PHP 中保持其類型?)
                  <legend id='POZ4b'><style id='POZ4b'><dir id='POZ4b'><q id='POZ4b'></q></dir></style></legend>

                  <small id='POZ4b'></small><noframes id='POZ4b'>

                1. <i id='POZ4b'><tr id='POZ4b'><dt id='POZ4b'><q id='POZ4b'><span id='POZ4b'><b id='POZ4b'><form id='POZ4b'><ins id='POZ4b'></ins><ul id='POZ4b'></ul><sub id='POZ4b'></sub></form><legend id='POZ4b'></legend><bdo id='POZ4b'><pre id='POZ4b'><center id='POZ4b'></center></pre></bdo></b><th id='POZ4b'></th></span></q></dt></tr></i><div class="h5xjht5" id='POZ4b'><tfoot id='POZ4b'></tfoot><dl id='POZ4b'><fieldset id='POZ4b'></fieldset></dl></div>
                    1. <tfoot id='POZ4b'></tfoot>

                        <bdo id='POZ4b'></bdo><ul id='POZ4b'></ul>
                          <tbody id='POZ4b'></tbody>

                        • 主站蜘蛛池模板: 密度电子天平-内校-外校电子天平-沈阳龙腾电子有限公司 | 隔爆型防爆端子分线箱_防爆空气开关箱|依客思 | 石家庄救护车出租_重症转院_跨省跨境医疗转送_活动赛事医疗保障_康复出院_放弃治疗_腾康26年医疗护送转诊团队 | 伊卡洛斯软装首页-电动窗帘,别墅窗帘,定制窗帘,江浙沪1000+别墅窗帘案例 | 恒温振荡混匀器-微孔板振荡器厂家-多管涡旋混匀器厂家-合肥艾本森(www.17world.net) | 南京兰江泵业有限公司-水解酸化池潜水搅拌机-絮凝反应池搅拌机-好氧区潜水推进器 | 电解抛光加工_不锈钢电解抛光_常州安谱金属制品有限公司 | 河南橡胶接头厂家,河南波纹补偿器厂家,河南可曲挠橡胶软连接,河南套筒补偿器厂家-河南正大阀门 | 波纹补偿器_不锈钢波纹补偿器_巩义市润达管道设备制造有限公司 | 知网论文检测系统入口_论文查重免费查重_中国知网论文查询_学术不端检测系统 | 钢格板|镀锌钢格板|热镀锌钢格板|格栅板|钢格板|钢格栅板|热浸锌钢格板|平台钢格板|镀锌钢格栅板|热镀锌钢格栅板|平台钢格栅板|不锈钢钢格栅板 - 专业钢格板厂家 | 电加热导热油炉-空气加热器-导热油加热器-翅片电加热管-科安达机械 | 变频器维修公司_plc维修_伺服驱动器维修_工控机维修 - 夫唯科技 变位机,焊接变位机,焊接变位器,小型变位机,小型焊接变位机-济南上弘机电设备有限公司 | 云阳人才网_云阳招聘网_云阳人才市场_云阳人事人才网_云阳人家招聘网_云阳最新招聘信息 | 锂电池砂磨机|石墨烯砂磨机|碳纳米管砂磨机-常州市奥能达机械设备有限公司 | 【MBA备考网】-2024年工商管理硕士MBA院校/报考条件/培训/考试科目/提前面试/考试/学费-MBA备考网 | TTCMS自助建站_网站建设_自助建站_免费网站_免费建站_天天向上旗下品牌 | 气动绞车,山东气动绞车,气动绞车厂家-烟台博海石油机械有限公司 气动隔膜泵厂家-温州永嘉定远泵阀有限公司 | 超声波焊接机,振动摩擦焊接机,激光塑料焊接机,超声波焊接模具工装-德召尼克(常州)焊接科技有限公司 | 健康管理师报考条件,考试时间,报名入口—首页 | 湖北省煤炭供应链综合服务平台| 工业淬火油烟净化器,北京油烟净化器厂家,热处理油烟净化器-北京众鑫百科 | 泰国专线_泰国物流专线_广州到泰国物流公司-泰廊曼国际 | 智能楼宇-楼宇自控系统-楼宇智能化-楼宇自动化-三水智能化 | LNG鹤管_内浮盘价格,上装鹤管,装车撬厂家-连云港赛威特机械 | 天津拓展_天津团建_天津趣味运动会_天津活动策划公司-天津华天拓展培训中心 | 防水试验机_防水测试设备_防水试验装置_淋雨试验箱-广州岳信试验设备有限公司 | 杭州网络公司_百度SEO优化-外贸网络推广_抖音小程序开发-杭州乐软科技有限公司 | 污水处理设备维修_污水处理工程改造_机械格栅_过滤设备_气浮设备_刮吸泥机_污泥浓缩罐_污水处理设备_污水处理工程-北京龙泉新禹科技有限公司 | 消泡剂_水处理消泡剂_切削液消泡剂_涂料消泡剂_有机硅消泡剂_广州中万新材料生产厂家 | 细石混凝土泵_厂家_价格-烟台九达机械有限公司 | 神超官网_焊接圆锯片_高速钢锯片_硬质合金锯片_浙江神超锯业制造有限公司 | 口臭的治疗方法,口臭怎么办,怎么除口臭,口臭的原因-口臭治疗网 | 恒压供水控制柜|无负压|一体化泵站控制柜|PLC远程调试|MCGS触摸屏|自动控制方案-联致自控设备 | 郑州水质检测中心_井水检测_河南废气检测_河南中环嘉创检测 | 等离子空气净化器_医用空气消毒机_空气净化消毒机_中央家用新风系统厂家_利安达官网 | 没斑啦-专业的祛斑美白嫩肤知识网站-去斑经验分享 | 沥青灌缝机_路面灌缝机_道路灌缝机_沥青灌缝机厂家_济宁萨奥机械有限公司 | 【化妆品备案】进口化妆品备案流程-深圳美尚美化妆品有限公司 | 工业rfid读写器_RFID工业读写器_工业rfid设备厂商-ANDEAWELL | 飞利浦LED体育场灯具-吸顶式油站灯-飞利浦LED罩棚灯-佛山嘉耀照明有限公司 |