Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: maxSessions config value larger then CPU count is ignored #2610

Open
Zlaman opened this issue Jan 23, 2025 · 10 comments
Open

[🐛 Bug]: maxSessions config value larger then CPU count is ignored #2610

Zlaman opened this issue Jan 23, 2025 · 10 comments

Comments

@Zlaman
Copy link

Zlaman commented Jan 23, 2025

What happened?

My VM has 4 CPU's. I am starting selenium/hub and selenium/node-docker with below commands.
config.toml has override-max-sessions = true and max-sessions = 10
As per the logs from selenium/node-docker (see them below) - Max sessions set to 10, but another line is Mapping Capabilities {browserName: chrome, platformName: linux, se:downloadsEnabled: true} to docker image selenium/standalone-chrome:latest **4 times**
It results in "maxSessions": 4 while expected is 10 as per config.toml

curl localhost:4444/wd/hub/status

{
  "value": {
    "ready": true,
    "message": "Selenium Grid ready.",
    "nodes": [
      {
        "id": "0f578f41-ac9c-484a-b06d-6777a8384a4a",
        "uri": "http:\u002f\u002f172.18.0.3:5555",
        "maxSessions": 4,
        "sessionTimeout": 300000,
        "osInfo": {
          "arch": "amd64",
          "name": "Linux",
          "version": "5.15.167.4-microsoft-standard-WSL2"
        },
        "heartbeatPeriod": 60000,
        "availability": "UP",
        "version": "4.27.0 (revision d6e718d)",
        "slots": [
          {
            "id": {
              "hostId": "0f578f41-ac9c-484a-b06d-6777a8384a4a",
              "id": "9ecdd10f-ac80-4a06-b1c2-cc1ced9232d4"
            },
            "lastStarted": "1970-01-01T00:00:00Z",
            "session": null,
            "stereotype": {
              "browserName": "chrome",
              "platformName": "linux",
              "se:downloadsEnabled": true
            }
          },
          {
            "id": {
              "hostId": "0f578f41-ac9c-484a-b06d-6777a8384a4a",
              "id": "a58f5da3-83ce-422d-b390-e4bd63203cc2"
            },
            "lastStarted": "1970-01-01T00:00:00Z",
            "session": null,
            "stereotype": {
              "browserName": "chrome",
              "platformName": "linux",
              "se:downloadsEnabled": true
            }
          },
          {
            "id": {
              "hostId": "0f578f41-ac9c-484a-b06d-6777a8384a4a",
              "id": "592f3a21-3c70-4258-b4eb-13a92125a6dd"
            },
            "lastStarted": "1970-01-01T00:00:00Z",
            "session": null,
            "stereotype": {
              "browserName": "chrome",
              "platformName": "linux",
              "se:downloadsEnabled": true
            }
          },
          {
            "id": {
              "hostId": "0f578f41-ac9c-484a-b06d-6777a8384a4a",
              "id": "9a7759c7-0d04-4b0f-a420-5f08d2f7d58d"
            },
            "lastStarted": "1970-01-01T00:00:00Z",
            "session": null,
            "stereotype": {
              "browserName": "chrome",
              "platformName": "linux",
              "se:downloadsEnabled": true
            }
          }
        ]
      }
    ]
  }
}

I have also tried to start selenium-node-docker with extra environment variables
-e SE_NODE_MAX_SESSIONS=10
-e SE_NODE_OVERRIDE_MAX_SESSIONS=true
but it does not help as well.

Command used to start Selenium Grid with Docker (or Kubernetes)

docker network create grid
docker run -d -p 4442-4444:4442-4444 --network grid --name selenium-hub selenium/hub:latest
docker run -d --network grid --name selenium-node-docker \
    -e SE_EVENT_BUS_HOST=selenium-hub \
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 \
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
    -e SE_BROWSER_ARGS_DISABLE_DSHM=--disable-dev-shm-usage \
    -e SE_START_VNC=false \
    -e SE_START_NO_VNC=false \
    -e SE_ENABLE_TRACING=false \
    -e SE_NODE_DOCKER_CONFIG_FILENAME=docker.toml \
    -v /home/user/selenium/config.toml:/opt/selenium/docker.toml:ro \
    -v /home/user/selenium/assets:/opt/selenium/assets \
    -v /home/user/selenium/downloads:/home/seluser/Downloads \
    -v /var/run/docker.sock:/var/run/docker.sock \
    selenium/node-docker:latest

