您的位置:首页 > 其它

应用优化

2016-07-20 15:10 267 查看
1.使用连接池

2.减少对 mysql 的访问
select old, gender from users where userid = 231;
select address from users where userid = 231;
这两句跟 
select old, gender, address from users where userid = 231;
这个请求数就减少了

3.使用查询缓存
show variables like '%query_cache%';

 have_query_cache             | YES     |     表明服务器在安装是否已经配置了高速缓存
| query_cache_limit            | 1048576 |    
| query_cache_min_res_unit     | 4096    |
| query_cache_size             | 1048576 |        表明缓存区大小,单位为 MB
| query_cache_type             | OFF     |        0/off 缓存关闭  1/on 缓存打开(使用 sql_no_cache 提示的 select 除外) 2/demand 只有带 sql_cache 的 select 语句提供高速缓存
| query_cache_wlock_invalidate | OFF    

 Qcache_free_blocks                            | 1            |        查询缓存中的空闲内存块的数目
| Qcache_free_memory                            | 1031360      |    查询缓存的空闲内存总数
| Qcache_hits                                   | 0            |        缓存采样数数目
| Qcache_inserts                                | 0            |        被加入到缓存中的查询数目
| Qcache_lowmem_prunes                          | 0            |    因为缺少内存而被从缓存中删除的查询数目
| Qcache_not_cached                             | 2139001      |    没有被缓存的查询数目(不能被缓存的,或由于 query_cache_type)
| Qcache_queries_in_cache                       | 0            |    在缓存中已注册的查询数目
| Qcache_total_blocks                           | 1            |        查询缓存中的块的总数目
| Queries                                       | 4008543      |
| Questions                                     | 3    

4.增加 cache 层

5.负载均衡
1)利用 mysql 复制分流查询操作
2)采用分布式数据库架构
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: