Performance Testing Neo4j database using Bolt Protocol in Apache JMeter

Performance Testing Neo4j database using Bolt Protocol in Apache JMeter | Apache JMeter 5.2 is out now. You can check out my article here. If you prefer video format, you can check it out my YouTube channel. New protocol called Bolt has been introduced in this newer version of JMeter to test the Neo4j database using cypher queries. This blog post helps you to get started with performance test scripting bolt protocol in Apache JMeter 5.2.

Here is my YouTube video which gives you an overview about what’s new in Apache JMeter.

What is Bolt?

Bolt is a 2008 American computer animated comedyadventure film produced by Walt Disney Animation Studios and released by Walt Disney Pictures.

Bolt - animated film character
Bolt – animated film character

No, I am not talking about your favorite character from the feature film Bolt :) I am talking about Bolt Protocol.

What is Bolt Protocol?

Bolt is light weight client-server protocol designed for database applications. Client will be sending out the queries basically a statement with parameters and the server will respond to the query.

Bolt Protocol originally authored by Neo4j graph database team. You can check it out https://boltprotocol.org/ for more details.

The recommended default port of bolt is 7687 which communicates over TCP or WebSocket connection.

Prerequisite

If your project has Neo4j, you can use the credentials directly in JMeter and test your queries which we are going to see it in a moment. But those who do not have Neo4j, please read on. Others, you can skip this section and download only Apache JMeter 5.2.

  1. Download Apache JMeter 5.2 and validate the checksum
  2. Neo4j Community Edition and validate the checksum

The version Neo4j which we are going to use is 3.5.12 for Windows OS.

How to install Neo4j Community Edition in Windows OS?

Follow the below steps to install Neo4j Community Edition in Windows 10:

  1. After downloading the zip file from the above link and extract it.
  2. Open cmd prompt and navigate to the folder where you extracted the zip contents.
  3. Change the directory to bin folder by entering the command cd bin
  4. Then enter the command neo4j.bat console as shown below and hit enter
Performance Testing Neo4j database using Bolt Protocol in Apache JMeter
Performance Testing Neo4j database using Bolt Protocol in Apache JMeter – Starting neo4j database

Neo4j is up and running at http://localhost:7474 by default.

Launch the Neo4j in your favorite browser. When you login first, you need to enter the default credentials neo4j/neo4j and it will prompt you to change the default credentials.

Now, let’s load up some demo data to Neo4j.

Enter :play movies command and hit the run button as shown below.

Click on the right arrow as shown below.

It will display the CREATE code block, you need to click on it which will paste the code to the query box, then you need to hit enter. This will create demo data for you to play.

Below is the demo data which is ready for us to play with JMeter.

Performance Testing Neo4j database

I assume that you have some experience in JMeter by creating a Thread Group, adding HTTP Requests, View Results Tree.

Download JMeter 5.2, Extract the zip file, and launch JMeter by navigating to bin > jmeter.bat

Add the below elements to the Test Plan.

  1. Thread Group
  2. Bolt Connection Configuration (under Config Element)
  3. Bolt Request (under Sampler)
  4. View Results Tree (under Listener)

Save the test plan with a valid name.

In Bolt Connection Configuration element, you need to enter your Neo4j URI and credentials.

Important Note: The Console port number is 7474, but the Bolt communicates over 7687.

Bolt Connection Configuration

We are all set to send the cypher queries using Bolt Request. Let us retrieve 25 Movie names from the Neo4j database.

Tip : You could find the neo4j-java-driver-1.7.5.jar in your lib folder.

Click on Bolt Request and enter the below query in Cypher Statement.

MATCH (n:Movie) RETURN n LIMIT 25

Delete the default text in the Params field.

Click on Run button and head to View Results Tree to see the result. If you to Response Body as shown, you could see the Records: Skipped

Response Body of Bolt Request
Response Body of Bolt Request

That is because in the Bolt Request default value for Record Query Results set to false. Let us set the flag to true and re-run the test plan.

Record Query Results
Record Query Results

Now we are getting the records as node which will not be very helpful. Let’s fix the cypher statement.

Bolt Request with Records
Bolt Request with Records

Use the below cypher statement in the Bolt Request and execute again.

MATCH (n:Movie) return n.title limit 25

Now you can see the actual movie names as shown below.

Bolt Request Response with Movie names
Bolt Request Response with Movie names

Important Note: You need to use Record Query Results as true only for unit testing. If you enable it during the load test, it will cause memory overhead. Use it wisely.

Every bolt request uses a connection from the pool, at this moment the connection pool size is 100 which is not configurable.

If you add the Aggregate Report, the response time is the round trip time between the cypher query execution time and the time to consume the results to send back.

Bolt Request Response Time = (Cypher Query Execution Time + Results Processing Time to send back)

GitHub Repository

Please check my GitHub repository for the sample Bolt test plan.

Conclusion

By leveraging Bolt Request Sampler in Apache JMeter 5.2 you can easily send cypher statement to test the Neo4j graph database. The Bolt Request sampler is not matured enough where you cannot configure the pool size. But eventually, it will mature enough to test the graph database.

Image Credit for Bolt from Wikipedia

About the Author

3 thoughts on “Performance Testing Neo4j database using Bolt Protocol in Apache JMeter”

  1. Sir, I wanted to do load testing on a rest api , that is used to insert data into Neo4j db. Do you know a way to do this using jmeter ?

    Reply
  2. Hi Naveen,
    Your blog on Neo4j DB testing using JMeter is very well explained and its useful. But I have requirement to do the same in the Loadrunner. Can you please tell which protocol to use ?

    Below is the code which I tried using Java vuser protocol and I refered the Oracle DB testing code, to create the script, but that doesn’t work:
    import lrapi.lr;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.ResultSet;
    import java.sql.PreparedStatement;
    import java.sql.Statement;

    public class Actions
    {
    private Connection connection;

    public int init() throws Throwable {
    Class.forName(“org.neo4j.jdbc.Driver”);
    String url = “jdbc:neo4j:http://1f677f96.databases.neo4j:7687“;
    // Connect to URL using USERNAME and PASSWORD
    connection = DriverManager.getConnection(url,”neo4j”,”S22ZHiZ76nlR6_BsME6ccMKaW2557DsMFYHFuaLJ5Yg”);
    lr.log_message(“JDBC Connection Successful”);
    return 0;
    }//end of init

    public int action() throws Throwable {
    lr.start_transaction(“Database_Query_1”);
    database_query();
    lr.end_transaction(“Database_Query_1”, lr.AUTO);
    return 0;
    }//end of action

    public int database_query() throws SQLException {
    Statement stmt = null;
    //ResultSet rset = null;
    String SQL_QUERY1 = “MATCH (n:ItemFound) where not (n)-[:SUGGESTIONS]->() and n.itemStatus = ‘ONGOING’ RETURN count(n)”;
    PreparedStatement statement = connection.prepareStatement(“MATCH (n:ItemFound) where not (n)-[:SUGGESTIONS]->() and n.itemStatus = ‘ONGOING’ RETURN count(n)”);
    statement.execute();
    ResultSet result = statement.getResultSet();
    while (result.next()) {
    lr.log_message(result.getString(1));
    }
    return 0;
    }

    public int end() throws Throwable {
    if(connection!=null){
    try{
    connection.close();
    }catch(SQLException e){
    e.printStackTrace();
    }
    }
    return 0;
    }//end of end

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Hamster - Launch JMeter Recent Test Plans SwiftlyDownload for free
+
Share via
Copy link