BytePower 技术周刊 - 028

2022-11-17

# BytePower 技术周刊 - 028

# 📘 封面


詹姆斯·韦伯太空望远镜捕捉到了圆柱形星际气体和尘埃构成的天体景象“创生之柱”的详细图像。“创生之柱”位于距地球约 6500 光年的鹰状星云内,曾在 1995 年被哈勃望远镜捕获,而此次发布的新图像揭示了天体景象的新细节,天体生物学家称其“壮观得无法形容”。

# 📖 文章

# Long-lived TCP connections and Load Balancers (opens new window) (英文)

There are a bunch of solutions to this problem but I'm only going to talk about a few obvious ones.

The simplest solution is to make the connections not be long lived. If we opened a new connection for each request we wouldn't have this problem. Performance would be worse, though how much worse depends on what constitutes a request. But we don't have to make that dramatic a change to fix our problem. Rather than making each request use a separate connection we could reuse the connection for some period of time or number of requests and then tear it down. When the second server comes online it won't get traffic immediately but over time the law of large numbers will kick in and cause load to balance out automatically. For example allowing connections to live for no longer than 10 minutes means that about 10 minutes after you bring the second server online the load should be back to being balanced. of course the more connections you have the truer this example is!

Another solution to the problem is to have the Load Balancer intervene to force the connections to rebalance. Some load balancers allow you to configure the load balancer to poll the servers. When a server comes online the load balancer will become aware of that and it could forcibly reset some of the existing connections by sending a TCP RST packet to the client. The client will then know that that one connection has gone "bad" and it can open new connections to the server. This solution is much more intrusive than the first one - it requires the load balancer to preemptively monitor the servers and to figure out which existing connections to terminate. To do this correctly the load balancer may need to understand the wire protocol - a server might be listening on the TCP socket and be able to accept the connection but the software could be hung. As a result I tend to toss this solution into the "too smart by half" pile.

A third solution is also intrusive, but the intrusion happens inside the protocol. The problems above stem from the fact that the client doesn't know that there are multiple servers behind the load balancer, it doesn't know which connections go to which server, and it doesn't know which servers are online. If we just tweak the protocol so that the initial handshake says "hello client, I'm 'server X', nice to meet you" the client will have half of what it needs. Add a "which servers are in the cluster and what is their state" that the client can call every once in a while and you've neatly solved the problem. With those two bits of info the client has everything it needs to deal with problems, detect imbalances, and rebalance when servers go offline or come online. Of course we've added even more complexity to solve the problem, so again probably too smart by half!

# 利用 NotionNext 快速部署博客系统 (opens new window)(中文)

NotionNext 将您的 Notion 笔记渲染成静态博客、托管在 Vercel 云服务中。与 Hexo 静态博客相比较不同的是,NotionNext 会自动同步您的笔记至博客站点,而无需每次写好文章都要推送到 Github。

所有的博文和页面的编写及发布都只在您的 Notion 笔记中完成。依托于 Notion 强大的编辑功能,您可以随时随地撰写文章、记录创意与灵感。

NotionNext 是基于 craigary 的 Nobelium 项目二次开发,继承了 Nobelium 功能特点,例如快速秒开、设备全配适等。

# 你只会用前端数据埋点 SDK 吗? (opens new window)(中文)

相信不少人因为项目中没有接触过数据埋点相关的内容,而没有花时间去了解它,总觉得这又是一个自己还不能涉及的方面,然而数据埋点本身并不难理解,只是很难做得好,本文会从 认识数据埋点 SDK、设计前端数据埋点 SDK 两个核心方面来展开,聊聊前端数据埋点的那些事。

# 耗时一年半才出第一版,这个工具会一统前端么? (opens new window)(中文)

# 前端项目中常用的一些工具,比如:

  • 代码格式化工具:Prettier、dprint
  • lint 工具:ESLint、StyleLint
  • 测试工具:Vitest、jest
  • 编译器:babel、SWC
  • 打包工具:webpack、vite、rollup

要熟练使用他们并不容易,因为:需要了解不同工具如何配置;需要考虑如何将这些工具整合到项目中。最终,项目中往往充斥着各种各样的配置文件。以至于复杂的项目中通常有个特殊的职位 —— webpack 配置工程师。

# macOS Ventura 正式版来了,升级之后试试这些新变化 (opens new window)(中文)

# 台前调度

作为 macOS Ventura 最大的功能更新之一,台前调度的加入无疑让我们的工作效率大大提升。你只需要在控制中心轻点台前调度图标,macOS 会帮你把所有打开的 app 自动整理成单一视图,让你可以专注在当前进行的工作中。

# Golang 多版本管理 (opens new window)(中文)

虽然感觉一般用不到,但是 go 也有类似 node 的多版本管理工具。

# 🧰 工具

# wails (opens new window)

使用 Go + HTML + CSS + JS 构建漂亮的跨平台桌面应用。

# Typedown - A WYSIWYG Markdown Editor (opens new window)

一个 Windows 系统上所见即所得的 Markdown 编辑器,有望替代 Typora。

# askcommand (opens new window)

A tiny app to remind you about those commands you always forget. Powered by AI.

# outline (opens new window)

一款适用于个人或团队的文档(wiki)软件,支持私有化部署。

# This Wallpaper Does NOT Exist (opens new window)

由 AI 生成的壁纸。

# ❓ 为什么

# 为什么很多人觉得星座很准? (opens new window)(中文)

巴纳姆效应:巴纳姆效应又称为星相效应,指的是一种心理学现象,即每个人都很容易相信一个笼统的、一般性的性格描述,十分准确地揭示了自己的特点。

心理学家曾经做过一个实验,他给一群人做完一种多项人格检查表后,拿出两份结果让参加者判断哪一份是自己的结果。事实上,一份是参加者的结果,另一份只是一个平均值的结果。参加者竟然认为后者更准确地表达了自己的人格特征。这就说明,即使这种描述十分空洞,一旦用一段笼统的、几乎适用于任何人的话来描述,那么会让绝大多数人认为这段话将自己刻画得细致入微、准确至极。

上次更新: 2022-11-17 16:00:55