(Cache,Asynchronous,Concurrent)
前端性能优化
- 网页瘦身,降低带宽消耗。
- 尽量少的使用图片及大体积的东西。
- 合并js、css文件以减少请求加载次数
- 页面静态化
- DNS负载均衡
- CDN,Content Delivery Network,即内容分发网络
后台性能优化
- 数据库部分
- 数据冗余
将数据库的数据冗余处理,以减少大表连接查询 - 数据镜像
- 数据分区
- 数据冗余
- 逻辑
Cache
- page caching
- action caching
- Action caching is dependent on urls.
- fragment caching
- Fragment caching is dependent on the view being rendered.
- 片段缓存(Fragment caching)就是缓存已渲染的HTML片段进Rails.cache,(P: Rails provides a ‘cache’ view helper for this. It’s most basic form takes no arguments besides a block.)
<%= cache "#test{@test.id}-{@test.updated_at}" do %>
<div>
<b><%= @test.title %></b>
</div>
...
<% end %>
All cached content are stored in the Rails.cache(except page caching). Page caching are stored as HTML on disk.
Tip:
- 把握缓存粒度,以降低expired,提高命中率为目标
- 数据一致性