Vincit/tarn.js

Make it possible to limit the times a resource could be used

ddinchev opened this issue · 2 comments

I'm trying to use tarn.js with puppeteer to create a pool of workers that create screenshots out of coming URLs. Chrome is leaking resources and after a while workers become unstable. One solution would be to limit the times a worker can be used.

It would be a great addition to tarn.js if we can add a property like maxAcquireCount. After a worker has been used N times, it will be destroyed and recreated.

Another use case that this would also be useful for is allowing a downtimeless migration from one read-only DB to another read-only DB via DNS changes when using https://github.com/tgriesser/knex.

As in:

  • t0: knex pool has connections to DB Host A with ip 10.0.0.1
  • t1: DNS changes are made to change Host A to resolve to 10.0.0.2 (or nodes are added/removed from a load balancer)
  • t2: after some time, knex retires old connections to 10.0.0.1 and establishes new connections to 10.0.0.2 (or re-establishes new connections to the load balancer, resulting in connections to hosts that were newly added and allowing DBs that were removed from the load balancer to be retired)

Currently knex (admittedly using v0.12.6) seems to keep some connections very active, resulting in no time for connections to become idle and have their connections refreshed.

@ddinchev You can use the validate hook to do that.
@elliotf knex 0.12.6 doesn't use Tarn.