All Projects → binded → Phantom Pool

binded / Phantom Pool

Licence: mit
PhantomJS resource pool based on generic-pool

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Phantom Pool

React Anime
✨ (ノ´ヮ´)ノ*:・゚✧ A super easy animation library for React!
Stars: ✭ 1,313 (+1187.25%)
Mutual labels:  npm
Lmify
Install NPM dependencies programmatically 🤙
Stars: ✭ 98 (-3.92%)
Mutual labels:  npm
Poolboy
A hunky Erlang worker pool factory
Stars: ✭ 1,363 (+1236.27%)
Mutual labels:  pool
Splashr
💦 Tools to Work with the 'Splash' JavaScript Rendering Service in R
Stars: ✭ 93 (-8.82%)
Mutual labels:  phantomjs
Npm Introspect
🔎 Introspect is a tool to traverse the NPM ecosystem and identify quality modules. Use the CLI to upload and examine your project's dependencies.
Stars: ✭ 95 (-6.86%)
Mutual labels:  npm
Democracy Client
DEMOCRACY App Client
Stars: ✭ 98 (-3.92%)
Mutual labels:  npm
Npmarket
🛒 More efficient search for node packages.
Stars: ✭ 91 (-10.78%)
Mutual labels:  npm
String To Color
Time invariant color from any object.
Stars: ✭ 101 (-0.98%)
Mutual labels:  npm
Tplink Cloud Api
A node.js npm module to remotely control TP-Link smartplugs (HS100, HS110) and smartbulbs (LB100, LB110, LB120, LB130) using their cloud web service (no need to be on the same wifi/lan)
Stars: ✭ 96 (-5.88%)
Mutual labels:  npm
Cryptocurrency Cli
💰 Cryptocurrency Portfolio On The Command Line 💰
Stars: ✭ 99 (-2.94%)
Mutual labels:  npm
Lambda Phantom Scraper
PhantomJS/Node.js web scraper for AWS Lambda
Stars: ✭ 93 (-8.82%)
Mutual labels:  phantomjs
Vue Csv Import
Vue.js component to select a CSV file, map the columns to fields, and post it somewhere.
Stars: ✭ 95 (-6.86%)
Mutual labels:  npm
Geotic
Entity Component System library for javascript
Stars: ✭ 97 (-4.9%)
Mutual labels:  npm
Doge
Darknet Osint Graph Explorer
Stars: ✭ 93 (-8.82%)
Mutual labels:  npm
Npm Quick Run
Quickly run NPM script by prefix without typing the full name
Stars: ✭ 97 (-4.9%)
Mutual labels:  npm
Angular File Uploader
Angular file uploader is an Angular 2/4/5/6/7/8/9/10 + file uploader module with Real-Time Progress Bar, Responsive design, Angular Universal Compatibility, localization and multiple themes which includes Drag and Drop and much more.
Stars: ✭ 92 (-9.8%)
Mutual labels:  npm
Pool
General Purpose Connection Pool for GRPC,RPC,TCP Sevice Cluster
Stars: ✭ 98 (-3.92%)
Mutual labels:  pool
React Native Context Menu View
Use native context menus in React Native
Stars: ✭ 101 (-0.98%)
Mutual labels:  npm
Node Sonic Channel
🦉 Sonic Channel integration for Node. Used in pair with Sonic, the fast, lightweight and schema-less search backend.
Stars: ✭ 101 (-0.98%)
Mutual labels:  npm
Config Chain
Handle configuration once and for all
Stars: ✭ 98 (-3.92%)
Mutual labels:  npm

phantom-pool

Build Status

Resource pool based on generic-pool for PhantomJS.

Creating new phantom instances with phantom.create() can be slow. If you are frequently creating new instances and destroying them, as a result of HTTP requests for example, this module can help by keeping a pool of phantom instances alive and making it easy to re-use them across requests.

Here's an artificial benchmark to illustrate:

Starting benchmark without pool

noPool-0: 786.829ms
noPool-1: 790.822ms
noPool-2: 795.150ms
noPool-3: 788.928ms
noPool-4: 793.788ms
noPool-5: 798.075ms
noPool-6: 813.130ms
noPool-7: 803.801ms
noPool-8: 782.936ms
noPool-9: 805.630ms

Starting benchmark with pool

pool-0: 48.160ms
pool-1: 98.966ms
pool-2: 89.573ms
pool-3: 99.057ms
pool-4: 101.970ms
pool-5: 102.967ms
pool-6: 102.938ms
pool-7: 99.359ms
pool-8: 101.972ms
pool-9: 103.309ms

Done

Using pool in this benchmark results in an average >8x speed increase.

Install

npm install --save phantom-pool

Requires Node v6+

Usage

See ./test directory for usage examples.

const createPhantomPool = require('phantom-pool')

// Returns a generic-pool instance
const pool = createPhantomPool({
  max: 10, // default
  min: 2, // default
  // how long a resource can stay idle in pool before being removed
  idleTimeoutMillis: 30000, // default.
  // maximum number of times an individual resource can be reused before being destroyed; set to 0 to disable
  maxUses: 50, // default
  // function to validate an instance prior to use; see https://github.com/coopernurse/node-pool#createpool
  validator: () => Promise.resolve(true), // defaults to always resolving true
  // validate resource before borrowing; required for `maxUses and `validator`
  testOnBorrow: true, // default
  // For all opts, see opts at https://github.com/coopernurse/node-pool#createpool
  phantomArgs: [['--ignore-ssl-errors=true', '--disk-cache=true'], {
    logLevel: 'debug',
  }], // arguments passed to phantomjs-node directly, default is `[]`. For all opts, see https://github.com/amir20/phantomjs-node#phantom-object-api
})

// Automatically acquires a phantom instance and releases it back to the
// pool when the function resolves or throws
pool.use(async (instance) => {
  const page = await instance.createPage()
  const status = await page.open('http://google.com', { operation: 'GET' })
  if (status !== 'success') {
    throw new Error('cannot open google.com')
  }
  const content = await page.property('content')
  return content
}).then((content) => {
  console.log(content)
})

// Destroying the pool:
pool.drain().then(() => pool.clear())

// For more API doc, see https://github.com/coopernurse/node-pool#generic-pool

Security

When using phantom-pool, you should be aware that the phantom instance you are getting might not be in a completely clean state. It could have browser history, cookies or other persistent data from a previous use.

If that is an issue for you, make sure you clean up any sensitive data on the phantom instance before returning it to the pool.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].