Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace throttle implementation by external library #654

Closed
wants to merge 9 commits into from
Closed

Replace throttle implementation by external library #654

wants to merge 9 commits into from

Conversation

jbigman
Copy link
Contributor

@jbigman jbigman commented Aug 11, 2023

No description provided.

- got from 11.8.6 to 13.0.0
- mocha from 9.1.4 to 10.2.0
- ramda from 0.21.0 to 0.29.0
- and minor bumps on others
# Conflicts:
#	package-lock.json
#	package.json
@jbigman
Copy link
Contributor Author

jbigman commented Aug 11, 2023

Don't mind about the third commit description, i missed a copy paste. it contains eslint adjustments.

});

if (opts.throttle !== undefined) {
const throttle = pThrottle({
Copy link
Owner

@facundoolano facundoolano Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you need to add this explicit throttle setup here? doesn't the setup in the internal request module apply here as well by just passing the throttle option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thougth the same, but test fails if i don't edit processpage when it batch request fulldetails

@jbigman
Copy link
Contributor Author

jbigman commented Aug 11, 2023

I wrote this implementation

const req = (resolve, reject) => requestLib(opts)
    .then((response) => resolve(response.body))
    .catch((error) => reject(error));

  let promiseToResolve = (resolve, reject) => req(resolve, reject);

  if (throttleParams !== undefined) {
    const throttle = pThrottle({
      limit: throttleParams.limit ? throttleParams.limit : 1000,
      interval: throttleParams.interval ? throttleParams.interval : 0
    });
    promiseToResolve = (resolve, reject) => throttle(req(resolve, reject));
  }
  return new Promise(promiseToResolve);

But we could use the throttling method everytime with default values set to {limit: 1000, interval : 0}

  const throttle = pThrottle({
    limit: throttleParams && throttleParams.limit ? throttleParams.limit : 1000,
    interval: throttleParams && throttleParams.interval ? throttleParams.interval : 0
  });
  return new Promise((resolve, reject) => throttle(requestLib(opts)
    .then((response) => resolve(response.body))
    .catch((error) => reject(error))));

@jbigman
Copy link
Contributor Author

jbigman commented Aug 11, 2023

Both the limit and interval options must be specified in p-throttle usage.

That's why i force interval or limit with default values if one is missing

@facundoolano
Copy link
Owner

so a couple of things:

  1. by default throttling should be off. we don't want to silently introduce a limit unless the client explicitly tell us to do so
  2. it's ok to set a default to the missing argument if the other is specified.
  3. see the related documentation on this repo. You should make sure we continue to support the same behavior, and update accordingly if there are new options or things to be considered (but it's best not to introduce a change in behavior or interface if not necessary). In particular, I think it's fine to continue to assume the interval is always seconds, and just take an integer as the throttle value, which will be assumed to be the request limit by second.
  4. I need to review more closely that duplicated setting you have for the fullDetail, I want to understand why it's necessary

@jbigman
Copy link
Contributor Author

jbigman commented Aug 11, 2023

in fact, p-throttle doesnt queue requests, i'll try to use throttledQueue instead

@jbigman jbigman marked this pull request as draft August 11, 2023 18:19
@jbigman jbigman changed the title Replaced throttle implementation by p-trottle library Replace throttle implementation by external library Aug 11, 2023
@facundoolano
Copy link
Owner

closing due to inactivity, but feel free to send a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants