Languages
[Edit]
EN

Performance - Java MySQL JDBC library vs Node.js mysql package in sequential query test

8 points
Created by:
Xitiz
2195

In this short article, we would like to show performance comparison between Java and Node.js that connect to MySQL database. The main goal is to show connection mechanism overhead between different technologies: Java JDBC library and Node.js mysql package.

Scenario

Edit

In the below test we execute SELECT * FROM `users` WHERE `role` = 'moderator' query on 120 rows stored in database repeating the same query sequentaly 1, 5, 10, 50, 100, 500, 1000, 5000, 10000 and 50000 times.

    Results

    Edit

    Smaller times mean better result.

    Java MySql JDBC vs Node.js mysql package execution time for SQL queries.
    Java MySql JDBC vs Node.js mysql package execution time for SQL queries.
    Number of queries

    Java JDBC library execution time
    [in ms]

    Node.js mysql package execution time
    [in ms]
    111
    553
    10107
    503020
    1004933
    500145113
    1000248198
    5000728884
    1000013121685
    5000052827749

    Conclusions

    Edit

    In the test, for bigger number of queries, Java JDBC has better performance (since 5000 queries).

    Environment

    Edit

    Used OS: Windows 11 x64

    Used Software:

    • Java
    • Node.js
    • MariaDB

    Used PC:

    • Ryzen 9 5900x
    • DRR 4 (2x 32GB)
    • Samsung SSD M.2 970 EVO (1TB)
    • GeForce GTX 970 (4GB RAM)

     

    Java program

    Edit

    Example src/com/example/Program.java file:

    Example pom.xml file:

      Compilation (in command line):

      Hint: or use mvn clean install.

      Running (in command line):

       

      JDBC jar file source:

      1. MySQL JDBC - Maven Repository
      2. Direct JDBC jar file link

       

      Node.js program

      Edit

      Example index.js file:

      Example package.json file:

      Installation (in command line):

      Running (in command line):

       

      Database preparation

      Edit

      Example create_tables.sql file:

      Example insert_data.sql file (execute it 30 times to fill database):

       

      See also

      Edit
      1. Java - download Adopt Open JDK for free - Java 8, 11, 16 or 17

      2. Java - how to make MySQL select query with JDBC?

      3. Node.js - install under Windows

      4. Node.js - MySQL Select query

      References

      Edit
      1. Download Java 11
      2. Download Node.js 16.13.0
      3. Download MariaDB Server 
      1
      Donate to Dirask
      Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
      Join to our subscribers to be up to date with content, news and offers.
      Native Advertising
      🚀
      Get your tech brand or product in front of software developers.
      For more information Contact us
      Dirask - we help you to
      solve coding problems.
      Ask question.

      ❤️💻 🙂

      Join