Skip to Content
Node与Express开发(第2版)
book

Node与Express开发(第2版)

by Ethan Brown
June 2021
Intermediate to advanced
290 pages
9h 21m
Chinese
Posts & Telecom Press
Content preview from Node与Express开发(第2版)
考虑生产环境中的问题
|
119
那样把获胜者都写入一个文件里。一旦文件已经记录了
50
个获胜者,就不能再增加了。
但问题在于,服务器做了负载均衡,因此有一半的请求会被其中一台服务器处理,另一半
则会被另一台服务器处理。结果就是这台服务器通知了
50
个
人说他们获胜了,而另一台
也通知了
50
个人…
…不过好在这些奖品价值不高,不是
iPad
之类的贵重物品。客户也欣
然当了冤大头,拿出了
100
份而不是
50
份奖品
(我提出要自掏腰包为多出的
50
条毯子买
单,但他们大度地拒绝了)。
我从这次经历中得到的教训是,除非你有一个
所有
服务器都能访问的文件系统,否则不应
该依靠本地文件系统来实现持久化。不过,只读数据(比如日志和备份)是个例外。例
如,我就经常把表单提交数据备份到本地文件,以防数据库连接失败。毕竟,当数据库中
断时,要从每一台服务器收集这些文件是很麻烦的,至少这样做不会有什么损失。
12.4.1
 使用应用集群实现水平扩展
Node
本身支持
应用集群
,这是一种简单的、单服务器的水平扩展形式。使用应用集群,你
可以为机器的每个核心(
CPU
)创建一个独立的应用服务器实例
(服务器实例超过核心数
并不会提升应用的性能)。应用集群有两大好处:首先,它有助于最大化给定服务器(实
体机器或虚拟机器)的性能;其次,这是在并行条件下测试应用的低成本方式。
现在给我们的网站增加集群支持。尽管我们通常在主应用文件里完成所有工作,还是要创
建第二个应用文件,它将使用之前一直使用的非集群应用文件在集群中运行应用。为此,
需要先对
meadowlark.js ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua

Publisher Resources

ISBN: 9787115565099