当前位置:网站首页>缓存读写--写
缓存读写--写
2022-06-13 03:41:00 【喵叔哟】
在上一篇文章中我们讨论了缓存架构方案,使用这个架构方案可以减轻读数据库的压力,但是这个方案在大量并发写操作的情况下会造成数据库性能降低。那么这篇文章我将讲解一下如何处理大量并发写的问题。
一、案例
在一个电商系统中,我们要增加一个预约功能,用户可以在指定的时间段内对商品进行购买预约。预约功能和其他功能不一样的地方是,预约功能会出现短时间内大量并发写的情况,很有可能造成数据库和服务器崩溃,对于服务器来说我们可以增加服务器数量,但是对于数据库来说简单的增加数据库数量是不够的。一定有人会说使用分表分库啊,这个方案确实不错,但是预约功能并不是每天都有的,这么做又有些大材小用。因此在这里我推荐使用缓存层(又称写缓存)作为解决大量并发写的方案。每个预约请求经过校验后将先将数据存放在高性能的缓存中,这样大量的写操作会首先冲击缓存层,当缓存层中的数据达到某个阈值的时候再将其中的数据批量落库。(这里的缓存层大部分情况优会使用NoSQL来实现)优点是利用缓存的高吞吐能力来承受洪峰流量。
二、思路
写缓存需要考虑五个问题:
- 写请求和批量落库是同步操作还是异步操作;
- 落库如何触发;
- 如何存储缓存数据;
- 并发操作缓存层应注意哪些问题;
- 批量落库失败了怎么处理。
2.1 异步还是同步
2.1.1 . 同步
写请求提交数据后,当前写操作线程会等到批量落库完成后才返回结果给用户。优点是用户预约成功后,可以在预约页面马上看到自己预约的信息,缺点是用户在提交预约请求后需要等待一段时间&#x
边栏推荐
- Install cnpm and use cnpm command in vscode terminal
- Simulink code generation: table lookup module and its code
- 【测试开发】博客系统——Loadrunner性能测试(发布博客功能 基准测试)
- Lambda终结操作查找与匹配noneMatch
- 机器人避障系统基础
- 【MySQL】索引与事务
- Pollution discharge fees of listed companies 2010-2020 & environmental disclosure level of heavy pollution industry - original data and calculation results
- The latest collation of the number of years of education per capita in the country and provinces -1989-2020- includes the annual original data, calculation process and result summary
- Oracle database management
- Byte stream & buffer stream
猜你喜欢

LVS四层负载均衡集群(5)LVS概述

Wechat payment configuration

Very simple installation and configuration of nodejs

LVS四層負載均衡集群(5)LVS概述

UDP connection map collection

Install cnpm and use cnpm command in vscode terminal
![[test development] automatic test selenium (I)](/img/cd/b6dc4ac53b4f30f745ec0590ac384b.png)
[test development] automatic test selenium (I)

Spark optimization - data skew solution

LVS four layer load balancing cluster (4) main methods of load balancing

2000-2019 enterprise registration data of all provinces, cities and counties in China (including longitude and latitude, registration number and other multi indicator information)
随机推荐
Alibaba cloud keep on record
大疆无人机飞控系统的原理、组成及各传感器的作用
测试写入mysql数据300W条,每次1.6-2W之间就断掉然后出现以下问题:
单片机:A/D 差分输入信号
300W pieces of MySQL data were written in the test, and they were broken between 1.6 and 2W each time. Then the following problems occurred:
[multithreading] what is multithreading in the end -- the elementary level of multithreading (review for self use)
Doris' table creation and data division
Stream流的注意事项
Prefecture level city - air flow coefficient data - updated to 2019 (including 10m wind speed, boundary height, etc.)
[200 opencv routines by youcans] 201 Color space conversion of images
Serialization & deserialization
【测试开发】软件测试基础篇
【MySQL】索引与事务
四旋翼飞行器避障系统基础
Database object, sequence, view, index
Spark optimization - Performance (general performance, operator, shuffle, JVM) tuning
Very simple installation and configuration of nodejs
LVS四層負載均衡集群(3)集群功能分類 - HPC
Complete set of Stata code commands: follow and verify do files, common Stata commands, code collection, panel entropy method
LVS四層負載均衡集群(5)LVS概述