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

Maintaining a minimum active number of resources. #77

Closed
frank-weindel opened this issue Aug 25, 2014 · 2 comments
Closed

Maintaining a minimum active number of resources. #77

frank-weindel opened this issue Aug 25, 2014 · 2 comments

Comments

@frank-weindel
Copy link

I'm having trouble getting my pool keep a minimum number of resources alive. Essentially, I want to have at least 4 available at all times and spawn up to 4 more when load becomes heavier.

This is my code:

this.generatorPool = poolModule.Pool({
    name: 'generator-pool',
    create: function (resolveResource) {
      var generator = new Generator();
      generator.start().then(
        // Generator load successful
        function() {
          resolveResource(null, generator);
        },
        // Generator failed to load
        function () {
          resolveResource(new Error('Failed to load generator'));
        }
      );
    },
    destroy: function (generator) {
      console.log('DESTROYING THE GENERATOR)
      generator.stop();
    },
    max: 8,
    min: 4,
    refreshIdle: false,
    idleTimeoutMillis: 30000
  });

For some reason the first 4 resources are still being destroyed after 30 seconds. What could be up?

@sandfox
Copy link
Collaborator

sandfox commented Aug 26, 2014

This looks like intended behaviour.

Once each of the first 4 resources are destroyed are they being replaced by another set of resources? (i.e does the pool always have 4 resources in it, because that should be what is happening)
The resources are getting destroyed after 30 seconds because of the idleTimeoutMillis: 30000.

@frank-weindel
Copy link
Author

Looking at it closer I see the problem is different than I originally thought. When I have the minimum set to 4 the pool does start to spawn 4 resources when its created. However, immediately after the pool creation I call acquire 4 times. This starts up an ADDITIONAL 4 resources instead of waiting for the first 4 to finish initializing and using them. Those 4 additional resources were what I was seeing get destroyed. Its not a huge deal for me since this can only happen at startup.

I can understand fixing that issue might not be worth the complexity.

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

No branches or pull requests

2 participants