如何模拟工作负载

发布于 2024-12-20 01:44:06 字数 676 浏览 1 评论 0原文

我必须编写一个程序(perl、python 或 java)来模拟服务器上的工作负载,这样它需要 2 个参数:

  1. Memory

  2. Time

并且基于这些参数应该启动一个进程,在指定的时间内消耗指定的内存量。内存的最大值可以高达 50-100GB,时间可以长达 12-24 小时。

我不能使用 fork 或多线程,这个进程应该是单线程并且应该连续执行操作(如整数/浮点等)。我也不想进行任何 I/O 操作。

我能想到的最简单的方法是:

 1. while(timeSpent < timeLimit || memoryConsumed < memorySpecified){
 2.           if(memoryConsumed < ){
 3.                Add random number to ArrayList 
 4.           }else{
 5.                Multiply all numbers (Do some exception handling to prevent this from overflowing) 
 6.           }
 7. }

如果有更好的方法,请告诉我。

谢谢,

阿米特

I have to write a program (perl , python or java) to simulate workload on our server such that it takes 2 arguments :

  1. Memory

  2. Time

And based on these arguments it should start a process that consumes the specified amount of memory for specified amount of time.Max value of memory can be as high as 50-100GB and Time can be upto 12-24 hrs.

I cannot use fork or multi threads, this process should be a single thread and should continuously do operations (like Integer / Floating point etc). I don't want to do any I/O operations also.

The simplest way I could think of was:

 1. while(timeSpent < timeLimit || memoryConsumed < memorySpecified){
 2.           if(memoryConsumed < ){
 3.                Add random number to ArrayList 
 4.           }else{
 5.                Multiply all numbers (Do some exception handling to prevent this from overflowing) 
 6.           }
 7. }

Please let me know if there is a better way of doing this.

Thanks,

Amit

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

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

发布评论

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

评论(3

欢烬 2024-12-27 01:44:06

像这样的 python 代码不适合您的需求吗?

import argparse
import datetime

def main():
    parser = argparse.ArgumentParser(description = "Consume memory and time.")
    parser.add_argument('memory', metavar = 'M', type=int, help = "memory (in megabytes) to consume")
    parser.add_argument('time', metavar = 'H', type=int, help = "time (in hours) to consume")
    args = parser.parse_args()

    data = bytearray(args.memory * 1000000)
    now = datetime.datetime.today()
    finish = now + datetime.timedelta(hours = args.time)
    while now < finish:
        for i in xrange(args.memory * 1000000):
             data[i] = now.second
        now = datetime.datetime.today()


if __name__ == '__main__':
    main()

Wouldn't something like this python code suit your needs?

import argparse
import datetime

def main():
    parser = argparse.ArgumentParser(description = "Consume memory and time.")
    parser.add_argument('memory', metavar = 'M', type=int, help = "memory (in megabytes) to consume")
    parser.add_argument('time', metavar = 'H', type=int, help = "time (in hours) to consume")
    args = parser.parse_args()

    data = bytearray(args.memory * 1000000)
    now = datetime.datetime.today()
    finish = now + datetime.timedelta(hours = args.time)
    while now < finish:
        for i in xrange(args.memory * 1000000):
             data[i] = now.second
        now = datetime.datetime.today()


if __name__ == '__main__':
    main()
夜光 2024-12-27 01:44:06

我正在使用实用程序stressweather.ou.edu/~apw/projects/stress...尽管对其进行了一些调整以扩展我想要的功能..

感谢你们的帮助。

I am using the utility stress weather.ou.edu/~apw/projects/stress ... though tweaked it a bit to extend the features that I wanted..

Thanks for your help guys.

偏闹i 2024-12-27 01:44:06

你的例子看起来很合理,至少第一步是这样。然而,有很多小细节需要正确处理:

  • 你说你不想进行 I/O,这很好,但是在
    在现代机器中分配 50-100 GB,无论您是否会进行 I/O
    不管你想要与否(通过页面错误),所以你可能想要重新定义
    你的规格在那里。
  • 另外,请考虑“对象”的粒度,许多
    科学计算应用程序无法摆脱“许多小物体”
    范例。您可能希望有一些参数来平衡
    “许多小物体”和“几个大物体”。
  • 另外,通过乘法或相加或其他方法,将您的所有数据点相乘或相加
    容器中,您可能会生成一系列页面错误,这些错误可能
    操作系统很容易预测,因此在
    现实世界中,您可能想添加一些随机性
    遍历它。

这是一个比看起来更微妙的问题,很多人都想从简单的甚至标准的测试开始,例如:SETI 或光线追踪器。

Your example seems reasonable, at least for a first step. There are however many little details to get right:

  • You say you don't want to do I/O, and that is fine, however in the
    allocation of 50-100 GB in a modern machine you will do I/O whether you
    want it or not (by way of page faults), so you may want to redefine
    your spec there.
  • Also, take into account the granularity of your "objects", many
    scientific computing apps cannot get by the "many small objects"
    paradigm. You many want to have some parameter to balance between
    "many small objects" and "few large objects".
  • Also, by multiplying or adding or something all datapoints in your
    container you may generate a sequence of page faults that may
    easily be predicted by the OS, and therefore unrealistic in the
    real world, you may want to add some randomness in the way you
    traverse it.

It is a more subtle problem than it seems, and you many want to start simple and perhaps even with standard tests like: SETI or a raytracer.

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