互联网创业的准备数据库:硬盘iops、mysql
《互联网创业的准备》系列文章 硬盘常识: 机械硬盘HDD固态硬盘SSD 最小单位1个扇区为512B,或4K(2012年民用普及)1个分页为4K、8K或更高() 性能因素转速(rpm):5400、7200、1w、1.5w层数:SLC(单层快)、MLC(双层慢)、TLC(三层更慢,SSD暂未采用,
《互联网创业的准备》系列文章——
硬盘常识:机械硬盘HDD 固态硬盘SSD
最小单位 1个扇区为512B,或4K(2012年民用普及) 1个分页为4K、8K或更高()
性能因素 转速(rpm):5400、7200、1w、1.5w 层数:SLC(单层快)、MLC(双层慢)、TLC(三层更慢,SSD暂未采用,U盘大量采用)
接口 SATA 3G、SATA 6G(2012年民用普及)、SAS 6G SATA 3G、SATA 6G、SAS 6G、PCI-E
尺寸 2.5英寸、3.5英寸 2.5英寸、PCI-E版型
常见品牌 西部数据、希捷 Intel、镁光(Crucial)、浦科特(PLEXTOR)
硬盘性能指标:
连续读写(常用单位为MB/s):文件在硬盘上存储位置是连续的,适用场景:大文件拷贝(比如视频音乐)。速度即使很高,对数据库性能也没有参考价值。
4K随机读写(常用单位为iops):在硬盘上随机位置读写数据,每次4KB,适用场景:操作系统运行、软件运行、数据库。(图片静态服务器、视频静态服务器是大文件,测试64K随机或更大)
常用硬盘性能测试软件:
Windows:AS SSD Benchmark、CrystalDiskMark、HD Tune Pro、iometer
Linux:iometer
Align I/Os:硬盘IO大小。测试设备时根据硬盘最小单位进行选择,机械硬盘上选512B或4K,SSD上选4K、8K等。测试分区时受分区sector size影响。由于Linux ext3的sector size为4096,所以在扇区为512B的机械硬盘上也无法选择Align I/Os on 512B进行测试,测试效果不佳。vps无法进行设备测试,如果是自购服务器,应使用设备测试。
Seq 即 Sequential 即连续读写。AS SSD会先以16MB的尺寸为单位,持续向受测分区写入生成1个达到1GB大小的文件,然后再以同样的单位尺寸读取这个,最后计算平均成绩而给出结果。
4K 即 Random 4k, Queue Depth=1 即 随机4K并发1个队列。AS SSD会以512KB的单位尺寸生成1GB大小的测试文件,然后在其地址范围(LBA)内进行随机4KB单位尺寸进行写入及读取测试,直到跑遍这个范围为止,最后同样计算平均成绩给出结果。
4K QD32 即 Random 4k, Queue Depth=32 即 随机4K并发32个队列。
4K-64Thrd 即 4K, 64 Thread 即 随机4K并发64个线程,和 4K QD64是一个意思。AS SSD会生成64个16MB大小的测试文件(共计1GB),然后同时以4KB的单位尺寸,同时在这64个文件中进行写入和读取测试,最后依然以平均成绩为结果。
通过AS SSD可以看出,iops与MB/s可以直接换算,比如4K读取是6227iops,即每秒钟可以读取6227个4K的文件,即 6227 * 4K / 1024 = 24.3 MB/s。
Intel的SSD性能数据采用iometer 4K QD32的测试结果:
价格与速度:
型号 容量 2012价格 4K QD32随机读/写(iops) 4K QD64 连续读写(MB/s)
民用 机械7200rpm 3.5英寸 SATA 6G 希捷Barracuda 7200.14 3TB ¥1.1k 409/365 386/291 200/180
企业级 机械10000rpm 2.5英寸 SAS 6G 希捷Savvio 10K.5 300GB ¥1k 750/700 170/170
企业级 机械15000rpm 2.5英寸 SAS 6G 希捷Savvio 15K.3 300GB ¥2.2k
企业级 固态SLC 2.5英寸 SATA 3G Intel X25-E 32G ¥2.5k 3.5w/3.3k 250/170
企业级 固态MLC PCI-E Intel 910 400G ¥14w 9w/3.8w 1000/750
企业级 固态MLC PCI-E Intel 710 100G ¥2.5k 3.8w/2.3k 270/170
民用 固态MLC 2.5英寸 SATA 6G Intel 520 120G ¥840 2.5w/8w 550/500
民用 固态MLC 2.5英寸 SATA 6G 镁光 M4 128G ¥800 7.8w/4.2w 7w/4w 500/175
为什么民用SSD的iops很高价格却很低,而企业级SSD的iops有的很低而价格却很高?因为企业级SSD的耐用性高,比如Intel 710 100G寿命为4K写入500TB,即5000次全盘写入。
Intel SSD寿命指标:smart中的“E8:Avai lable Reserved Space”:可用的预留闪存数量、“E9:Media Wearout Indicator”:闪存磨耗指数。其他厂商的SSD类似,比如镁光的wear leaving count。
SSD新盘的剩余磨损为100,当低于10时,应更换,报废。
todo:数据库的选择
关系型数据库用Mysql还是PostgreSQL,或者全用NoSQL?mongo还是hbase?
Mysql 和 PostgreSQL都可以。mysql用的人多,但是oracle收购sun以后,把mysql限制的更加封闭,正在衰落,和可能和OpenOffice一样被oracle整死,免备案空间,衍生出LibreOffice。但不用很担心,即使mysql被oracle整死,也会衍生出开源版本,使用方式一样。
关系型数据库和NoSQL搭配使用较好,关系型适合底层业务,NoSQL适合上层业务。关注淘宝hbase的使用。
Mysql性能与硬盘iops的关系:mysql可以把读取结果放在内存中,即query cache,所以db server安装大内存即可实现只读内存、不读硬盘。
当预计数据量会增长到超过内存大小时,进行分表(把一个表中的数据拆分),放到多个大内存服务器上,保证每个服务器上的数据都小于内存大小,香港服务器,即可实现全部缓存。
2012年内存价格:UDIMM no ECC DDR3 1600民用内存 ¥270/8GB,RDIMM ECC DDR3 1600服务器内存 ¥440/8G。但一台服务器能安装的内存有限,2012年典型的Dell服务器有24个插槽,主板芯片支持768G内存,2012年DDR3内存生产工艺最高是单条8G(DDR4已实现单条16G,但主板尚未支持DDR4),所以一台服务器最大内存192G(¥440 * 24条 = 1w)。
数据库写入时必须写硬盘(否则就不叫持久化存储了……),¥2.5k的Intel 710企业级SSD的写入iops为2.3k,而万转硬盘的iops为700,如果要达到SSD的性能,需要多块万转硬盘组RAID。如果使用iops为3w的SSD,性能比机械硬盘提升了30倍。
如果数据量不大,远低于192G,就不需要做分表了吗?
仍然要分表,原因有2个:
1、大内存会提升mysql读取性能,但并发读取能力也是有上限的,香港虚拟主机,这时受CPU性能限制,2012年典型的服务器是双路,即2个8核CPU(mysql内存并发待测试)。
2、内存很大,对并发写入能力没有作用,写入能力完全依赖于硬盘的iops。一台服务器的写入性能很有限,请看下面的测试。

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

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

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

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

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.

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment
