云原生、微服务和 Serverless

云原生、微服务和 Serverless

2025 南京大学《操作系统原理》
云原生、微服务和 Serverless

舞台已经搭好了……

我们有容器 (虚拟机) 了

  • 本来虚拟机里也是 HTTP Server (httpd)
  • 干脆把程序拆成 Microservices?
    • Cloud Native: 云会负责容器管理、API Gateway、负载均衡……

center

2025 南京大学《操作系统原理》
云原生、微服务和 Serverless

Serverless: “容器” 的概念都可以不要了

center

  • 你只需要实现 int foo() {}
  • 剩下的都交给云厂商
    • 黑心商人:都不需要 oversubscribe 了,直接按量计费,最大程度榨干机器性能
2025 南京大学《操作系统原理》
云原生、微服务和 Serverless

Function-as-a-Service (FaaS)

Remote Procedure Call (RPC) 调用远程函数

  • apt install ffmpeg; ffmpeg -i a.mp4 -f ffmetadata -
def get_media_data(object_key):
    client = fc2.Client(
        endpoint="https://<id>.cn-hangzhou.fc.aliyuncs.com",
        accessKeyID="xxxxxxxx", accessKeySecret="yyyyyy"
    )

    return client.invoke_function(
        "FcOssFFmpeg",
        "GetMediaMeta",
        payload=json.dumps({
            "bucket_name": "test-bucket",
            "object_key": object_key
        })).data

get_media_data('/object/key/to/a.mp4')
2025 南京大学《操作系统原理》
云原生、微服务和 Serverless

再加上 CI/CD

center

  • 你只需要 git push,剩下都是自动的
    • 例子:ics.nju.edu.cn;git push 会触发 http 请求 hook (X-Gitlab-Token 的 header),服务器就获得控制权了
    • 本地测试好,git push 等一等,应用就上线了
2025 南京大学《操作系统原理》
云原生、微服务和 Serverless

“计算机” 会消失吗?

只需要云和终端?

response = OpenAI().responses.create(
    model="gpt-4.1-mini",
    input="Generate an image of ...",
    tools=[{"type": "image_generation"}],
)

image_data = [
    output.result for output in response.output
    if output.type == "image_generation_call"]

if image_data:
    image_base64 = image_data[0]
    with open("cat_and_otter.png", "wb") as f:
        f.write(base64.b64decode(image_base64))
  • “AI inference” 占程序运行时长的比例会越来越高吗?
2025 南京大学《操作系统原理》