当前位置:网站首页>面试官:如何处理高并发?
面试官:如何处理高并发?
2022-07-26 11:47:00 【用户9919783】
昨天跟高中同学聊天,大厂需要高并发经验进不去,只能进小作坊,小作坊里又不需要处理高并发,如此死循环。高并发的经验,在面试场景里永远不会过时,有着举足轻重的作用,秒杀场景流量削峰就是高并发之一。
什么是高并发?
高并发指在同一个时间点,大量的客户请求,访问服务器,update的修改数据库数据,这时候update会锁表,等待执行完毕才能处理下一个请求,当客户请求累计到一定数量,超过数据库链接限制,则会返回链接超时,也会因为请求过多,同一条数据添加两次,不能保证数据的一致性。高并发请求核心要素则是必须保证大量请求高可用,一致性,高性能。从上面可以看出,保证系统的稳定性,可以减少直接对DB层数据的请求更新。
如何保证高性能呢?
客户层可以采用用户答题和输入验证码等方法,限制请求次数,防止0点秒杀的时刻,峰值全部集中在一起,这样最主要是可以防止有人作弊秒杀,而且也可以延缓客户请求,吧请求分布在不同的时间段。
业务层可以限制接口的调用次数。
也可以采用流量削峰来实现,如今已经有大量优秀的开源框架支撑流量削峰功能,如RabbitMq和kafka等。RabbitMq的消息队列除了有解耦和异步的功能外,还可以实现流量削峰,将大量用户请求先存储在mq队列中,之后就可以分摊在其他时间段进入数据库。
如何保证一致性?
当消费仓库存货时,可以在每次消费之前,判断一次count>0,当有存货的时候,才能继续消费执行,否则回滚。
如何实现高可用?
最后,为了保证服务器的高可用,肯定是需要部署在多个服务器上保证其中一个宕机,系统还能正常运行。
服务降级
当请求到达系统承受能力,可以对其他不核心的功能先关闭,尽可能吧系统内存全部给秒杀功能,保证秒杀的正常运行。
服务限流
限流是接口的访问请求进行限流,也可以用rabbitmq进行限流,mq会对队列进行排队限流,一旦超过过期时间,则会丢弃,客户端快速失败进行第二轮重试。
拒绝请求
当服务降级和服务限流不能解决的情况下,最后就只能返回一个错误页面给用户,比如“用户请求过多”“服务繁忙,稍后再试”等,只会发生在服务器过载时候启用,只会存在短暂不可用情况,一旦正常运行的服务器负载降下来,则可以正常请求。
边栏推荐
- pytest接口自动化测试框架 | 重新运行失败用例
- pytest接口自动化测试框架 | fixture调用fixture
- 网络协议:TCP/IP协议
- Didi was fined 8billion! The era of making money from user data is over
- Esp8266 Arduino programming example - development environment construction (based on Arduino IDE)
- Hashtable
- Esp8266 Arduino programming example - know esp8266
- Yuancosmos daily | yuancosmos social app "Party Island" product off the shelves; Guangzhou Nansha yuanuniverse industrial agglomeration zone was unveiled; The inter ministerial joint conference system
- Cohere博客:在生产环境中运行大型语言模型-推理框架概览
- 开放原子开源基金会OpenHarmony工作委员会主席侯培新寄语OpenAtom OpenHarmony分论坛
猜你喜欢

Exploration on cache design optimization of community like business

最新心形拼图小程序源码+带流量主

PyCharm是真的强

4.1 配置Mysql与注册登录模块

Redis database, which can be understood by zero foundation Xiaobai, is easy to learn and use!

Outsourcing for four years, abandoned

系统调用捕获和分—Ring3层LD_PRELOAD机制进行库函数劫持

【附下载】一款强大的Web自动化漏洞扫描工具——Xray

3.1 create menu and game page - up

Live broadcast preview at 19:30 on July 27: harmonyos3 and Huawei's full scene new product launch
随机推荐
pytest接口自动化测试框架 | fixture调用fixture
Miccai2022 paper | evolutionary multi-objective architecture search framework: application in covid-19 3D CT classification
An online duplicate of a hidden bug
【附下载】一款强大的Web自动化漏洞扫描工具——Xray
System call capture and analysis conclusion making system call log collection system
Pytest interface automation test framework | rerun failed cases
Application scheme of ankerui residual pressure monitoring system in residential quarter
How did the $50000 annual salary run out
Win10 uses NVM to install node, NPM, and cnpm
Who is responsible for the problems of virtual idol endorsement products? And listen to the lawyer's analysis
X 2 earn must rely on Ponzi startup? Where is the way out for gamefi? (top)
零基础小白也能懂的 Redis 数据库,手把手教你易学易用!
Fineos announced the open registration of grouptech connect activities in 2022
MICCAI2022论文 | 进化多目标架构搜索框架:在COVID-19三维CT分类中的应用
大佬们,cdc oracle 怎么设置从指定scn号开始读取,或是怎么设置只读全量的归档,不去读取快
Recalling Sister Feng
Meiker Studio - Huawei 14 day Hongmeng equipment development practical notes 8
Pycharm is really strong
PostgreSQL in Linux and windows installation and introductory basic tutorial
Pytest interface automated test framework | fixture call fixture