Giter Site home page Giter Site logo

clicking's Introduction

🤞clicking

When you're ready to buy a seckill item, you click the seckill button repeatedly

项目作者 项目使用语言 JDK版本 项目状态 项目进度

项目介绍:

Clicking是一个基于SpringBoot实现的秒杀系统,通过一些优化,提升其应对高并发的处理能力。

写在最前面

该项目主要能体现了应对高并发,大流量场景的秒杀系统的解决方案。(初学者入门)

项目效果展示

ProjectPresentations3

项目的基本结构

展开查看

.
├─main
│  ├─java
│  │  └─com
│  │      └─github
│  │          └─soyanga
│  │              └─secondskillsystem
│  │                  ├─access  	-- 防刷限流组件
│  │                  ├─config		-- 方法参数解析组件
│  │                  ├─controller	-- MVC的web层
│  │                  ├─dao			-- 数据库操作
│  │                  ├─domain		-- 实体类
│  │                  ├─exception	-- 全局异常处理
│  │                  ├─rabbitmq	-- RabbitMq组件
│  │                  ├─redis		-- Redis,Jedis 相关缓存配置
│  │                  ├─result		-- 请求结果封装
│  │                  ├─service		-- 服务层实现
│  │                  ├─util		-- 工具组件
│  │                  ├─Validator	-- 登陆号码校验组件
│  │                  └─vo			-- 返回视图整合处理
│  └─resources
│      ├─static
│      │  ├─bootstrap
│      │  │  ├─css
│      │  │  ├─fonts
│      │  │  └─js
│      │  ├─img		--图片资源
│      │  ├─jquery-validation
│      │  │  └─localization
│      │  ├─js
│      │  └─layer
│      │      ├─mobile
│      │      │  └─need
│      │      └─skin
│      │          └─default
│      └─templates	-- 存放Thymeleaf模板引擎所需的HTML
└─test
    └─java	-- 测试文件

具体技术栈

  • 前端:JQuery+Bootstrap+Thymeleaf

  • 后端:SpringBoot-2.1.4+JSR303服务端验证框架+MyBatis

  • 中间件:RabbitMQ+Redis+Druid

项目搭建环境

  • IDEA+Maven+Tomcat+JDK8+Windows10

如何启动

  1. 直接将last version文件导入IDEA即可,Maven提示选择自动导入依赖。
  2. 启动前请根据本地环境配置好application.properties中的数据库,Redis,Rabbit相关配置 (eg:地址,端口号)。
  3. 启动前请先创建seckill数据库,数据库建表语句放在:/mysql/seckill_sql.sql文件内。运行前务必先在插入秒杀用户信息商品信息秒杀商品信息秒杀开始结束时间(…因为目前还没有做注册功能)。:busts_in_silhouette:
  4. 以上3步做好后,运行src/main/java/com/github/soyanga/secondskillsystem下的/MainApplication.java中的main方法访问http://localhost:8080/login/to_login即可进入登陆页面。
  5. 本项目运行环境默认是在windows下的,如需部署到服务器上则根据实际情况自行配置相关参数。:yum:

秒杀系统优化

秒杀功能基本实现后使用JMeter对项目进行了压测,发现qps并不是很理想,且出现了超买。

根据项目分析发现性能瓶颈主要是在数据库上,所有秒杀请都会访问数据库,数据库并不能承受这么高的并发量,我适当调节了数据库连接池Druid的参数,并没有对性能上有太多的提升。所以如下分别从页面,秒杀接口上入手,减少对数据库的访问。并且对系统安全上进行了优化

页面优化:

  1. 页面缓存+URL缓存+对象缓存
  2. 页面静态化,前后端分离
  3. 静态资源的优化(图片 CSS,JS)
    • JS/CSS压缩,减少流量(项目中并未具体实现,只是利用了SpringBoot.resources)
    • 多个JS/CSS组合一个请求,减少连接数(并未具体实现)
  • CDN优化
    • CDN服务器就近访问,服务器轮询(可以进一步优化的点)

秒杀接口优化:

  1. Redis预减库存减少数据库访问
  2. 内存标记减少Redis访问
  3. RabbitMQ队列缓冲,异步下单,增强用户体验
  • Nginx水平扩展(没有实施环境,只是概念层假设)
  • LVS

安全优化:

  1. 秒杀接口地址隐藏
  2. 数学公式的验证码 (削峰)
  3. 接口防刷 类似限流

解决超买

  1. 数据库加唯一索引:防止用户重复购买(添加事务,数据库添加失败就回滚并不会创建订单)
  2. SQL加库存数量判断:防止库存变成负数

项目执行流程

ProjectPresentations3

项目详细搭建过程,具体技术实现(…正在整理完善 :happy:)

我的博客

clicking's People

Contributors

soyanga avatar

Stargazers

 avatar 小小少年 avatar  avatar  avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.