Skip to content

Commit 87d52f3

Browse files
committed
Adding 4th and final post from Simon [deploy site]
1 parent 987166b commit 87d52f3

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
+++
2+
Description = "In the fourth and final post in his series, Simon Stewart continues talking about what's coming in Selenium 4 and reviews what's new in the Selenium Grid."
3+
Title = "The new Selenium Grid"
4+
Date = 2021-02-05
5+
Author = "shs96c"
6+
AuthorLink = "https://twitter.com/shs96c"
7+
tags = ["selenium"]
8+
categories = ["general", "releases"]
9+
+++
10+
11+
>In the fourth and final post in his series, Simon Stewart continues talking about what's
12+
>coming in Selenium 4 and reviews what's new in the Selenium Grid.
13+
14+
We’ve covered a lot of ground in the past few blog posts, including how to contribute to the project, and some
15+
details of what you can expect as a Selenium user. But there’s more to Selenium than just the APIs you use to write
16+
your tests, and one of the big features we’ve not covered yet is the refreshed Selenium Grid: a mechanism that
17+
allows you to distribute your tests across a fleet of machines.
18+
19+
Before going further, it’s always nice to acknowledge where we’ve come from, not only because it’s interesting, but
20+
also because it helps explain the “why” of the refreshed design.
21+
22+
Way back in the mists of time (2008), Jennifer Bevin and Jason Huggins worked on a system called the Selenium Farm
23+
at Google. This was a fleet of machines sitting in a cupboard somewhere that allowed you to run the original
24+
Selenium protocol. This was, of course, at Google scale, so there was more than one cupboard :)
25+
26+
This allowed people at Google to distribute their tests and scale out beyond their individual machines.
27+
This was such a great idea that when Jennifer talked about the Farm at a Selenium meetup, Philippe
28+
Haringou (then at ThoughtWorks) decided to write an Open Source implementation of the same thing,
29+
which he called “Selenium Grid”.
30+
31+
Selenium Grid was a lovely piece of technology, but it had one drawback: it only spoke the original
32+
Selenium RC protocol. That was fine, but WebDriver spoke a different wire protocol, which was called the
33+
JSON Wire Protocol, and folks wanted to be able to use both Selenium RC and WebDriver at the same time.
34+
35+
This is where Francois Reynaud enters the picture. He was working at eBay, reporting to Michael Palotas,
36+
and he had written something like the original Selenium Grid, but which also worked with the JSON Wire
37+
Protocol. They very kindly contributed that work to the Selenium project, and it formed the basis of the
38+
Selenium Grid 2. We decided at the time that the Selenium standalone server would effectively be a
39+
“grid of one”: it would have everything you needed in it to set up a Selenium Grid, as well as to work as
40+
a single standalone server. Merging the code and getting it stable took a while, but thanks to the efforts
41+
of Francois, Kristian Rosenvold, and many others, we merged Grid 2 into the main Selenium project and shipped
42+
Selenium 2 in 2011.
43+
44+
Even if 2011 doesn’t feel that long ago, the modern world has changed quite significantly. In 2011, we didn't
45+
have Docker. We didn't have Kubernetes, we didn't really have AWS. So, the Selenium Grid didn't know that those
46+
things were coming in, and wasn't written to take advantage of them. Fortunately, we did have virtual machines
47+
back then, and the Grid 2 had been designed to be able to support them.
48+
49+
This was the hook that an excellent project called Zalenium. Developed by Diego Molina, Zalenium added a really
50+
nice UI and support for Docker and Kubernetes—all built on top of the Grid 2. This has allowed the Selenium Grid to
51+
continue to be relevant and useful to this day, which is an amazing achievement.
52+
53+
But, like I said, it took us time to stabilise Grid 2: about six months of hard work, largely led by Kristian.
54+
That’s because while Grid 2 was sophisticated, the code was hard to read and hard to maintain—and very few people
55+
could do that. Worse, the merging of the Grid 2 and the original Selenium server was pretty crude; effectively
56+
there were two separate servers shipped in the same binary. This led to problems occurring in the Grid but not
57+
when run in standalone mode, and vice versa.
58+
59+
With Selenium 4 we’ve decided to bite the bullet and address these three concerns. Firstly, we want something that
60+
was easier to work on and maintain. Secondly, we want to merge the servers into a single unit. Thirdly, we want
61+
something that will take advantage of the world of modern infrastructure we have available to us now, not just in
62+
the form of Docker and Kubernetes, but also to be able to use emerging technologies such as distributed tracing.
63+
64+
To do this, we looked at the functionality the Grid provided, and to model each piece as a component that we can
65+
either run “in memory” (allowing us to have a single standalone server), or in a more distributed way, allowing
66+
the “hub and node” architecture that we’re familiar with from the original Selenium Grid, to a fully distributed
67+
design.
68+
69+
The first component is the “router”. It serves as the entry point to the Grid. You can expose it to the internet
70+
and it directs requests to the Grid. It’s designed to be stateless, and so you can add more to Grid as you find
71+
you need to.
72+
73+
When the router sees a new session request, it places it on a “session queue.” The session queue is read by a
74+
component called the “distributor,” which maintains a model of all the places in the Grid where a session could be
75+
run: we call them “slots”. The slots are hosted by components called “nodes,” and each node can have one or more
76+
slots. When the distributor pulls a new session request from the queue, it identifies the most appropriate slot
77+
to use, and forwards the request to the node which owns the slot. Once the node has started the session, the
78+
distributor puts the session ID and the URL of the Node that is running the test into the “session map”—you can
79+
think of the session map as being a simple map of a session ID to URL—and the new session response is sent
80+
back to the waiting test.
81+
82+
Requests for running sessions (that is, for most webdriver calls!) are handled slightly differently. The router
83+
will use the session map to look up which node to forward the request to, avoiding the need to involve the
84+
distributor entirely. This means that you can just keep adding nodes to the Grid, and there are fewer bottlenecks
85+
in the architecture to slow your requests down.
86+
87+
Conceptually, there are these five moving pieces within the Grid. But there's actually a sixth one, which is a
88+
message bus. The five Grid components communicate internally through the message bus, but the actual components
89+
that you need to think about when you're thinking about the Grid are the Router, Session Queue, Distributor, and
90+
Nodes.
91+
92+
When you run Selenium Grid 4 in “standalone” mode, you actually get a “grid of one”. We wire up all these
93+
components in a single process, but they’re all still there.
94+
95+
You can also run it in the traditional Hub and Node approach that you've seen with Selenium Grid 2, where you
96+
fire up a Hub and a Node and it registers. If you've used Selenium Grid recently, that's probably the architecture
97+
that you're familiar with. In this case, most of the components (the router, session queue, and distributor) are
98+
running in the Hub, and the Nodes run the sessions themselves.
99+
100+
What’s new with Grid 4 is that you can go into a fully distributed mode if you want to. Typically, you would want
101+
to use something like Kubernetes for this, and some of the key components are designed to store data using a
102+
database or Redis for better reliability and scalability.
103+
104+
Something to note is that when running a distributed Grid, it becomes really difficult to figure out what is
105+
happening, particularly when something goes wrong. To alleviate that problem, we have adopted Open Telemetry to
106+
bring observability into the Grid. What do we mean by observability? It simply means that we want to be able to
107+
see everything that happens.
108+
109+
Finally, we’d like to expose information about the running Grid in meaningful and useful ways. The original
110+
Grid supported both JMX (a Java management API) and an HTML-based console. While nice, this didn’t make it easy
111+
to query specific areas of the Grid that you might be interested in that weren’t surfaced by the UI (for example,
112+
how many slots are available, or to find out which node a particular session is running on) To provide more
113+
flexibility, we’ve chosen to provide a GraphQL endpoint for the Grid. To ensure that GraphQL endpoint is
114+
sufficiently flexible, we’re building the new Grid console using it. That should allow you to also extract useful
115+
metrics and information from the Grid for your monitoring needs.
116+
117+
Those are some highlights of the new Selenium Grid. What are you the most excited about?
118+
119+
*This was originally posted at https://saucelabs.com/blog/whats-coming-in-selenium-4-the-new-selenium-grid*

0 commit comments

Comments
 (0)