V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iwdmb
V2EX  ›  程序员

Azure CTO 认为应以 Rust 代替 C/C++

  •  
  •   iwdmb · 2022-09-26 19:37:55 +08:00 · 5290 次点击
    这是一个创建于 550 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Mark Russinovich's Twitter:

    Speaking of languages, it's time to halt starting any new projects in C/C++ and use Rust for those scenarios where a non-GC language is required. For the sake of security and reliability. the industry should declare those languages as deprecated.

    机翻

    说到语言,是时候停止在 C/C++ 中启动任何新项目,并将 Rust 用于需要非 GC 语言的场景。为了安全性和可靠性。业界应声明这些语言已弃用。

    https://twitter.com/markrussinovich/status/1571995117233504257

    39 条回复    2022-09-27 22:59:16 +08:00
    iwdmb
        1
    iwdmb  
    OP
       2022-09-26 19:38:53 +08:00
    AWS/Azure 陆续推广、Linux Kernel 6.1 加入 Rust
    Rust 的春天要来了吗
    233373
        2
    233373  
       2022-09-26 19:39:58 +08:00
    春去春又來
    iwdmb
        3
    iwdmb  
    OP
       2022-09-26 19:45:58 +08:00   ❤️ 2
    备注
    Mark Russinovich 是 Windows Internals (深入解析 Windows 操作系统) 的作者
    chenqh
        4
    chenqh  
       2022-09-26 19:53:44 +08:00
    关键词,新项目,非 GC 语言
    Jirajine
        5
    Jirajine  
       2022-09-26 20:02:23 +08:00
    说的虽然没错,但 Rust 也不是写什么都适合,可以接受 GC 且不想用开放速度换取软件质量的场景最好不要用 Rust (当然以上场景 C/Cpp 通常更痛苦),尤其是涉及 async ,async Rust 为了零开销抽象付出的代价太大了,任何可以接受开销的场景下基本都不适合。
    Nugine0
        6
    Nugine0  
       2022-09-26 20:31:55 +08:00   ❤️ 9
    Cloudflare 将 Nginx 替换为用 Rust 编写的 http 代理服务 Pingora ,将 CPU 和内存消耗分别减少了约 70% 和 67%。Pingora 自部署以来已处理了数百万亿个请求,从未因为本身代码而崩溃。

    https://blog.cloudflare.com/how-we-built-pingora-the-proxy-that-connects-cloudflare-to-the-internet/
    sardina
        7
    sardina  
       2022-09-26 20:42:54 +08:00 via iPhone   ❤️ 1
    风口来了
    des
        8
    des  
       2022-09-26 20:51:33 +08:00 via iPhone
    @Nugine0 据说要开源,不知道什么时候
    Nugine0
        9
    Nugine0  
       2022-09-26 21:03:53 +08:00 via Android
    国内首个基于 Rust 语言的 RPC 框架 — Volo 正式开源!

    https://mp.weixin.qq.com/s/XcceLyKxWOVtoMIJBuwXWQ

    Volo 是字节跳动服务框架团队研发的轻量级、高性能、可扩展性强、易用性好的 Rust RPC 框架,使用了 Rust 最新的 GAT 和 TAIT 特性。

    在字节内部,Volo 已经落地多个业务和基础组件,并且取得了超预期的性能收益(与 Go 版本对比,不那么公平)。

    ……
    paoqi2048
        10
    paoqi2048  
       2022-09-26 21:06:36 +08:00
    国内国外两个样
    tool2d
        11
    tool2d  
       2022-09-26 21:57:35 +08:00   ❤️ 2
    不太可能,传统 C++历史工程都是几百万行,怎么转啊。

    新项目可替代的备用语言太多,又何必选 Rust 。
    Kasumi20
        12
    Kasumi20  
       2022-09-26 22:28:22 +08:00   ❤️ 3
    Rust 真的太香啦! 用 Rust 写的程序自带安慰剂和兴奋剂
    Osk
        13
    Osk  
       2022-09-26 22:54:43 +08:00
    Mark 大佬都这么说, 得赶紧学学了...


    他的 sysinternal 工具救我于水火
    dbskcnc
        14
    dbskcnc  
       2022-09-26 23:01:15 +08:00 via Android
    @Nugine0 实际情况是用长连接替代 nginx 的短连接, 语言在此作用其实不大
    shijingshijing
        15
    shijingshijing  
       2022-09-26 23:30:34 +08:00
    @Kasumi20 笑死,一刀 999
    mirrorman
        16
    mirrorman  
       2022-09-26 23:36:21 +08:00   ❤️ 1
    @Nugine0 这不是仅仅换了个语言这么简单,架构都变了没得可比性
    Nugine0
        17
    Nugine0  
       2022-09-26 23:56:06 +08:00
    @dbskcnc
    @mirrorman

    Cloudflare 团队选择 Rust 是因为它可以在不妥协性能的前提下以内存安全的方式完成 C 语言所能做的事情。

    "We chose Rust as the language of the project because it can do what C can do in a memory safe way without compromising performance."

    快速安全地发布功能很困难,尤其是在我们的规模下。很难预测在每秒处理数百万个请求的分布式环境中可能发生的每个边缘情况。模糊测试和静态分析只能缓解这么多。Rust 的内存安全语义保护我们免受未定义行为的影响,让我们确信我们的服务将正确运行。
    有了这些保证,我们可以更多地关注我们的服务更改将如何与其他服务或客户来源进行交互。我们可以以更高的节奏开发功能,而不会受到内存安全问题和难以诊断崩溃的负担。
    当崩溃确实发生时,工程师需要花时间来诊断它是如何发生的以及是什么原因造成的。自 Pingora 成立以来,我们已经处理了数百万亿个请求,并且还没有因为我们的服务代码而崩溃。
    事实上,Pingora 崩溃是如此罕见,当我们遇到一个问题时,我们通常会发现不相关的问题。最近,我们的服务开始崩溃后不久,我们发现了一个内核错误。我们还发现了一些机器上的硬件问题,过去排除了由我们的软件引起的罕见内存错误,即使在几乎不可能进行重大调试之后也是如此。

    "Shipping features quickly and safely is difficult, especially at our scale. It's hard to predict every edge case that can occur in a distributed environment processing millions of requests a second. Fuzzing and static analysis can only mitigate so much. Rust's memory-safe semantics guard us from undefined behavior and give us confidence our service will run correctly.
    With those assurances we can focus more on how a change to our service will interact with other services or a customer's origin. We can develop features at a higher cadence and not be burdened by memory safety and hard to diagnose crashes.
    When crashes do occur an engineer needs to spend time to diagnose how it happened and what caused it. Since Pingora's inception we’ve served a few hundred trillion requests and have yet to crash due to our service code.
    In fact, Pingora crashes are so rare we usually find unrelated issues when we do encounter one. Recently we discovered a kernel bug soon after our service started crashing. We've also discovered hardware issues on a few machines, in the past ruling out rare memory bugs caused by our software even after significant debugging was nearly impossible."
    cndns
        18
    cndns  
       2022-09-27 00:09:08 +08:00 via Android
    @Nugine0 nginx 压力山大啊,前有用 go 开放的 caddy 要追它,现在坐等 pingora 开源
    seakingii
        19
    seakingii  
       2022-09-27 00:13:59 +08:00
    RUST 相对 C++的极大优势是 更安全.受不了 C++写的程序老是崩溃,C++的操控难度太高.
    seakingii
        20
    seakingii  
       2022-09-27 00:14:59 +08:00
    另外,RUST 也正在涉及 Linux 的内核, RUST 蚕食 C++的情况越来越明显...
    seakingii
        21
    seakingii  
       2022-09-27 00:15:29 +08:00
    RUST 蚕食 C 以及 C++的情况越来越明显...
    agagega
        22
    agagega  
       2022-09-27 00:17:22 +08:00
    有时候可能不是 Rust 多么强,而是老 C++代码下限太低🤣 按说生命周期检查 C++也可以通过编译器扩展去做,C++某些时候表达能力比 Rust 还厉害一点,但我是真不喜欢 CMake ,C++要用个包也是麻烦
    ColorfulBoar
        23
    ColorfulBoar  
       2022-09-27 01:10:37 +08:00
    @agagega #22 试试 vcpkg (manifest mode)?这玩意体验比较像 cargo 一点。另外有些人试过做 borrow checker 不过不太成功。我觉得这玩意也不是个技术问题,越是容易写出 lifetime 方面 bug 的人越喜欢写 borrow checker 检查不了的东西(并认为自己特懂硬件编译器在阻止自己控制底层细节),C++编译器又不可能强制搞个 strict mode ,那能怎么办嘛,还是得练习解决掉制造问题的人
    cnbatch
        24
    cnbatch  
       2022-09-27 01:44:00 +08:00   ❤️ 1
    这两条新闻,记得好像在哪里见过并且还曾经有很多人评论过……

    然后想起来了,在这里:
    https://www.oschina.net/comment/news/210809

    其中一个评论我看得不太明白:“7 岁就得了肢端肥大?”


    而 Pingora 的在上上周就被人讨论过:
    https://www.oschina.net/comment/news/210473

    目前高赞的是这个评论:
    「现在性能强,是因为他满足自身定制的各种需求,但如果放到公用领域,就一样的功能臃肿,能做到稳定都不易,就别想性能了。不过是多了一个更多的选择。」

    个人觉得,最好等到 Pingora 开源(如果 Cloudflare 愿意的话),应该会有不少人很感兴趣,从而在思路、设计的角度去跟 nginx 做一次对比和分析。接着或许会有一些有用的发现,说不定某些思路最终可以跨语言,大家都受益。
    devcat9
        25
    devcat9  
       2022-09-27 02:19:19 +08:00
    泻药。

    公司内部的共识是,能选 Rust 全选 Rust 。
    不能选 Rust 的话,要用非常 modern 的 C++
    leighton
        26
    leighton  
       2022-09-27 07:37:24 +08:00 via iPhone   ❤️ 4
    以前在 aws 某有点年头的 org ,我走之前 org 的最新指导是,非 gc 语言要么纯 c 要么 rust ,gc 语言鼓励用 kotlin ,没特殊原因一律不准用 c++写新项目
    iapplebear
        27
    iapplebear  
       2022-09-27 09:31:44 +08:00   ❤️ 2
    非必要不使用 C++
    x500
        28
    x500  
       2022-09-27 10:05:46 +08:00
    还是看个人水平
    Andreas8
        29
    Andreas8  
       2022-09-27 11:27:30 +08:00 via iPhone   ❤️ 1
    Rust 从入门到放弃👨‍🦼
    lookStupiToForce
        30
    lookStupiToForce  
       2022-09-27 11:44:31 +08:00
    看完又想到了 linus 的名言
    leegradyllljjjj
        31
    leegradyllljjjj  
       2022-09-27 13:53:23 +08:00   ❤️ 3
    当初被你们匡去学 go ,学 web3.0 ,现在又让我去学 rust ,导致现在工作都找不到,你们这些坏人
    taowen
        32
    taowen  
       2022-09-27 14:00:12 +08:00
    WebAssembly 读和写 nullptr 都是不报错的。C++访问 move 之后的对象也是不编译报错的。这两玩意配合到一起,简直绝配。
    sharpy
        33
    sharpy  
       2022-09-27 14:54:14 +08:00
    google 还有个 carbon ,这个像没有借用检查的 rust ,据说目标是兼容 c++
    zxkmm
        34
    zxkmm  
       2022-09-27 17:17:35 +08:00
    @sharpy 盈利公司和基金会背景的语言是两种结果。盈利公司的语言永远不可能发展到被用来写底层。也不可能被合并到 kernel 。
    novolunt
        35
    novolunt  
       2022-09-27 17:19:59 +08:00
    @leegradyllljjjj 哈哈哈哈哈哈 笑出声
    golang 还行吧
    dog82
        36
    dog82  
       2022-09-27 20:04:23 +08:00
    rust 的学习曲线很陡峭,容易放弃;对写 crud 的人不够友好
    DeWjjj
        37
    DeWjjj  
       2022-09-27 21:44:59 +08:00   ❤️ 1
    rust = offical package management + offical lang + offical fmt.
    c++ = metaur package management + mateur lang + mateur fmt.
    c++变数太大了,规则还不一。但是 rust 就不一样了,给你卡的死死的不能变就是不能动。
    虽然代码数量会写起来比较多,但是不容易错。
    kennylam777
        38
    kennylam777  
       2022-09-27 22:55:33 +08:00
    Google 了一下 Linux kernel rust ,還真的要來了
    iwdmb
        39
    iwdmb  
    OP
       2022-09-27 22:59:16 +08:00
    Linus Torvalds: Rust will go into Linux 6.1
    https://www.zdnet.com/article/linus-torvalds-rust-will-go-into-linux-6-1/

    能被当初把 C++ 战的体无完肤的 Linus Torvalds 认可
    算得上 Rust 的一个大里程碑
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2748 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 12:35 · PVG 20:35 · LAX 05:35 · JFK 08:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.