Solving SSH Lag Through Proxy: A Complete Guide to SSH on Port 443

解决代理环境下的 SSH 卡顿:SSH over 443 端口完全指南 问题描述 从内地 SSH 连接到香港的云服务器时,出现严重的卡顿现象: 输入延迟明显,每个字符都有停顿 但通过服务商提供的 noVNC Console(Web 终端)却非常流畅 明明都是连接同一台香港服务器,为什么体验差距如此之大? 环境信息 本地位置: 大陆 服务器位置: 香港(IP: <hk-server-ip>) 代理工具: Clash Verge(有香港代理节点) 操作系统: macOS 问题诊断 第一步:基础网络测试 首先测试直连服务器的网络质量: # 测试延迟和丢包率 ping -c 20 <hk-server-ip> # 结果: # - 平均延迟:170-180ms # - 丢包率:4% # - 延迟抖动:标准差 5-7ms 分析:对于大陆到香港的连接,这个延迟和丢包率虽然不理想,但也算"正常的糟糕"。真正的问题是:为什么 noVNC 不卡,而 SSH 卡? 第二步:路由追踪 traceroute -I <hk-server-ip> # 结果显示只有1跳就到达目标 # 这说明中间路由器没有响应 ICMP,无法看到完整路径 第三步:IP 归属查询 curl -s "http://ip-api.com/json/<hk-server-ip>" # 服务器:香港,ISP: Lucidacloud Limited curl -s ifconfig.me # 本地公网 IP 显示:香港,ISP: Nearoute Limited 关键发现:本地公网 IP 显示为香港,但我人在大陆!这说明当前网络已经走了 Clash 代理。 ...

November 10, 2025 · 4 min · 641 words · Starslayerx

Fastapi Lifespan Events

Lifespan Events 生命周期事件 通过生命周期事件可以定义在应用开启之前需要执行的代码,这意味着这些代码会在开始接收外部请求之前被执行一次。 同样地,也可以定义应用在关闭的时候定义需要执行的代码,在尽力处理完所有请求后,该代码会被执行一次。 这对于设置需要在整个 app 的请求间共享的资源时非常有用,或者是需要进行清理工作的时候。 例如,一个数据库连接池,或者加载一个共享的机器学习模型。 Use Case 使用示例 下面通过一个例子说明如何使用。 假如你有一个机器学习模型,并且需要让其处理请求,由于请求都共享同一个模型,因此不是一个请求对应一个模型,或一个用户一个模型。 假设模型加载需要一定的时间,因为要从磁盘中读取大量的数据,因此不能每个请求都去加载一次。 你可以在顶层的模块文件中定义加载,但这意味着当进行简单的自动化测试的时候,也会加载该模型,这样就会很慢。 这就是需要解决的问题,需要在请求响应之前加载模型,也不是在代码被加载的时候加载模型。 Lifespan 生命周期 可以通过在 FastAPI app 中使用 lifespan 参数来定义启动和关闭逻辑,以及一个 “context manager” (上下文管理器)。 通过下面这种方法创建一个含 yield 的 function from contextlib import asynccontextmanager from fastapi impor FastAPI def fake_answer_to_everything_ml_model(x: float): return x * 42 ml_models = {} @asynccontextmanager async def lifespan(app: FastAPI): # Load the ML model ml_models["answer_to_everything"] = fake_answer_to_everything_ml_model yield # Clean up the ML models and release the resources ml_models.clear() app = FastAPI(lifespan=lifespan) @app.get("/predict") async def predict(x: float): result = ml_models["answer_to_everything"](x) return {"result": result} 这里在生成器 yield 之前将模拟的昂贵函数放入机器学习字典中。 这段代码将在应用程序接收请求之前执行,即启动阶段。 ...

October 24, 2025 · 2 min · 245 words · Starslayerx

Understanding SVG Paths

