range

If there were you, the world would be just right

1、安装ShadowSocks

#yum install python-setuptools && easy_install pip 
#pip install shadowsocks

安装

wget https://bootstrap.pypa.io/3.5/get-pip.py
python3 get-pip.py
pip3 install shadowsocks

2、创建配置文件

vi /etc/shadowsocks.json

内容:

{ 
    "server":"0.0.0.0", 
    "server_port":8388,
    "password":"admin888", 
    "timeout":600, 
    "method":"rc4-md5"
}

3、启动

 #ssserver -c /etc/shadowsocks.json -d start

4、Windows客户端地址
https://github.com/shadowsocks/shadowsocks-windows/releases


主要内容

  1. 大数据量统计重复问题
  2. 促销商品超卖问题
  3. 百万用户千万订单查询问题
  4. mysql分库分表求和问题。
  5. mysq使用innodb引擎上千万级别的数据怎么导出。

1. 大数据量统计重复问题

问题描述

  1. 上亿条数据(有重复),统计其中出现次数最多的前N个数

以上类型题目其本质其实还是属于统计类型的业务,比如:统计目前商品表中各个分类的商品数量,并排出前十的分类以及分类商品数量。

对于这种业务我们有多种不同的方案,以下是方案解释:

方案1

该类型的案例:统计目前商品表中各个分类的商品数量,并排出前十的分类以及分类商品数量。

涉及sql语句以及表此时数据量:

select count(*) as count,category_id from products group by category_id order by count desc limit 0,10;


为优化此sql语句,我们加了一个idx_category_id(category_id)的索引。但是这个索引的优化并不理想。所以我们需要另辟蹊跷。

查询效率比较低:多达45s

mysql> select count(*) as count,category_id from products group by category_id order by count desc limit 0,10;
+--------+-------------+
| count  | category_id |
+--------+-------------+
| 792262 |          44 |
| 792108 |          81 |
| 791920 |          39 |
| 791488 |          18 |
| 791354 |          95 |
| 791258 |          35 |
| 791208 |          51 |
| 791160 |          82 |
| 791095 |          29 |
| 791084 |          37 |
+--------+-------------+
10 rows in set (1 min 45.95 sec)

阅读剩余部分...