虚拟化应用程序的编程注意事项

发布于 2024-10-04 22:04:28 字数 226 浏览 6 评论 0原文

SO 有很多问题询问虚拟化对于开发和测试的利弊。

我的问题略有不同 - 在虚拟化很普遍的世界中,程序员在编写可以部署到虚拟化环境中的软件时应该考虑哪些事情?我最初的一些想法是:

  1. 检测应用程序的另一个实例是否正在运行
  2. 与硬件(物理/虚拟)
  3. 通信 资源限制(为在单 CPU 虚拟机上运行的多核 CPU 编写的应用程序)

还有其他吗?

There are lots of questions on SO asking about the pros and cons of virtualization for both development and testing.

My question is subtly different - in a world in which virtualization is commonplace, what are the things a programmer should consider when it comes to writing software that may be deployed into a virtualized environment? Some of my initial thoughts are:

  1. Detecting if another instance of your application is running
  2. Communicating with hardware (physical/virtual)
  3. Resource throttling (app written for multi-core CPU running on single-CPU VM)

Anything else?

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

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

发布评论

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

评论(2

誰ツ都不明白 2024-10-11 22:04:28

您已经掌握了这三大要点的大部分基础知识。注意:

  • 硬件通信相关问题。磁盘访问速度差异很大(并且可能具有异常高的极限 - 想象一个虚拟机在磁盘写入过程中关闭 3 天......)。网络访问可能会因异常响应而中断
  • 花哨的指针算术。尽量避免它
  • 严重依赖异常不常见的低级/汇编指令
  • 依赖机器时钟。请记住,在 VM 上运行时,您对时钟和时间间隔进行的任何调用可能会定期返回异常值。
  • 单 CPU 应用程序可能会发现自己在多个 CPU 计算机上运行,​​这些计算机会执行诸如 工作窃取
  • 极端情况和异常故障模式更为常见。您可能不必像在虚拟机上那样担心网卡会在真机上的通信过程中消失
  • 手动管理资源(内存、磁盘等...)。工作自动化程度越高,虚拟环境处理它的能力就越好。例如,您可能最好使用内存管理类型的语言/环境,而不是用 C 编写应用程序。

You have most of the basics covered with the three broad points. Watch out for:

  • Hardware communication related issues. Disk access speeds are vastly different (and may have unusually high extremes - imagine a VM that is shut down for 3 days in the middle of a disk write....). Network access may interrupt with unusual responses
  • Fancy pointer arithmetic. Try to avoid it
  • Heavy reliance on unusually uncommon low level/assembly instructions
  • Reliance on machine clocks. Remember that any calls you're making to the clock, and time intervals, may regularly return unusual values when running on a VM
  • Single CPU apps may find themselves running on multiple CPU machines, that do funky things like Work Stealing
  • Corner cases and unusual failure modes are much more common. You might not have to worry as much that the network card will disappear in the middle of your communication on a real machine, as you would on a virtual one
  • Manual management of resources (memory, disk, etc...). The more automated the work, the better the virtual environment is likely to be at handling it. For example, you might be better off using a memory-managed type of language/environment, instead of writing an application in C.
蘑菇王子 2024-10-11 22:04:28

根据我的经验,您实际上只需要关心几件事:

  • 您的应用程序不应该因为 CPU 时间短缺(即使用超时太紧)而失败

  • 不要使用低优先级始终运行的进程在后台执行任务

  • < p>时钟可能运行不均匀

  • 不要相信操作系统关于系统负载的说法

几乎任何其他问题都应该不是由应用程序处理,而是由虚拟器、主机操作系统或您首选的系统管理员处理:-)

In my experience there are really only a couple of things you have to care about:

  • Your application should not fail because of CPU time shortage (i.e. using timeouts too tight)

  • Don't use low-priority always-running processes to perform tasks on the background

  • The clock may run unevenly

  • Don't truss what the OS says about system load

Almost any other issue should not be handled by the application but by the virtualizer, the host OS or your preferred sys-admin :-)

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