对单表亿级数据的简单测试
本次对mysql做了单表亿级数据量的压测。 表的关系简单,只有两个int字段,user_id和company_id,且都增加了索引。 通过python脚本,随机向同一个表随机插入100W、500W、1000W-1E数据,并且记录了每次插入数据所耗时间。 先来看下写入数据的情况吧: python脚
本次对mysql做了单表亿级数据量的压测。
表的关系简单,只有两个int字段,user_id和company_id,且都增加了索引。
通过python脚本,随机向同一个表随机插入100W、500W、1000W-1E数据,并且记录了每次插入数据所耗时间。
先来看下写入数据的情况吧:
python脚本空转:
空转100W:0.14s
空转1000W:1.74s
单次插入1000W条数据:295.11s
1000W基础上再插入1000W,轮询,直到写入1E数据,记录每次插入所耗的时间。
可以看到,随着数据量的不断增大,每次插入1000W条数据的时间还是比较稳定,上下浮动不大。
我们最终关心的是单表乙级数据量下,查询速度能有多快。
下面是用python客户端脚本模拟对1E条数据进行随机查询,随机用的是python的随机函数;机器资源有限,开发机是公用的,
所以也没太敢占用太大资源来做压测,并发用的Python的线程模块。
本次查询测试采用三种方法:
1、单进程对数据库执行随机查询1000次操作,执行100次,记录每次时间
2、并发1000、2000线程对数据库进行随机查询1000次操作,记录每次时间
3、用mysql官方软件mysqlslap 对数据库进行操作
第一种:
单次查询1000次的结果,跑100次,发现时间浮动还是比较大,这可能跟插入的数据散列情况有关,
user_id相同的数据还是有不少,20-100之间,线上业务出现这种数据的情况不大,所以,这些数据不影响最终结果。
第二种:并发1000线程对数据库进行随机1000次查询,
1000线程:最慢时间8s,处理能力 125/s ;
2000线程:最慢时间10s,处理能力 100/s;
第三种:mysqlslap进行测试
开启2000个线程,执行SELECT * FROM user_company_test_5000 WHERE user_id=7432查询
平均处理时间8.76s,每秒能处理229个查询。
用官方的mysqlslap进行测试,跟python脚本的测试结果偏差较大,
猜测原因有两个:
1:mysqlslap 直接采用socket对Mysql进行连接,所以它除了 mysql处理时间和网络请求时间没有其他影响结果的操作
2:mysqlslap只能指定sql,没有办法随机查询数据,而测试表里面的数据分散不均匀,这也是一个原因。
mysqlslap的数据只能视为最好情况,但第二个python脚本则更接近生产环境,1000次查询数据也是随机查询,
所以第二种能作为生产环境的依据。
再来看看批量查询,IN 语句最多50个值
好吧,我只开了200个线程,最慢时间93s,最快时间46s,简直可以用惨不忍睹来讲。。如果是批量查询,
那就拆成多条语句来查吧。如果用IN ,必然会影响服务。
结论:
跟dba沟通过,理论上每秒能够支持5000次的查询量是比较正常的,但我用mysqlslap对单表100W的数据量进行了
测试,2000个client 每秒处理能力也只有700左右,
从第二种数据上看,当单机client达到2000时,每秒还能处理100次左右的查询,还是不错的。
原文出处:http://www.imsiren.com/archives/995
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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

70B model, 1000 tokens can be generated in seconds, which translates into nearly 4000 characters! The researchers fine-tuned Llama3 and introduced an acceleration algorithm. Compared with the native version, the speed is 13 times faster! Not only is it fast, its performance on code rewriting tasks even surpasses GPT-4o. This achievement comes from anysphere, the team behind the popular AI programming artifact Cursor, and OpenAI also participated in the investment. You must know that on Groq, a well-known fast inference acceleration framework, the inference speed of 70BLlama3 is only more than 300 tokens per second. With the speed of Cursor, it can be said that it achieves near-instant complete code file editing. Some people call it a good guy, if you put Curs

Last week, amid the internal wave of resignations and external criticism, OpenAI was plagued by internal and external troubles: - The infringement of the widow sister sparked global heated discussions - Employees signing "overlord clauses" were exposed one after another - Netizens listed Ultraman's "seven deadly sins" Rumors refuting: According to leaked information and documents obtained by Vox, OpenAI’s senior leadership, including Altman, was well aware of these equity recovery provisions and signed off on them. In addition, there is a serious and urgent issue facing OpenAI - AI safety. The recent departures of five security-related employees, including two of its most prominent employees, and the dissolution of the "Super Alignment" team have once again put OpenAI's security issues in the spotlight. Fortune magazine reported that OpenA

In 2025, global digital virtual currency trading platforms are fiercely competitive. This article authoritatively releases the top ten digital virtual currency trading platforms in the world in 2025 based on indicators such as transaction volume, security, and user experience. OKX ranks first with its strong technical strength and global operation strategy, and Binance follows closely with high liquidity and low fees. Platforms such as Gate.io, Coinbase, and Kraken are at the forefront with their respective advantages. The list covers trading platforms such as Huobi, KuCoin, Bitfinex, Crypto.com and Gemini, each with its own characteristics, but investment should be cautious. To choose a platform, you need to consider factors such as security, liquidity, fees, user experience, currency selection and regulatory compliance, and invest rationally

According to news on June 26, at the opening ceremony of the 2024 World Mobile Communications Conference Shanghai (MWC Shanghai), China Mobile Chairman Yang Jie delivered a speech. He said that currently, human society is entering the fourth industrial revolution, which is dominated by information and deeply integrated with information and energy, that is, the "digital intelligence revolution", and the formation of new productive forces is accelerating. Yang Jie believes that from the "mechanization revolution" driven by steam engines, to the "electrification revolution" driven by electricity, internal combustion engines, etc., to the "information revolution" driven by computers and the Internet, each round of industrial revolution is based on "information and "Energy" is the main line, bringing productivity development

Top 10 digital currency trading platforms: 1. OKX, 2. Binance, 3. Gate.io, 4. Huobi Global, 5. Kraken, 6. Coinbase, 7. KuCoin, 8. Bitfinex, 9. Crypto.com, 10. Gemini, these exchanges have their own characteristics, and users can choose the platform that suits them based on factors such as security, fees, currency selection, user interface and customer support.

Ranking of the top ten virtual currency trading platforms (latest in 2025): Binance: Global leader, high liquidity, and regulation has attracted attention. OKX: Large user base, supports multiple currencies, and provides leveraged trading. Gate.io: A senior exchange, with a variety of fiat currency payment methods, providing a variety of trading pairs and investment products. Bitget: Derivatives Exchange, high liquidity, low fees. Huobi: An old exchange that supports a variety of currencies and trading pairs. Coinbase: A well-known American exchange, strictly regulated. Phemex and so on.

This article recommends ten digital currency trading apps: 1. OKX; 2. Binance; 3. Gate.io; 4. Huobi Global; 5. Kraken; 6. Coinbase; 7. KuCoin; 8. Crypto.com; 9. Bitfinex; 10. Poloniex. When choosing a platform, you need to consider factors such as security, liquidity, transaction fees, currency selection, user interface, customer service support and regulatory compliance, and carefully evaluate risks and never blindly follow the trend.
