{"action":"created","issue":{"url":"https://api.github.com/repos/petkaantonov/bluebird/issues/570","labels_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/570/labels{/name}","comments_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/570/comments","events_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/570/events","html_url":"https://github.com/petkaantonov/bluebird/issues/570","id":67101994,"number":570,"title":"Load balancing / throttling","user":{"login":"vitaly-t","id":5108906,"avatar_url":"https://avatars.githubusercontent.com/u/5108906?v=3","gravatar_id":"","url":"https://api.github.com/users/vitaly-t","html_url":"https://github.com/vitaly-t","followers_url":"https://api.github.com/users/vitaly-t/followers","following_url":"https://api.github.com/users/vitaly-t/following{/other_user}","gists_url":"https://api.github.com/users/vitaly-t/gists{/gist_id}","starred_url":"https://api.github.com/users/vitaly-t/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vitaly-t/subscriptions","organizations_url":"https://api.github.com/users/vitaly-t/orgs","repos_url":"https://api.github.com/users/vitaly-t/repos","events_url":"https://api.github.com/users/vitaly-t/events{/privacy}","received_events_url":"https://api.github.com/users/vitaly-t/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-04-08T10:45:04Z","updated_at":"2015-07-31T12:38:57Z","closed_at":"2015-05-06T09:58:17Z","body":"Promise approach has a great potential to solving the load balancing / throttling problem, which is yet missing. This is a proposal to add such feature to the library.\r\n\r\nAs an example, use a question + my answer from StackOverflow for [massive amounts of queries](http://stackoverflow.com/questions/29100807/node-postgres-with-massive-amount-of-queries).\r\n\r\nIn essence, we have a number of promises that need to be resolved sequentially. Typically, this can be achieved by using `promise.all()`. However, in cases where the number of promise objects is so large that a single call to `promise.all()` is impossible, we need to implement a complex workaround, like the one link to which I provided earlier (perhaps not a very good one at that).\r\n\r\nWhat we need is something called `promise.page` or `promise.throttle` that would adhere to the idea of splitting one huge chunk of promises into smaller chunks and page through them all till they are all resolved. In addition, we need a flexibility in the resolution strategy:\r\n\r\n* specify that each chunk/page of promises is to be resolved one after another. This is very-very important, because in many cases an attempt to execute a chunk of promises before the previous one is finished will lead to running out of memory.\r\n* by default, the whole request should reject, if one chunk rejects, but we need an option where it is possible to either just stop or carry on with other chunks of promises.\r\n* such a method would need to request each next chunk of data through a promise, because typically the data would never reside in memory in its entirety.\r\n\r\nIt should help greatly if you think if this all as an almost-infinite queue that got terminated and now needs to be processed entirely, fast and in huge bulks.\r\n\r\nAnd you don't need to think of it as something that deals only with copious amounts of promises. Totally not. Here's an example:\r\n\r\nWe have 100 requests to be sent to a particular service in one go. However, the service accepts only up to 10 at a time, so we need to send it in 10 blocks. Promise support for throttling would shine in this case.\r\n\r\nP.S. I've been tempted to implement it in my own library - [pg-promise](https://github.com/vitaly-t/pg-promise), but it's just truly a generic promise task, and not just database-related.\r\n"},"comment":{"url":"https://api.github.com/repos/petkaantonov/bluebird/issues/comments/126677554","html_url":"https://github.com/petkaantonov/bluebird/issues/570#issuecomment-126677554","issue_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/570","id":126677554,"user":{"login":"vitaly-t","id":5108906,"avatar_url":"https://avatars.githubusercontent.com/u/5108906?v=3","gravatar_id":"","url":"https://api.github.com/users/vitaly-t","html_url":"https://github.com/vitaly-t","followers_url":"https://api.github.com/users/vitaly-t/followers","following_url":"https://api.github.com/users/vitaly-t/following{/other_user}","gists_url":"https://api.github.com/users/vitaly-t/gists{/gist_id}","starred_url":"https://api.github.com/users/vitaly-t/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vitaly-t/subscriptions","organizations_url":"https://api.github.com/users/vitaly-t/orgs","repos_url":"https://api.github.com/users/vitaly-t/repos","events_url":"https://api.github.com/users/vitaly-t/events{/privacy}","received_events_url":"https://api.github.com/users/vitaly-t/received_events","type":"User","site_admin":false},"created_at":"2015-07-31T12:38:57Z","updated_at":"2015-07-31T12:38:57Z","body":">making the time between two operations at least N milliseconds\r\n- that, and CPU-throttling are the same, you are talking semantics. The CPU throttling is done by introducing delays between request batches of either predefined size or dynamic size, based on the current CPU load. The latter is outside any promise library.\r\n"}}