# config.toml
[docker]
configs = [
    "selenium/standalone-chrome:latest", '{"browserName": "chrome"}'
]
host-config-keys = ["Binds"]
url = "http://127.0.0.1:2375"
video-image = "selenium/video:latest"

[node]
detect-drivers = false
enable-managed-downloads = true
override-max-sessions = true
max-sessions = 10

Relevant log output

selenium/node-docker
Starting Selenium Grid Node Docker...
2025-01-23 04:21:37,253 INFO success: socat entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2025-01-23 04:21:37,253 INFO success: selenium-grid-docker entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
Appending Selenium option: --log-level INFO
Appending Selenium option: --http-logs false
Appending Selenium option: --structured-logs false
Appending Selenium option: --tracing false
Tracing is disabled
04:21:37.483 INFO [LoggingOptions.configureLogEncoding] - Using the system default encoding
04:21:37.485 INFO [LoggingOptions.getTracer] - Using null tracer
04:21:37.507 INFO [UnboundZmqEventBus.<init>] - Connecting to tcp://selenium-hub:4442 and tcp://selenium-hub:4443
04:21:37.528 INFO [UnboundZmqEventBus.<init>] - Sockets created
04:21:38.529 INFO [UnboundZmqEventBus.<init>] - Event bus ready
04:21:38.578 INFO [NodeServer.createHandlers] - Reporting self as: http://172.18.0.3:5555
04:21:38.580 INFO [LoggingOptions.getTracer] - Using null tracer
04:21:38.592 INFO [NodeOptions.getSessionFactories] - Detected 4 available processors
04:21:38.593 WARN [NodeOptions.getSessionFactories] - Overriding max recommended number of 4 concurrent sessions. Session stability and reliability might suffer!
04:21:38.594 WARN [NodeOptions.getSessionFactories] - One browser session is recommended per available processor. Safari is always limited to 1 session per host.
04:21:38.594 WARN [NodeOptions.getSessionFactories] - Overriding this value for Internet Explorer is not recommended. Issues related to parallel testing with Internet Explored won't be accepted.
04:21:38.594 WARN [NodeOptions.getSessionFactories] - Double check if enabling 'override-max-sessions' is really needed
04:21:38.594 WARN [NodeOptions.getSessionFactories] - Max sessions set to 10
04:21:38.814 INFO [V141Docker.isContainerPresent] - Checking if container is present: e67e0b9cbd42
04:21:38.923 INFO [Docker.getImage] - Obtaining image: selenium/standalone-chrome:latest
04:21:38.926 INFO [V141Docker.getImage] - Listing local images: Reference{domain='docker.io', name='selenium/standalone-chrome', tag='latest', digest='null'}
04:21:38.935 INFO [Docker.getImage] - Obtaining image: selenium/video:latest
04:21:38.935 INFO [V141Docker.getImage] - Listing local images: Reference{domain='docker.io', name='selenium/video', tag='latest', digest='null'}
04:21:38.938 INFO [Docker.getImage] - Obtaining image: selenium/video:latest
04:21:38.938 INFO [V141Docker.getImage] - Listing local images: Reference{domain='docker.io', name='selenium/video', tag='latest', digest='null'}
04:21:38.942 INFO [Docker.getImage] - Obtaining image: selenium/standalone-chrome:latest
04:21:38.942 INFO [V141Docker.getImage] - Listing local images: Reference{domain='docker.io', name='selenium/standalone-chrome', tag='latest', digest='null'}
04:21:38.947 INFO [DockerOptions.lambda$getDockerSessionFactories$2] - Mapping Capabilities {browserName: chrome, platformName: linux, se:downloadsEnabled: true} to docker image selenium/standalone-chrome:latest 4 times
04:21:38.954 INFO [Node.<init>] - Binding additional locator mechanisms: relative
04:21:39.025 INFO [NodeServer$2.start] - Starting registration process for Node http://172.18.0.3:5555
04:21:39.026 INFO [NodeServer.execute] - Started Selenium node 4.27.0 (revision d6e718d): http://172.18.0.3:5555
04:21:39.031 INFO [NodeServer$2.lambda$start$1] - Sending registration event...
04:21:39.193 INFO [NodeServer.lambda$createHandlers$2] - Node has been added

