Django 中的末日:测试 LiveView 在 600,000 divs/秒时的极限
Doom in Django: testing the limits of LiveView at 600.000 divs/segundo

原始链接: https://en.andros.dev/blog/7b1b607b/doom-in-django-testing-the-limits-of-liveview-at-600000-divssegundo/

Django LiveView 在最近的测试中表现出惊人的强大性能,可能是有史以来最快的动态前端之一。为了真正突破其极限,一项具有挑战性的实验被展开:在 Django 应用程序中运行 DOOM! 该设置涉及使用 ViZDoom 生成游戏帧,然后使用 Django 的模板引擎将每个帧转换为 10,000 个独立的 `

` 元素(每个像素一个)。LiveView 然后以每秒 60 帧的速度渲染这些 divs – 令人难以置信的每秒 600,000 个 divs! 重要的是,这些数据是实时广播的,允许多个用户同时观看相同的游戏过程。DOOM 的成功运行证明了 Django LiveView 处理极其繁重的工作负载的能力,证明了它在复杂动态应用中的强大性能。源代码已在 GitHub 上提供,供那些受到启发并构建自己令人印象深刻的项目的人使用。

## Django LiveView 与 Doom:性能测试 一位开发者 andros 分享了一个项目,展示了 Django LiveView 的性能极限,通过渲染 Doom 来达到每秒 60 万个 div 的速度。该项目并非专注于可玩性,而是为了压力测试 LiveView 的能力。 讨论集中在优化策略上——一些人建议使用更少、更大的 div,或者使用渐变填充的单像素列来减少浏览器的工作量。另一些人指出,这个练习的目的是*测试*性能,不一定是为了最大化效率。人们将其与使用 HTMX 以及使用 div 条的旧实现等类似项目进行了比较。 对话还涉及了 Django LiveView 的架构、它与 Phoenix LiveView 的相似之处(以及实现上的差异),以及现代浏览器中 HTML/CSS 渲染的强大性能。一些评论者探讨了 Cloudflare Workers 和 Bunny 等替代托管选项,并争论了 Cloudflare 上 Python 支持的“丑陋”问题。最终,该项目引发了关于框架命名约定以及以非常规方式渲染 Doom 的持久吸引力的讨论。
相关文章

原文

Based on the latest tests I've published, Django LiveView appears to be the fastest dynamic frontend (I'm sure more variables can be measured).

Django LiveView benchmark comparison

OK... but... How can I test its limits? By drawing a Snake? A Pac-Man?... No... let's crank up the difficulty to Nightmare! Let's run DOOM inside Django 😈

Django starts ViZDoom and sends one <div> per pixel with its color. The game runs at 100x100 pixels at 60 FPS = 600.000 divs/second! 😵‍💫

Here's how the data flows:

  1. ViZDoom generates a frame.
  2. Django transforms the frame into 10.000 divs using its template engine.
  3. Django LiveView renders them on the page of connected users.
  4. CSS arranges them.

Furthermore, since the data is sent via broadcast, all players can see the same thing in real time.

Crazy.

Mission accomplished! Django LiveView survived the DOOM stress. It was a ridiculous and fun experiment that proves this framework can handle pretty much anything you throw at it.

Now go build something cool without Doom Slayer.

You can check the source code on GitHub.

联系我们 contact @ memedata.com