What the heck?
levipearson at gmail.com
Thu Dec 12 16:20:53 MST 2013
On Thu, Dec 12, 2013 at 2:16 PM, S. Dale Morrey <sdalemorrey at gmail.com> wrote:
> Now I've got to figure out how to slowdown the requests and gradually feed
> them to the server. Batching will help somewhat, but the max I can send in
> a batch is 100 and even then it's going to quickly overwhelm the server to
> send them out without a delay between sends.
My previous email suggested setting the timeout to i * 500ms, which
will space them 500ms apart. You can easily space them more the
obvious way. To introduce a batching-style periodic delay of, say, 5
seconds for every 100 requests, you would simply add another term to
your delay calculation by doing an integer divide of i by 100 and
multiplying by 5 seconds.
> Another option is to get rid of the loop entirely and just have the
> callback calling in a cycle, but I'm afraid that's going to smash the stack
One of the most frustrating aspects of callback-style programming, but
perhaps fortuitous for you in this instance, is that each callback
executes with a fresh stack. It's in no way connected to the stack
frame that generated the closure; indeed, the callback might be a
top-level function and not a nested closure at all. So if each
invocation updates its loop variables and sets a timeout callback for
500ms in the future to invoke itself, you'll use no extra stack space
at all. This will also eliminate the problem of the closures always
referring to the loop index variable of a loop that already completed!
More information about the PLUG