Dmitri Tikhanski is a Contributing Writer to the BlazeMeter blog.

Become a JMeter and Continuous Testing Pro

Start Learning
Slack

Test Your Website Performance NOW! |

arrowPlease enter a URL with http(s)
Jun 15 2020

Load Testing Graph Databases Using Bolt Protocol With Apache JMeter

Starting from JMeter 5.2, support for Bolt protocol was added to JMeter distribution bundle. Bolt protocol was developed for use in the Neo4j graph database. However, it can theoretically be used in JMeter for load testing any other server which understands OpenCypher queries sent over Bolt protocol transport.

 

In this article, you will learn how to use the Bolt Connection Configuration and Bolt Request sampler in order to establish Neo4j database connectivity and run OpenCypher queries against the database.

 

The article assumes that you have a Neo4j database instance running locally. So if you don’t have a local (or remote) instance, you will need to download Neo4j and install it onto your local or remote machine.

 

1. Creating a New Graph

 

First, you will need to create a new database to work with. The most convenient way of managing Neo4j data is with Neo4j Desktop. Just click the “Create a Local Graph” button in the project of your choice:

 

Load Testing Graph Databases Using Bolt Protocol With Apache JMete

 

2. Provide Graph Name and Password

 

The next step is to provide the name of your graph and secure it with the password. For this demo, we’ll use BlazeMeter for both:

 

Load Testing Graph Databases Using Bolt Protocol With Apache JMeter

 

When you click the “Create” button, the Neo4j database will create the new graph with the specified name and password. Make sure to use a Neo4j version that is above 3.0, otherwise, there will be no Bolt protocol support.

 

3. Starting the Graph

 

By default, the newly created graph is in the stopped state. No connections can be made at this stage, you will need to click the “Start” button to kick off the graph.

 

Load Testing Graph Databases Using Bolt Protocol With Apache JMete

 

4. Open Neo4j Browser

 

Wait until the graph becomes “Active” and then click on the “Manage” button.

 

Load Testing Graph Databases Using Bolt Protocol With Apache JMete

 

On the next screen, you will see some details including version, status, and endpoints. You should be interested in “Bolt port” which is 7687 by default. This will be required later on for configuring the graph connection in JMeter.

 

Now you can click the “Open Browser” button.

 

Load Testing Graph Databases Using Bolt Protocol With Apache JMete

 

A new window with Neo4j Browser will appear. The Neo4j browser provides browser-based UI allowing visualization of your graph data, running queries, etc.

 

5. Importing test data

 

By default, the newly created graph is empty. You can still run queries against it, but they will return empty results or errors so now it’s time to load the graph with some sample test data. The most commonly used dataset is probably Northwind database, a set of tables with indices and relations originally developed by Microsoft for testing SQL Server 2000 and became a some form of sample test data standard.

 

In Neo4j, you can execute the following command in the Neo4j browser:

:play northwind graph

 

The command will open a window with instructions for migrating the data from RDBMS in general and some particular OpenCypher queries. This will load the Northwind dataset into your graph so you can have some sample data to play with. Just follow the instructions and you will get the data loaded into the graph.

 

Load Testing Graph Databases Using Bolt Protocol With Apache JMete

 

In this example, we stopped at the first query on page 4 which looks like:

MATCH (s:Supplier)-->(:Product)-->(c:Category)

RETURN s.companyName as Company, collect(distinct c.categoryName) as Categories

 

And returns the following data:

 

Load Testing Graph Databases Using Bolt Protocol With Apache JMete

 

6. Executing Bolt Request in JMeter

 

Now it’s time to open JMeter. If you’re new to the JMeter tool, then you should walk through How to Get Started With JMeter: Part 1 - Installation & Test Plans article or even attend at least the first few lessons of free online JMeter Academy as the below part of the article will mostly cover Bolt protocol specifics.

 

Assuming you have a Thread Group with 1 thread (virtual user) and 1 iteration, add a Bolt Connection Configuration and provide Bolt endpoint (the one from the Neo4j Browser) and the password you specified at Step 2. The default username is neo4j. If you have a local Neo4j installation, the endpoint will be bolt://localhost:7687

 

Load Testing Graph Databases Using Bolt Protocol With Apache JMete

 

Now you need to add a Bolt Request sampler to send the query to the Neo4j database.

 

Load Testing Graph Databases Using Bolt Protocol With Apache JMete

 

You can also set Record Query Results dropdown to True to be able to observe the returned data using View Results Tree listener. 

 

Assuming everything is done correctly, you should be able to execute the request and see the returned records:

 

Load Testing Graph Databases Using Bolt Protocol With Apache JMete

 

The number of returned records should be the same as the same query executed in the Neo4j browser.

 

7. Parameterizing Bolt Request in JMeter

 

Now let’s amend the original query and filter the results so the query will return only categories for supplier company Pavlova. The new OpenCypher query will look like:

 

MATCH (s:Supplier {companyName: 'Pavlova'})-->(:Product)-->(c:Category)

RETURN s.companyName as Company, collect(distinct c.categoryName) as Categories

 

Load Testing Graph Databases Using Bolt Protocol With Apache JMete

 

As per Bolt Request sampler documentation:

 

It is strongly advised to use query parameters, allowing the database to cache and reuse execution plans.

 

You should move your filter expression to Params section of the Bolt Request sampler instead of inlining it into the query.

 

The Query section needs to look like this:

 

MATCH (s:Supplier {companyName: $companyName})-->(:Product)-->(c:Category)

RETURN s.companyName as Company, collect(distinct c.categoryName) as Categories

 

And the Params section should have the declaration of the companyName parameter:

{"companyName" : "Pavlova"}

 

Load Testing Graph Databases Using Bolt Protocol With Apache JMete

 

Now let’s run the query once again:

 

Load Testing Graph Databases Using Bolt Protocol With Apache JMete

 

As you can see, only one company is returned now and others are filtered out.

 

8. Additional Information

 

Neo4j driver version

 

As of JMeter 5.2.1, the shipped Neo4j driver version is 1.7.5. If you need to test a newer Neo4j database, you might need to update the driver in JMeter Classpath (but there is a certain risk that the new driver API will not be compatible with existing Bolt test elements code).

 

Neo4j connection pool

 

You might be aware that establishing a connection is quite an “expensive” operation. Therefore, it’s recommended to go for a Connection Pool pattern so that a pool of connections is established once. This way, the thread which needs to perform an operation takes a next available connection from the pool instead of establishing a new one and closing the connection after the request.

 

As of JMeter 5.2.1, the underlying connection pool is controlled by the neo4j-java-driver and for version 1.7.5 the maximum number of connections in the pool is 100.

 

I hope that this article will help you to conduct your Neo4j database load test faster and easier. If anything remains unclear, you can always reach out to us via the comments section below -where you can ask your questions and share any form of feedback.

   
arrowPlease enter a URL with http(s)

Interested in writing for our Blog?Send us a pitch!