Operating System

Ubuntu

Docker Selenium version (image tag)

selenium/hub:4.28.0-20250120 selenium/node-docker:4.28.0-20250120

Selenium Grid chart version (chart version)

No response

Copy link

@Zlaman, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@VietND96
Copy link
Member

Ok, looks like the TOML config applies for the node-docker but doesn't apply for the browser node defined inside.
In this case, can you set ENV vars when starting node-docker SE_NODE_OVERRIDE_MAX_SESSIONS=true and SE_NODE_MAX_SESSIONS=10

@Zlaman
Copy link
Author

Zlaman commented Jan 23, 2025

Thanks, I tried starting selenium/node-docker with below command, but it still results in "maxSessions": 4 from wd/hub/status and same log output from docker logs selenium-node-docker command

docker run -d --network grid --name selenium-node-docker \
    -e SE_EVENT_BUS_HOST=selenium-hub \
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 \
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
    -e SE_BROWSER_ARGS_DISABLE_DSHM=--disable-dev-shm-usage \
    -e SE_START_VNC=false \
    -e SE_START_NO_VNC=false \
    -e SE_ENABLE_TRACING=false \
    -e SE_NODE_MAX_SESSIONS=10 \
    -e SE_NODE_OVERRIDE_MAX_SESSIONS=true \
    -e SE_NODE_DOCKER_CONFIG_FILENAME=docker.toml \
    -v /home/zalman/selenium/config.toml:/opt/selenium/docker.toml:ro \
    -v /home/zalman/selenium/assets:/opt/selenium/assets \
    -v /home/zalman/selenium/downloads:/home/seluser/Downloads \
    -v /var/run/docker.sock:/var/run/docker.sock \
    selenium/node-docker:latest

@VietND96
Copy link
Member

This one let me check again.
However, you are using dynamic grid, where max-sessions doesn't matter. Although there are 4 sessions per Node, but the number of Node is dynamic. For example you submitted 10 requests, expected that there are 3 Nodes with 12 sessions available to pickup those.

@Zlaman
Copy link
Author

Zlaman commented Jan 23, 2025

Thank you. I am using only one node, I guess as the max-sessions parameter is under [node] section, this is a setting per node, not the global setting per whole hub. Node logs also state Max sessions set to 10 but then Mapping Capabilities {browserName: chrome, platformName: linux, se:downloadsEnabled: true} to docker image selenium/standalone-chrome:latest **4 times**

@VietND96
Copy link
Member

With your requirement, I think just a standalone image is suitable for you.

docker run -p 4444:4444 -e SE_NODE_OVERRIDE_MAX_SESSIONS=true -e SE_NODE_MAX_SESSIONS=10 selenium/standalone-chrome:latest

No need to have node-docker layer.

@Zlaman
Copy link
Author

Zlaman commented Jan 23, 2025

I need an ability to record videos from every session, not sure it is possible to use selenium/standalone-chrome for that, it will only record video from one of the sessions that is currently visible on screen

@VietND96
Copy link
Member

Currently, multiple sessions are opening the browsers on the same screen, and recording only listens on that screen.
We can create multiple VNC displays. However, we have to control a session that can open the browser on a unique display and then notify the recorder, which displays the port for recording. It would be a complex process that requires WebDriver and tools to work together.
That is why in Dynamic Grid (node-docker), we keep the browser node spawned up, and each node takes a single session, where the session can be recorded correctly.

@diemol
Copy link
Member

diemol commented Jan 24, 2025

This is a duplicate of #1817

@Zlaman
Copy link
Author

Zlaman commented Jan 24, 2025

Thanks @VietND96 , that's why I am using Dynamic Grid.

Thanks @diemol I see that #1817 is closed without resolution. I think that the situation I am facing is still a bug because it does not correspond to this documentation https://github.com/SeleniumHQ/docker-selenium?tab=readme-ov-file#increasing-session-concurrency-per-container

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants