Skip to content

Commit

Permalink
Abstract BIGBLUEBOT_POOL from configuration
Browse files Browse the repository at this point in the history
BREAKING CHANGE

Browsers' pool has been a burden for newcomers for a long time.
This implement an automatic pool size calculation based on the number
of bots and the browser capacity threshold defined at config's property
`browser.pool.size.max`.
  • Loading branch information
pedrobmarin committed Apr 15, 2021
1 parent 16f95b0 commit e0a965a
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 28 deletions.
3 changes: 0 additions & 3 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ BIGBLUEBOT_HOST=
# <string> External browser path. Defaults to null.
# BIGBLUEBOT_BROWSER=

# <number> Browser processes. Defaults to 1.
# BIGBLUEBOT_POOL=

# <string> Endpoint browser websocket. Defaults to null.
# BIGBLUEBOT_ENDPOINT=

Expand Down
16 changes: 0 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,6 @@ BIGBLUEBOT_SECRET=yourbigbluebuttonsecret
- [optional] number of bots to join the room
```
BIGBLUEBOT_BOTS=1
```
By default, there is a maximum of 10 bots per browser in the pool. to increase that
number, add more browsers to the pool using `BIGBLUEBOT_POOL` or adjust the maximum pool
size at `config/config.json`:
```
"pool": {
"population": 1,
"size": {
"min": 1,
"max": 10
}
}
```
- [optional] time (milliseconds) between bots to join
```
Expand All @@ -66,10 +54,6 @@ BIGBLUEBOT_LIFE=60000
- [optional] external browser to be used
```
BIGBLUEBOT_BROWSER=/path/to/your/browser
```
- [optional] number of browser processes
```
BIGBLUEBOT_POOL=1
```
- [optional] endpoint browser websocket to be used
```
Expand Down
1 change: 0 additions & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"height": 720
},
"pool": {
"population": 1,
"size": {
"min": 1,
"max": 10
Expand Down
2 changes: 0 additions & 2 deletions lib/conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const {
BIGBLUEBOT_WAIT,
BIGBLUEBOT_LIFE,
BIGBLUEBOT_BROWSER,
BIGBLUEBOT_POOL,
BIGBLUEBOT_ENDPOINT,
BIGBLUEBOT_TOKEN,
BIGBLUEBOT_SCREENSHOT,
Expand All @@ -34,7 +33,6 @@ if (BIGBLUEBOT_WAIT) custom.bot.wait = parseInt(BIGBLUEBOT_WAIT);
if (BIGBLUEBOT_LIFE) custom.bot.life = parseInt(BIGBLUEBOT_LIFE);

if (BIGBLUEBOT_BROWSER) custom.browser.path = BIGBLUEBOT_BROWSER;
if (BIGBLUEBOT_POOL) custom.browser.pool.population = parseInt(BIGBLUEBOT_POOL);
if (BIGBLUEBOT_ENDPOINT) custom.browser.endpoint = BIGBLUEBOT_ENDPOINT;
if (BIGBLUEBOT_TOKEN) custom.browser.token = BIGBLUEBOT_TOKEN;
if (BIGBLUEBOT_IGNORE_HTTPS_ERRORS) custom.browser.ignoreHTTPSErrors = parseBoolean(BIGBLUEBOT_IGNORE_HTTPS_ERRORS);
Expand Down
7 changes: 4 additions & 3 deletions lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ const factory = {

const size = { max: browser.pool.size.max, min: browser.pool.size.min };
const browsers = genericPool.createPool(factory, size);
const population = Math.ceil(bot.population / browser.pool.size.max);

module.exports = {
browsers: browsers,
population: browser.pool.population,
size: Math.ceil(bot.population / browser.pool.population),
browsers,
population,
size: Math.ceil(bot.population / population),
};
6 changes: 3 additions & 3 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ const run = async (actions, options = {}) => {
const locale = await util.locale(options);

let browsers = [];
for (let i = 0; i < pool.size; i++) {
for (let i = 0; i < pool.population; i++) {
logger.debug(`Opening browser`);

// Open a new browser process
browsers.push(pool.browsers.acquire().then(async browser => {
let promises = [];
for (let j = 0; j < pool.population; j++) {
for (let j = 0; j < pool.size; j++) {
let username;
await util.delay(bot.wait);

Expand Down Expand Up @@ -75,7 +75,7 @@ const run = async (actions, options = {}) => {
}));

// Sync the bots entrance
await util.delay(bot.wait * pool.population);
await util.delay(bot.wait * pool.size);
}

await Promise.all(browsers).finally(async () => {
Expand Down

0 comments on commit e0a965a

Please sign in to comment.