How to use the fibers.poolSize function in fibers

To help you get started, we’ve selected a few fibers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sandstorm-io / sandstorm / shell / server / 00-startup.js View on Github external
// large number, we effectively get a pool size equal to the maximum number of simultaneous fibers
// seen. This is exactly what we want! Now no fibers are ever deleted, so we never leak. A
// Sandstorm server that sees a brief surge of traffic may end up holding on to unused RAM
// long-term, but this is a relatively obscure problem.
//
// I initially tried to use the value `Infinity` here, but somehow when this made its way down into
// the C++ code and was converted to an integer, that integer ended up being zero. So instead we
// use 1e9 (1 billion), which ought to be enough for anyone.
//
// Third-party issues, for reference:
//
//    https://bugs.chromium.org/p/v8/issues/detail?id=5338
//    https://bugs.chromium.org/p/v8/issues/detail?id=3777
//    https://github.com/laverdet/node-fibers/issues/305
import Fiber from "fibers";
Fiber.poolSize = 1e9;

// Special debugging enabled on Blackrock only.
if ("replicaNumber" in Meteor.settings) {
  console.warn("Fiber bomb defense enabled.");

  // TEMPORARY: Monitor the number of fibers created and kill the process any time it goes over
  //   2000. Unfortunately, due to the aforementioned linked list in ThreadDataTable, the process
  //   will become unreasonably slow once the list gets this big. It's better to kill the process
  //   so that it restarts fresh rather than to let the Sandstorm server become unresponsive.
  // TODO(soon): Remove this when the bug is fixed.
  setInterval(() => {
    if (Fiber.fibersCreated > 2000) {
      console.error(
          "Process has allocated more than 2000 concurrent fibers. Due to " +
          "https://bugs.chromium.org/p/v8/issues/detail?id=5338 it will become extremely slow " +
          "unless we restart it. ABORTING");
github yortus / asyncawait / src / mods / fibersHotfix169.js View on Github external
function inc() {
    ++_activeFiberCount;
    if (_activeFiberCount >= _fiberPoolSize) {
        _fiberPoolSize += 100;
        Fiber.poolSize = _fiberPoolSize;
    }
}

/** Decrement the number of active fibers. */
function dec() {
    --_activeFiberCount;
}

// Private state.
//TODO: should this be global, in case multiple asyncawait instances are loaded in the process?
var _fiberPoolSize = Fiber.poolSize;
var _activeFiberCount = 0;
//# sourceMappingURL=fibersHotfix169.js.map
github wekan / wekan / server / authentication.js View on Github external
Meteor.startup(() => {
  // Node Fibers 100% CPU usage issue
  // https://github.com/wekan/wekan-mongodb/issues/2#issuecomment-381453161
  // https://github.com/meteor/meteor/issues/9796#issuecomment-381676326
  // https://github.com/sandstorm-io/sandstorm/blob/0f1fec013fe7208ed0fd97eb88b31b77e3c61f42/shell/server/00-startup.js#L99-L129
  Fiber.poolSize = 1e9;

  Accounts.validateLoginAttempt(function(options) {
    const user = options.user || {};
    return !user.loginDisabled;
  });

  Authentication = {};

  Authentication.checkUserId = function(userId) {
    if (userId === undefined) {
      const error = new Meteor.Error('Unauthorized', 'Unauthorized');
      error.statusCode = 401;
      throw error;
    }
    const admin = Users.findOne({ _id: userId, isAdmin: true });
github yortus / asyncawait / tests / config.fibersHotfix169.js View on Github external
return async(function () {
            if (Fiber.poolSize > peak)
                peak = Fiber.poolSize;
            await(Promise.delay(20));
        });
    }
github yortus / asyncawait / tests / config.fibersHotfix169.js View on Github external
return async(function () {
            if (Fiber.poolSize > peak)
                peak = Fiber.poolSize;
            await(Promise.delay(20));
        });
    }
github yortus / asyncawait / tests / config.fibersHotfix169.js View on Github external
beforeEach(function () {
    config.useDefaults();
    peak = 0;
    Fiber.poolSize = 120;
});
var peak = 0;
github yortus / asyncawait / async / asyncCommon.js View on Github external
var fn = this._queued.pop();
            fn();
        } else {
            ++this._avail;
        }
    };
    Semaphore.unlimited = new Semaphore(10000000);
    return Semaphore;
})();
exports.Semaphore = Semaphore;

/**
* The following functionality prevents memory leaks in node-fibers by actively managing Fiber.poolSize.
* For more information, see https://github.com/laverdet/node-fibers/issues/169.
*/
var fiberPoolSize = Fiber.poolSize;
var activeFiberCount = 0;
function adjustFiberCount(delta) {
    activeFiberCount += delta;
    if (activeFiberCount >= fiberPoolSize) {
        fiberPoolSize += 100;
        Fiber.poolSize = fiberPoolSize;
    }
}

/**
* TODO: ...
*/
var Iterator = (function () {
    /**
    * TODO: ...
    */
github yortus / asyncawait / async / asyncCommon.js View on Github external
function adjustFiberCount(delta) {
    activeFiberCount += delta;
    if (activeFiberCount >= fiberPoolSize) {
        fiberPoolSize += 100;
        Fiber.poolSize = fiberPoolSize;
    }
}
github yortus / asyncawait / src / mods / fibersHotfix169.js View on Github external
function inc() {
    ++_activeFiberCount;
    if (_activeFiberCount >= _fiberPoolSize) {
        _fiberPoolSize += 100;
        Fiber.poolSize = _fiberPoolSize;
    }
}
github yortus / asyncawait / src / mods / fibersHotfix169.js View on Github external
shutdown: function () {
                _fiberPoolSize = Fiber.poolSize;
                _activeFiberCount = 0;
                base.shutdown();
            }
        };