Overview 如果你曾经看过一个 icon 的 SVG 代码,你可能会注意到他们通常是有一个 <path> 元素和一个神秘的 d 属性实现的。 你可能以为他们不过是设计师最喜欢的矢量图形编辑器的输出,虽然可能是正确的,但有些过度简化了。 理解这个属性的内部运作机制将是前端技能的一大助力,它让你能够做到以前从未想过的事情,比如制作弯曲的动画。 这份指南将会谈到 d 属性,也被称为 path data。 A Path is a Series of Commands 路径是一系列命令 d 属性实际上是一系列命令,告诉浏览器如何绘制 path,如果将属性内容规范一下,将会是下面这样: M 12.0 7.2 C 10.5 5.6 8.1 5.2 6.3 6.7 C 4.5 8.1 4.2 10.6 5.7 12.4 L 12.0 18.3 L 18.3 12.4 C 19.7 10.6 19.5 8.1 17.7 6.7 C 15.8 5.2 13.4 5.6 12.0 7.2 Z 为了绘制出 path,浏览器按照顺序执行这些命令,每个命令绘制一小部分。 所有的 path 命令都遵循同样的语法,单个字母 + 一系列数字,字母代表命令类型,二数字则是命令的参数。 ...

October 22, 2025 · 8 min · 1618 words · Starslayerx

Fastapi Background Tasks

