开发者

My Memory Usage Assumption: Is it Correct?

I have a script when ran consumes 17mb of memory (logged using memory_get_peak_usage()).

Script is ran 1 million times per day. Total开发者_JAVA百科 daily memory consumption: 17 million mb

86400 seconds in a day.

17000000 / 86400 = 196.76

Assumption: Running this script 1 million times each day will require at least 196.76 dedicated memory.

Is my assumption correct?


If script is runs 1000000 copies at the same time, then you would get 17 million MB, but as it releases memory after to completes, you don't add usage to total sum.

You need to know how much copies run at same time and multiply that number of 17 MB. That would be max memory usage.


Not entirely correct; the first hundred times your script is executed, it'll probably all fit into memory fine; so, the first two minutes or so might go as expected. But, once you push your computer into swap, your computer will spend so much time handling swap, that the next 999,800 executions might go significantly slower than you'd expect. And, as they all start competing for disk bandwidth, it will get much worse the longer it runs.

I'm also not sure about the use of the php memory_get_peak_usage() function; it is an 'internal' view of the memory the program requires, not the view from the operating system's perspective. It might be significantly worse. (Perhaps the interpreter requires 20 megs RSS just to run a hello-world. Perhaps not.)

I'm not sure what would be the best way forward for your application: maybe it could be a single long-lived process, that handles events as they are posted, and returns results. That might be able to run in significantly less memory space. Maybe the results don't actually change every 0.0005 seconds, and you could cache the results for one second, and only run it 86400 times per day. Or maybe you need to buy a few more machines. :)


Yes, but what if it gets called multiple times at the same time? You have multiple threads running simultaneously.

EDIT: Also, why is that script running a million times / day? (unless you got a huge website)


I dont think this calculation will give correct results because you also need to consider other factors such as -

  1. How long the script runs.
  2. What are the number of scripts running at a time.
  3. Distribution of the invocation of scripts throughout the time.

And in your calculation whats the point in dividing by 86400 seconds? why not hours or milliseconds. To me, the calculation seems pretty meaningless.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