search
HomeDatabaseMysql Tutorial 第一次操刀数据库分表的教训与经验--白干一场

做完了分表之后,数据库里面的表从8张变成了8000张,我以为谷歌的抓取速度会降低为原来的一半,于是每天看一次谷歌抓取速度,结果实在是太失望了 结果发现,分完表之后谷歌抓取等待的时间迅速上升了,对mysql不是很了解,查了一下mysql的一些配置信息,我的

做完了分表之后,数据库里面的表从8张变成了8000张,,我以为谷歌的抓取速度会降低为原来的一半,于是每天看一次谷歌抓取速度,结果实在是太失望了

image

结果发现,分完表之后谷歌抓取等待的时间迅速上升了,对mysql不是很了解,查了一下mysql的一些配置信息,我的数据库默认是innodb,

结果发现innodb默认是把所有的表放在一个文件里面,无论这个数据库里面有多少张表,也想起来sqlserver默认也是吧所有的表放在一个文件里面,

sqlserver分表的时候自己可以新添加文件组,查了下mysql的配置,mysql 有这么个配置Innodb_file_per_table,不过设置完后必须从新导入一次数据,以后安装mysql得先看看Innodb_file_per_table的配置,以免自增麻烦。

我以为这样就好了,但是看谷歌抓取时候监控宝的监控记录,发现cpu还是和以前一样高

image

cpu高是因为什么呢?

是因为我分表造成的?

1:查看mysql 在win下的设置,说一台服务器上的文件句柄数最大为2048个,是不是我分的太多表造成(8000张。。)?-----经验欠缺,先这么着吧

2:会不会是因为我读取问题列表时候,吧问题的全部内容读取出来了,造成并发高时候,io忙,cpu很忙碌?-------这个有办法加个简介字段

3:会不会是因为我读取出来内容用正则表达式过滤html,传说正则表达式是高并发下的cpu杀手?--------------这个有办法加个简介字段、过滤html

给1000张表加字段的问题用博客园园友的分表工具,很轻松就搞定了,

原来是select * 换成 select 部分字段 PetaPoco 很容易就搞定了

以前是这么写的

Page result = learnDAL.learnDB.GetInstance().Page(page, itemsPerPage, @"select * from question_home order by addtime desc ", "");

                                    

现在这么写

Page result = learnDAL.learnDB.GetInstance().Page(page, itemsPerPage, PetaPoco.Sql.Builder.Select(@" title, titlecode, Brief as content, userid, siteid, tagids, havegoodanswer, addtime, tags").From("question_home").OrderBy("addtime desc ")

发现PetaPoco这种开源的小工具果然是小巧玲珑好掌握

做完之后上线做个压力测试对比下

【周五做的50并发和cpu观测】---ps:这个在线并发测试工具,只能免费使用几次,哎。。。。。。。

image

image

周六修改完之后

100个并发和cpu【ps:最后几个免费金币】

image

image

发现读取列表时候不读取大字段,和不做正则表达式过滤,cpu立马平稳了,

这次分表完全是白干了一场,还不知道一个mysql库里面放8000张表在win2003下是不是合理,是不是很糟糕,

求路过的大神指点一下 mysql和sqlserver,在一个数据库库里面放多少张表是合理的?

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use