Mahsum Akbas
Mahsum Akbas

Reputation: 1583

Use infinite maxInstance in Selenium Grid

i started Selenium Grid as Hub with default parameters:

java -jar selenium-server-standalone-3.4.0.jar -role hub

then i started a node with default parameters:

java -Dwebdriver.chrome.driver=C:\selenium\driver\chromedrive r.exe -jar selenium-server-standalone-3.4.0.jar -role node -hub http://localhost:4444/grid/register

when i checked localhost:4444 from web browser, i see following screen

enter image description here

As expected, there is allowing for 5 chrome instances.

after i execute my test scripts 5 times, i see following screen(warning):

enter image description here

So, my question is: When these slots will be free? or, is there any way to set infinite maxInstance value?

Upvotes: 1

Views: 3036

Answers (1)

Krishnan Mahadevan
Krishnan Mahadevan

Reputation: 14736

In the ideal scenario, after a test runs to completion it should free up the TestSlot it occupies in the Grid. The TestSlot is essentially equivalent to one browser icon you see on the Grid console.

From what you have shared, here's what I am inferring.

  • Your node supports 5 concurrent sessions across all browser flavors. What this means is that lets say you ran 6 tests (4 Chrome tests and 2 Firefox tests), only 5 will run and one of your tests will stand in queue [which is what you are seeing in your screen when the grid says 1 requests waiting for a slot to be free]

If your test is properly calling RemoteWebDriver.quit() at the end of the test, then once any of your 5 tests runs to completion, the sixth one standing in queue will be picked up for execution. You don't need to do anything extra.

But if your tests weren't calling the quit() method or if your test itself crashed (for e.g., you killed the JVM that is running your tests or if you were running the tests from an IDE, you pressed the stop button of your IDE) then those tests will become orphaned tests.

If you haven't tweaked any of the values, by default the grid will do the following :

  • The hub will run through all the active sessions that it is aware of to check if any of them are hung etc., every 5 seconds. This value is controlled by the flag -cleanUpCycle
  • The node will look for test sessions that have remained inactive for 1800 seconds and clean them off.

So to answer your first question,

When these slots will be free?

They will be free only after 30 minutes. This can be controlled by using the following properties at the Hub side.

  • -browserTimeout in seconds : number of seconds a browser session is allowed to hang while a WebDriver command is running (example: driver.get(url)). If the timeout is reached while a WebDriver command is still processing, the session will quit. Minimum value is 60. An unspecified, zero, or negative value means wait indefinitely. Default: 0
  • -cleanUpCycle in milliseconds : specifies how often the hub will poll running proxies for timed-out (i.e. hung) threads. Must also specify timeout option.Default: 5000 (5 seconds)
  • -timeout, -sessionTimeout in seconds : Specifies the timeout before the server automatically kills a session that hasn't had any activity in the last X seconds. The test slot will then be released for another test to use. This is typically used to take care of client crashes. For grid hub/node roles, cleanUpCycle must also be set. Default: 1800

You can refer to this SO reply of mine for additional details.

The second question that you had

is there any way to set infinite maxInstance value?

Yes there is a way to do this, but this will essentially kill your Grid infrastructure. For example lets say you set the value to 1000, this will cause the hub to spin off 1000 concurrent browser instances on your node. That in my opinion is a recipe for disaster.

You should instead try leveraging the cleanup parameters that I shared above to ensure that there are no stale tests hung.

In order to increase the max sessions, you would need to do the following :

  1. Use the parameter -maxSession and specify a value (default is 5). The value that you give here will be the maximum number of browsers (across browser flavors) that will get opened at the same time at any given point in your node.
  2. In order to control things a bit more further on a per browser flavor, you can specify a maxInstances per browser in a node configuration file.

For e.g., if you had a node configuration file as below:

{
  "capabilities":
  [
    {
      "browserName": "firefox",
      "maxInstances": 4,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "chrome",
      "maxInstances": 11,
      "seleniumProtocol": "WebDriver"
    }
  ],
  "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
  "maxSession": 15,
  "port": 5555,
  "register": true,
  "registerCycle": 5000,
  "hub": "http://localhost:4444",
  "nodeStatusCheckTimeout": 5000,
  "nodePolling": 5000,
  "role": "node",
  "unregisterIfStillDownAfter": 60000,
  "downPollingLimit": 2
}

This would cause your node to support a maximum of 15 concurrent browser instances to be opened but within those 15 instances only 4 firefox instances at the max can be opened and 11 chrome instances can be opened. You would use -nodeConfig to specify the path of the above JSON configuration file.

You can refer to this SO reply of mine to learn what are all the parameters that are available in the Standalone, Hub and Node mode.

Here's a template file from the selenium codebase itself.

Hope that answers your question.

Upvotes: 2

Related Questions