Background Tasks 后台任务 你可以定义一个在返回响应之后运行的后台任务。 这对请求之后执行一些操作十分有用,客户端无需一直等待操作任务完成再接收响应。 这包含一些例子: 执行操作后发送电子邮件 由于连接邮件服务器并发送邮件一般会比较“慢”(几秒钟),你可以立刻返回响应并在后台发送邮件请求。 处理数据 例如,你收到了一个文件需要缓慢处理,你可以返回一个 “Accepted” 响应 (HTTP 202) 并在后台处理文件。 Using Background Tasks 使用后台任务 首先要导入 BackgroundTasks 并在执行函数中定义一个路径参数,使用 BackgroundTasks 类型声明。 from fastapi import BackgroundTasks, FastAPI app = FastAPI() def write_notification(email: str, message=""): with open("log.txt", mode="w") as email_file: content = f"notification for {email}: {message}" email_file.write(content) @app.post("/send-notification/{email}") async def send_notification(email: str, backgroud_tasks: Background(Tasks): # Add parameter here background_tasks.add_task(write_notification, email, message="some notification") # add backgroud task here return {"message": "Notification sent in the background"} Create a task function 创建任务函数 创建一个函数放到后台运行,只是一个接收参数的基本函数,可以是 async def 或者就普通的 def 函数,FastAPI 会正确的处理它。 在这个例子中的任务函数将会编写文件,并且写入操作不使用 async 或 await 故使用 def 定义了一个基本的函数。 ...

October 10, 2025 · 2 min · 261 words · Starslayerx

Fastapi Middleware

Middleware 你可以添加中间件到 FastAPI 应用中。 “中间件” 是一个函数,它在每个请求被特定路径操作之前对其进行处理,同时在每个响应返回之前也对其进行处理。 在到达应用程序之前处理请求 可以在请求中做一些事情,或运行任何需要的代码 将处理后的请求传递给应用程序 之后处理应用程序返回的响应 可以对响应做一些事情,或运行任何需要的代码 然后返回响应 Create a Middleware 创建一个中间件 想要创建一个中间件,你可以在函数上面使用装饰器 @app.middleware("http"),该函数接受: request 请求 一个函数 call_next 并将会接收 request 作为一个参数 该函数会将 request 传递给对应的路径操作 然后返回对应路由操作生成的 response 你可以修改或者直接返回 response import time from fastapi import FastAPI, Request app = FastAPI() @app.middleware("http") async def add_process_time_header(request: Request, call_next): ... TIP 自定义专属 headers 可以使用 X-prefix 来添加。 但如果你有一个自定义的 header 并想要客户端能够看到这些信息,你需要使用 Starlette’s CORS docs 中的参数参数 expose_headers 将其加入你的 CORS 设置里 (CORS (Corss-Origin Resource Sharing))。 Before and after the response 在响应前后 你也可以在 request 前后运行代码,也可以在 response 前后运行代码。 ...

October 9, 2025 · 1 min · 164 words · Starslayerx

Docker - Containers

像 VMware 或 KVM 这类虚拟化系统, 他们运行在虚拟化层上运行完整的 Linux 内核与操作系统. 这种架构能提供极强的隔离性, 因为每个虚拟机都搭载独立的内核, 这些内核各自运行在硬甲虚拟化层之上的隔离内存空间中. 而容器技术有着根本性差异, 所有容器共享同一个内核, 工作负载间的隔离性全通过内核机制实现, 这种模式被称为操作系统级虚拟化 operating system virtualization. runc/libcontainer 提供了一个很好的定义: A container is a self-contained execution environment that shares the kernel of the host system and is isolated from other containers in the system. 容器最大的优势就在于性能, 当运行一个进程的时候, 只有小部分的代码在内核中用于管理容器. 如今, 容器几乎在任何地方运行. Docker 和 OCI 镜像提供了生成环境中软件的打包格式, 并为 Kubernetes 和大多数 “serverless” 云技术打下了基础. 所谓的 serverless 技术并不是真的没有服务器: 它们依赖其他人的服务器来完成工作, 这样应用开发者就无需关心管理硬甲和操作系统了. Creating a Container 创建容器的命令 docker container run 实际上是包装在一起的两条命令. 第一件事是从基本的镜像中创建一个容器, 可以通过 docker container create 命令实现. 第二件事是执行容器, 同样地, 可以通过 docker container start 命令实现. ...

September 23, 2025 · 9 min · 1877 words · Starslayerx

uv - Python package manager

这篇文章深入介绍 uv 管理 Python 项目的使用 Features Python versions uv python install: 安装 Python 版本 uv python list: 查看可用的 Python 版本 uv python find: 查找安装的 Python 版本 uv python pin: 固定当前项目的 Python 版本 uv python uninstall: 卸载一个 Python 版本 Scripts uv run: 运行一个脚本 uv add --script: 为脚本添加一个依赖 uv remove --script: 移除一个依赖 Projects 使用 pyproject.toml 配置项目 uv init: 创建一个 Python 项目 uv add: 为项目添加依赖 uv remove: 删除项目依赖 uv sync: 同步环境下的依赖 uv lock: 为项目依赖创建一个锁文件 uv run: 在项目环境执行命令 uv tree: 查看项目依赖树 uv build: 将项目构建为分发归档文件 uv publish: 将项目发布到包索引 Tools 允许与安装工具 ...

September 22, 2025 · 11 min · 2131 words · Starslayerx

English for Programmers - 03

Unit 3. Discussing Code vocabulary - Modifiers When discussing code, modifiers can be extremely useful for making your feedback constructive and precise. modifiers: words that change the meaning of a sentence For example, a colleague asks: What do you think of the website? Response 1: It’s good When I click something it loads very quickly and I can navigate it easyily without any instructions. Response 2: It’s good! It’s very responsive and can be navigated intuitively. ...

September 20, 2025 · 2 min · 390 words · Starslayerx

English for Programmers - 02

Unit 2. Code Review & Testing this unit will cover: Differentiate between various testing strategies Write professional guidelines Sound more natural and smooth when asking questions Use colloquial language in speaking to give and accept feedback vocabulary - None Pharses 词汇: 名词短语 Testing 测试是软件开发中的重要短语, 用于检查软件是否达到特定的标准和用户需求. 使用这些名词语句来证明英语名词的专业性: None Desciption Example time box an allocated period of time for completing a task - allcate a 2-hour time box for regression testing stress test a method to assess a system’s performance under heavy loads - simulate 1000 users accessing the login page at the same time sanity check 健全性测试 a quick check to verify that something is as expected - are the units of the output value correct? ad hoc test 临时测试 a test performed without predefined test cases or plans - input unexpected characters into a search bar edge case a problem that only happens in extreme situations - upload an empty, 0-byte file 一些名词短语也可以当作动词使用: ...

September 12, 2025 · 4 min · 777 words · Starslayerx

English for Programmers - 01

Unit 1. Implementing Code This unit will cover: Use technical verbs to accurately define tasks and actoins Write commit messages in the corret Git format Confidently name the symbols used when writing code Understand vocabulary for syntax and programming rule vocaluary - action verbs 动词词汇 He optimised the queries to improve the response time. optimised: 提高 (improved) Can you implement the new feature we discussed yesterday? implement: 实现 (put int action) The team will integrate a third-party API to get real-time data. ...

September 11, 2025 · 3 min · 553 words · Starslayerx