Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

备稿:4月10日 日常分享(原贝贝) #22

Closed
gsk475 opened this issue Apr 11, 2020 · 1 comment
Closed

备稿:4月10日 日常分享(原贝贝) #22

gsk475 opened this issue Apr 11, 2020 · 1 comment

Comments

@gsk475
Copy link
Collaborator

gsk475 commented Apr 11, 2020

No description provided.

@gsk475 gsk475 changed the title 备稿:4月10日 日常分享(未定) 备稿:4月10日 日常分享(原贝贝) Apr 11, 2020
@baysky
Copy link

baysky commented Apr 11, 2020

如何减少CPU消耗

减少等待

减少IO量

  • SQL/index,使用合适的索引减少扫描的行数(需平衡索引的正收益和维护开销,空间换时间)

  • 提升IO处理能力

  • 加cache/加磁盘/SSD

减少计算

减少逻辑运算量

  • 避免使用函数,将运算转移至易扩展的应用服务器中 如substr等字符运算,dateadd/datesub等日期运算,abs等数学函数

  • 减少排序,利用索引取得有序数据或避免不必要排序 如union all代替 union,order by 索引字段等

  • 禁止类型转换,使用合适类型并保证传入参数类型与数据库字段类型绝对一致 如数字用tiny/int/bigint等,必需转换的在传入数据库之前在应用中转好

  • 简单类型,尽量避免复杂类型,降低由于复杂类型带来的附加运算。更小的数据类型占用更少的磁盘、内存、cpu缓存和cpu周期

减少逻辑IO量

  • index,优化索引,减少不必要的表扫描 如增加索引,调整组合索引字段顺序,去除选择性很差的索引字段等等

  • table,合理拆分,适度冗余 如将很少使用的大字段拆分到独立表,非常频繁的小字段冗余到“引用表”

  • SQL,调整SQL写法,充分利用现有索引,避免不必要的扫描,排序及其他操作 如减少复杂join,减少order by,尽量union all,避免子查询等

  • 数据类型,够用就好,减少不必要使用大字段 如tinyint够用就别总是int,int够用也别老bigint,date够用也别总是timestamp

减少query请求量(非数据库本身)

  • 适当缓存,降低缓存数据粒度,对静态并被频繁请求的数据进行适当的缓存 如用户信息,商品信息等

  • 优化实现,尽量去除不必要的重复请求 如禁止同一页面多次重复请求相同数据的问题,通过跨页面参数传递减少访问等

  • 合理需求,评估需求产出比,对产出比极端底下的需求合理去除

升级cpu

  • 低延迟(快速响应),需要更快的cpu(每个查询只能使用一个cpu)

  • 高吞吐,同时运行很多查询语句,能从多个cpu处理查询中收益

@gsk475 gsk475 closed this as completed Apr 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants