如何实现在线裁判机器人?(例如TopCoder、Uva、ACM-ICPC)

发布于 2024-12-25 07:22:36 字数 366 浏览 1 评论 0原文

有许多在线评判网站可以通过将输出与正确答案进行比较来验证您的程序。更重要的是,他们还会检查运行时间和内存使用情况,以确保您的程序没有超出最大限制。

那么我的问题是,由于一些在线评判网站同时运行多个测试程序,它们是如何实现性能隔离的呢?他们如何在不同时间运行的同一程序上实现相同的运行时间?

我认为存在诸如“VMware”或“沙盒”之类的隔离环境进程,它们总是返回相同的结果。这是正确的吗?以及关于如何实施这些事情的任何想法?

当前解决方案

我正在使用 docker 进行沙箱处理。这是一种非常简单且最安全的方法。

There are many online judge sites which can verify your program by comparing its output to the correct answers. What's more, they also check the running time and memory usage to make sure that your program doesn't exceed the maximum limit.

So here is my question, since some online judge sites run several test programs at the same time, how do they achieve performance isolation? and how do they achieve same running time on same program that run at another time?

I think there are isolated environment processes like 'VMware' or 'Sandbox' that always return same result. is this correct? and any idea about how to implement these things?

Current Solution

I'm using docker for sandboxing. it's a dead simple and the safest way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

庆幸我还是我 2025-01-01 07:22:36

不幸的是,即使在专用机器上与虚拟机上,实际上也很难保证一致的运行时间。如果您确实想要实现像前面提到的那样的东西,您可能需要虚拟机来保留将在沙盒中运行的所有代码。通常,您不想为每个核心处理多个请求,因此我想说,对于内存和 CPU 绑定的算法,机器的每个物理核心最多使用 2 个虚拟机。

尽管我只能推测为什么不尝试每个核心的不同数量的虚拟机并看看它的性能如何。尝试以 90% 或更高的 SLO 合规率为目标(如果确实需要,则为 98-99),应该没问题。同样,很难准确地告诉您要做什么,因为很多事情都需要对其进行测试并查看其效果。

Unfortunately it is VERY hard to actually guarantee consistent running times even on a dedicated machine versus a VM. If you do want to implement something like this as was mentioned you probably want a VM to keep all the code that will run sandboxed. Usually you don't want to service more than a couple of requests per core so I would say for algorithms that are memory and cpu bound use at most 2 VMs per physical core of the machine.

Although I can only speculate why not try different numbers of VMs per core and see how it performs. Try to aim for about a 90% or higher rate of SLO compliance (or 98-99 if you really need to) and you should be just fine. Again its hard to tell you exactly what to do as a lot of these things require just testing it out and seeing how it does.

末骤雨初歇 2025-01-01 07:22:36

可能过于简单化,具体取决于您不在问题中的其他要求,但是;

如果算法受 CPU 限制,那么只需在隔离的 VM(或 FreeBSD 监狱,或...)中运行它并使用内置操作系统工具将是最简单的。

(可能就像在 unix 中使用“time”命令并使用“limit”设置内存限制一样简单)

May be overly simplistic depending on your other requirements which aren't in the question, but;

If the algorithms are CPU bound, simply running it in an isolated VM (or FreeBSD jail, or...) and using the built-in operating system instrumentation would be the simplest.

(Could be as simple as using the 'time' command in unix and setting memory limits with "limit")

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文