Apache JMeter Streamlit Machine Learning I recently stumbled upon an open source project called Streamlit. Streamlit is a framework where you can build custom Machine Learning tools by focussing on data science rather than the user interface. You can spin up your app with the intuitive user interface and leverage Python modules at ease. In this blog post, I am going to present everything in detail about how I leveraged Streamlit for Apache JMeter and what are all the benefits, future plan, and more.
Table of Contents
What is Streamlit?
Streamlit is an open-source Python library that makes it easy to build beautiful apps for machine learning.
It is simple, but powerful app model which helps you to build rich UI. You write the code, instantly you can see the output in the browser.
Use case of Streamlit
Below repository has the sample app demo, if you would like to see the real life use cases.
https://github.com/streamlit/demo-uber-nyc-pickups
Deep dream and Shaobo Guan’s Face-GAN explorer source will be available soon. You can star the Streamlit repo in here.
Apache JMeter with Streamlit for Machine Learning
By integrating Streamlit with Apache JMeter, you can build machine learning models to train to detect anomalies from your JMeter test results.
Please note that this project is just a beginning where you can execute and visualize the test results in interactive charts.
I am currently working on designing the machine learning model for performance testing metrics.
Demo
Prerequisites
You need the following stuffs to get started. I designed this app in my Windows 10 laptop, but it should work in other operating systems as well.
- Apache JMeter
- Your favorite IDE (I ? VS Code), you could try PyCharm as well
- Anaconda
- Python 2.7.0 or later / Python 3.6.x or later
- PIP
- Streamlit
Please try to use the latest version as possible e.g. have JMeter 5.2.1 instead of JMeter 5.2. I prefer Anaconda to install Streamlit. You can read the instructions over here.
I assume that you already have a working knowledge on Apache JMeter. If not, you can check this link to get started.
Once all the software is installed and verified, add the JMETER_HOME
environmental variable in your System pointing to the JMeter folder (containing JMeter sub-folders: bin, lib, docs etc.). This is a must to execute the JMeter test plan.
You can validate the environmental variable propagation via cmd > %JMETER_HOME%
command.
Clone the repository
Now it is time to clone the Streamlit-JMeter repository. After cloning, navigate into the repository in the command prompt and run the below command. You could use the terminal which is available in VS Code or PyCharm as well. As I mentioned, I prefer VS Code.
python -m pip install -r .\requirements.txt
Above command will install the necessary modules for the app.
In the command prompt, enter the below command:
streamlit run app.py
In case of powershell, issue the below command
streamlit run .\app.py
This will open a new tab or launch the default browser with the URL http://localhost:8501
You could see the About
page.
Execute JMeter Test Plan
To execute JMeter test plan, click on left sidebar widget and then click on Execute JMeter Test Plan
radio button. This will bring up the page where you can select the JMeter test plan as shown below.
After selecting the JMX file, click on Run
button to execute the JMeter test plan. This will execute your test plan in CLI mode and generates unique log file and place it in the bin
folder.
At top right corner, you could see the progress of the app.
To monitor the performance, go to the command prompt which displays the run time stats.
If you would like to stop the script execution, go to the command prompt and issue the CTRL + C
shortcut.
Analyze
To analyze the test results, click on Analyze JMeter Test Results
radio button which will bring up the page as shown below. Select the csv file to analyze which will display the metrics such as start time, end time, summary report etc.
To view the graphs, click on Show Graphs
checkbox.
All the graphs are interactive, on need basis you can generate variety of combinations by custom coding. Under the hood, graphs plotted using vega-lite
.
Limitations
- Supports only CSV results
- By default, it fetches all the files from the
JMETER_HOME
folder. - Limited number of charts has been added, other type of charts can be added by custom coding.
Known Issues
- Doesn’t execute if the JMeter file name which has space
- Quick Navigation between Execute and Analyze may break the code, you may need to launch the app again.
- Doesn’t display the JMeter test results runtime
What’s next?
- This is just a inception version where I experimented the capabilities of
streamlit
. The next big thing is writing a training model to detect the anomalies and predict the point of failure which is work-in-progress.
Notes
- I am not a professional developer nor a good open-source maintainer. My code may not have the standards, but it will do its job if everything is properly set.
You are a true leader.
Let’s put this in a shell script.
Thanks Wilson. Please share your inputs to implement unsupervised learning to detect the anomalies.
Hello Naveen,
Kudos to you for sharing this. This is a Gem for any Performance Engineer. Any update on the 2nd part “…training model to detect the anomalies and predict the point of failure….”
Keep up the great work!!
sincerely,
TB
Thanks for checking out. No update further. :)
Iam not successful in installing required packages on Pycharm….it throws error
ERROR: Command errored out with exit status 1:
command: ‘C:\Users\pmagal\PycharmProjects\LocustDemo\venv\Scripts\python.exe’ -u -c ‘import io, os, sys, setuptools, tokenize; sys.argv[0] = ‘”‘”‘C:\\Users\\pmag
al\\AppData\\Local\\Temp\\2\\pip-install-6i91htv1\\bottleneck_81c7aa9495634614b2454346af512fcd\\setup.py'”‘”‘; __file__='”‘”‘C:\\Users\\pmagal\\AppData\\Local\\Temp\\
2\\pip-install-6i91htv1\\bottleneck_81c7aa9495634614b2454346af512fcd\\setup.py'”‘”‘;f = getattr(tokenize, ‘”‘”‘open'”‘”‘, open)(__file__) if os.path.exists(__file__)
else io.StringIO(‘”‘”‘from setuptools import setup; setup()'”‘”‘);code = f.read().replace(‘”‘”‘\r\n'”‘”‘, ‘”‘”‘\n'”‘”‘);f.close();exec(compile(code, __file__, ‘”‘”‘ex
ec'”‘”‘))’ install –record ‘C:\Users\pmagal\AppData\Local\Temp\2\pip-record-teq4etfh\install-record.txt’ –single-version-externally-managed –compile –install-head
running build_ext
building ‘bottleneck.reduce’ extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools”: https://visualstudio.microsoft.com/visual-cpp-build-tools/
Hi Naveenkumar
I am successfully installed streamlit and configured in JMeter it is working fine for me, but I need updated repository or code for performance testing to integration. streamlit with JMeter.
The project is open source; feel free to add the code based on your requirements :)