1、Redis预减库存减少数据库访问
2、内存标记减少Redis访问
3、请求先入队缓存,异步下单,提高用户体验。
4、RabbitMQ安装与Spring Boot集成
5、Nginx水平扩展
6、压测
核心是减少数据库访问。
1、系统初始化,把商品数量加载到Redis
2、收到请求,Redis预减库存
3、请求入队,立即返回排队中(因为现在还不知道最终会成功还是失败)
4、请求出队,生成订单(只允许10个,进入队列了11个,则最后一个请求不被满足)
使用yum命令安装的好处是能够自动解决依赖关系。
cd /etc/yum.repos.d
mv CentOS-Base.repo CentOS-Base.repo.bak
wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache
[root@localhost src]# yum install -y erlang
已加载插件:fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 erlang.x86_64.0.R16B-03.18.el7 将被 安装
--> 正在处理依赖关系 erlang-appmon(x86-64) = R16B-03.18.el7,它被软件包 erlang-R16B-03.18.el7.x86_64 需要
--> 正在处理依赖关系 erlang-asn1(x86-64) = R16B-03.18.el7,它被软件包 erlang-R16B-03.18.el7.x86_64 需要
--> 正在处理依赖关系 erlang-common_test(x86-64) = R16B-03.18.el7,它被软件包 erlang-R16B-03.18.el7.x8
otp_src_20.3 rabbitmq-server-3.7.5-1.el7.noarch.rpm
otp_src_20.3.tar.gz rabbitmq-server-generic-unix-3.7.5.tar.xz
[root@localhost src]# wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.6/rabbitmq-server-3.6.6-1.el6.noarch.rpm
--2018-05-27 16:58:11-- http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.6/rabbitmq-server-3.6.6-1.el6.noarch.rpm
正在解析主机 www.rabbitmq.com (www.rabbitmq.com)... 104.20.63.197, 104.20.62.197, 2400:cb00:2048:1::6814:3fc5, ...
正在连接 www.rabbitmq.com (www.rabbitmq.com)|104.20.63.197|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:5487359 (5.2M) [application/x-redhat-package-manager]
正在保存至: “rabbitmq-server-3.6.6-1.el6.noarch.rpm”
100%[===========================================================>] 5,487,359 114KB/s 用时 48s
2018-05-27 16:59:02 (111 KB/s) - 已保存 “rabbitmq-server-3.6.6-1.el6.noarch.rpm” [5487359/5487359])
[root@localhost src]# ls
otp_src_20.3 rabbitmq-server-3.7.5-1.el7.noarch.rpm
otp_src_20.3.tar.gz rabbitmq-server-generic-unix-3.7.5.tar.xz
rabbitmq-server-3.6.6-1.el6.noarch.rpm
[root@localhost src]# yum install rabbitmq-server-3.6.6-1.el6.noarch.rpm
已加载插件:fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
正在检查 rabbitmq-server-3.6.6-1.el6.noarch.rpm: rabbitmq-server-3.6.6-1.el6.noarch
rabbitmq-server-3.6.6-1.el6.noarch.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 rabbitmq-server.noarch.0.3.6.6-1.el6 将被 安装
--> 解决依赖关系完成
依赖关系解决
=====================================================================================================
Package 架构 版本 源 大小
=====================================================================================================
正在安装:
rabbitmq-server noarch 3.6.6-1.el6 /rabbitmq-server-3.6.6-1.el6.noarch 5.9 M
事务概要
=====================================================================================================
安装 1 软件包
总计:5.9 M
安装大小:5.9 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : rabbitmq-server-3.6.6-1.el6.noarch 1/1
验证中 : rabbitmq-server-3.6.6-1.el6.noarch 1/1
已安装:
rabbitmq-server.noarch 0:3.6.6-1.el6
完毕!
[root@localhost src]# find / -name rabitmq
[root@localhost src]# find / -name 'rabbitmq'
/etc/selinux/targeted/active/modules/100/rabbitmq
/etc/rabbitmq
/var/lib/rabbitmq
/var/log/rabbitmq
/usr/lib/ocf/resource.d/rabbitmq
/usr/lib/rabbitmq
[root@localhost src]# rabbitmq-server
RabbitMQ 3.6.6. Copyright (C) 2007-2016 Pivotal Software, Inc.
## ## Licensed under the MPL. See http://www.rabbitmq.com/
## ##
########## Logs: /var/log/rabbitmq/[email protected]
###### ## /var/log/rabbitmq/[email protected]
##########
Starting broker...
completed with 0 plugins.
^[[A^[[B^[[B^H^H^H^H^H^H^H^H^H^H^H^H^H^C
Session terminated, killing shell...^C ...已杀死。
[root@localhost src]# ^C
[root@localhost src]#
[root@localhost src]#
[root@localhost src]#