Wednesday, November 19, 2014
JMeter Loop Controller & Counter
Why we need loop controller[1] in JMeter?
Assume you need to run the same HTTP request(sampler) multiple times, rather than creating duplicate samplers we can use this handy logic controller available in JMeter.
Eg:- Publish 1000 APIs to WSO2 API Manager, Benchmark web-server concurrent requests handle
Lets take the first sample scenario, We can create a HTTP request sampler which publishes API. (before that we need to create a HTTP request to login which is out of loop controller scope)
1. Create a Loop Controller using Add> Logic Controllers> Loop Controller,
2. Add a Counter to above Controller using, Add> Config Element> Counter,
3. Create sampler(s) according to your requirement, here I'm creating Add API HTTP Request Sampler, (Add> Sampler> HTTP Request),
You can see I'm appending ${api_id} for some request parameter values. This value will be initialized and incremented within our Counter(step 2). In my scenario I can't publish multiple APIs with the same name & context.
I tried this loop 20 times by updating Loop Count and Maximum values to 20. You can see multiple "Add API HTTP Request" & "Publish API HTTP Request" sampler requests,
[1] http://jmeter.apache.org/usermanual/component_reference.html#Loop_Controller
Wednesday, November 12, 2014
Run JMeter in command line
There are use-cases where you can't use JMeter GUI to run the script.
Eg :- during distributed JMeter load testing, run jmx from a remote machine (just using command line)
Following are the steps which I followed to run JMeter script in command line.
1. Create JMeter script in your local machine.(yes, using the GUI ;) )
2. Setup JMeter in the remote machine.
4. Move and setup apache-jmeter-X.XX.zip and jmx according to your preference.
I have extracted apache-jmeter-X.XX.zip inside my home directory(remote machine) and able to move to bin directory using,
Lets run this script in command line now.
-n denotes –nongui run JMeter in nongui mode
-t denotes –testfile jmx file which needs to run
-l denotes –logfile file to put sampler logs (jtl)
Following is the output I got, If you are not getting summery results make sure to attach "Generate Summary Results" listener to relevant samplers.
udara@udara-aws:~/apache-jmeter-2.11/bin$ sh jmeter.sh -n -t test.jmx -l log.jtl
Creating summariser <summary>
Created the tree successfully using test.jmx
Starting the test @ Tue Nov 11 19:29:28 UTC 2014 (1415734168842)
Waiting for possible shutdown message on port 4445
summary + 1 in 3.3s = 0.3/s Avg: 3324 Min: 3324 Max: 3324 Err: 0 (0.00%) Active: 1 Started: 1 Finished: 0
summary + 6 in 4.1s = 1.5/s Avg: 676 Min: 124 Max: 1756 Err: 0 (0.00%) Active: 0 Started: 1 Finished: 1
summary = 7 in 8s = 0.9/s Avg: 1054 Min: 124 Max: 3324 Err: 0 (0.00%)
Generate Summary Results for list APIs = 1 in 1.1s = 0.9/s Avg: 1065 Min: 1065 Max: 1065 Err: 0 (0.00%)
Generate Summary Results for List Subscriptions = 1 in 1s = 1.6/s Avg: 637 Min: 637 Max: 637 Err: 0 (0.00%)
Tidying up ... @ Tue Nov 11 19:29:36 UTC 2014 (1415734176890)
... end of run
Eg :- during distributed JMeter load testing, run jmx from a remote machine (just using command line)
Following are the steps which I followed to run JMeter script in command line.
1. Create JMeter script in your local machine.(yes, using the GUI ;) )
2. Setup JMeter in the remote machine.
- SCP apache-jmeter-X.XX.zip and created jmx in step 1.
4. Move and setup apache-jmeter-X.XX.zip and jmx according to your preference.
I have extracted apache-jmeter-X.XX.zip inside my home directory(remote machine) and able to move to bin directory using,
cd /home/udara-aws/apache-jmeter-2.11/binCopied test.jmx script in to the same location.
Lets run this script in command line now.
sh jmeter.sh -n -t test.jmx -l log.jtlHere we have used -n -t and -l arguments.
-n denotes –nongui run JMeter in nongui mode
-t denotes –testfile jmx file which needs to run
-l denotes –logfile file to put sampler logs (jtl)
Following is the output I got, If you are not getting summery results make sure to attach "Generate Summary Results" listener to relevant samplers.
udara@udara-aws:~/apache-jmeter-2.11/bin$ sh jmeter.sh -n -t test.jmx -l log.jtl
Creating summariser <summary>
Created the tree successfully using test.jmx
Starting the test @ Tue Nov 11 19:29:28 UTC 2014 (1415734168842)
Waiting for possible shutdown message on port 4445
summary + 1 in 3.3s = 0.3/s Avg: 3324 Min: 3324 Max: 3324 Err: 0 (0.00%) Active: 1 Started: 1 Finished: 0
summary + 6 in 4.1s = 1.5/s Avg: 676 Min: 124 Max: 1756 Err: 0 (0.00%) Active: 0 Started: 1 Finished: 1
summary = 7 in 8s = 0.9/s Avg: 1054 Min: 124 Max: 3324 Err: 0 (0.00%)
Generate Summary Results for list APIs = 1 in 1.1s = 0.9/s Avg: 1065 Min: 1065 Max: 1065 Err: 0 (0.00%)
Generate Summary Results for List Subscriptions = 1 in 1s = 1.6/s Avg: 637 Min: 637 Max: 637 Err: 0 (0.00%)
Tidying up ... @ Tue Nov 11 19:29:36 UTC 2014 (1415734176890)
... end of run
Sunday, November 9, 2014
Measure tempreture using TMP35 sensor
After receiving my LCD this came to my mind, as a weekend project :)
Ingredients
1. Arduino (I'm using uno here)
2. Breadboard with jumper cables (create the prototype)
3. LCD (I'm using 2*16)
4. TMP35 Sensor
5. USB cable
Other than that I have used a potentiometer(variable resistor) to control brightness of the LCD.
Let's configure our LCD first, I have used the following circuit found here[1].
Next step is to configure our temperature sensor. I'm using a TMP35 sensor for this, this provides a voltage output linearly proportional to the temperature. So we have to do some math within our program to output temperature in Celsius.
One more thing, unlike our LCD TMP35 provides analog signal as it's output. So we have to plug in to an analog pin located in Arduino.
Connect Analog out pin (middle one) to the A0 analog pin. Then + pin to the positive bus of our breadboard and - end to the ground bus. (make sure to plug these two pins in correct way, refer following image)
Now we are good to proceed to our program since we are done with the circuit prototype. Connect Arduino into a computer and open ArduinoIDE to write the sketch.You can find complete sketch here.
[1] http://arduino.cc/en/Tutorial/LiquidCrystal
Ingredients
1. Arduino (I'm using uno here)
2. Breadboard with jumper cables (create the prototype)
3. LCD (I'm using 2*16)
4. TMP35 Sensor
5. USB cable
Other than that I have used a potentiometer(variable resistor) to control brightness of the LCD.
Let's configure our LCD first, I have used the following circuit found here[1].
Next step is to configure our temperature sensor. I'm using a TMP35 sensor for this, this provides a voltage output linearly proportional to the temperature. So we have to do some math within our program to output temperature in Celsius.
One more thing, unlike our LCD TMP35 provides analog signal as it's output. So we have to plug in to an analog pin located in Arduino.
Connect Analog out pin (middle one) to the A0 analog pin. Then + pin to the positive bus of our breadboard and - end to the ground bus. (make sure to plug these two pins in correct way, refer following image)
Now we are good to proceed to our program since we are done with the circuit prototype. Connect Arduino into a computer and open ArduinoIDE to write the sketch.You can find complete sketch here.
#Adding LCD libraryNow upload this sketch into your Arduino and here is our final outcome :)
#include <LiquidCrystal.h>
#Init LCD library with digital pin 12, 11, 5, 4, 3 and #2
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int sensorPin = A0;
void setup() {
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop() {
#Read the sensor value
int sensorVal = analogRead(sensorPin);
#Convert reading to voltage
float voltage = (sensorVal/1024.0) * 5.0;
#convert millivolts into temperature
float temperature = (voltage - .5) * 100;
lcd.print("Room Temp: ");
lcd.print(temperature);
delay(1000);
lcd.clear();
}
[1] http://arduino.cc/en/Tutorial/LiquidCrystal
Thursday, November 6, 2014
AV cable and raspberry pi B+
I'm able to taste the latest revision of Raspberry Pi, the model B+ recently. Compared to the previous version this has more advantages,
1) 40 GPIO pins
2) 4 USB ports
3) Neat micro SD slot with push to release capability
4) 3.5mm integrated Audio/video port
We can find tons of information available on-line about first three, but found the last point bit complicated.
If you have a nice HDMI supported monitor or TV no need to worry about this. But if you are going to plug your Raspberry pi B+ to an old fashioned TV with a AV cable this post might helps you :)
Selecting a cable,
This is bit tedious task since there is no standard for AV cable pinouts. Found this post which is really helpful for this task.
FYI : I bought zune AV cable with the correct pinout configuration for Raspberry pi B+.
Even with the correct cable you won't get this to work in first attempt :(
I tried with the NOOBS installation, by default NOOBS configures HDMI output with higher priority than our poor AV out.
You can find this configuration in /boot/config.txt file,
1) 40 GPIO pins
2) 4 USB ports
3) Neat micro SD slot with push to release capability
4) 3.5mm integrated Audio/video port
We can find tons of information available on-line about first three, but found the last point bit complicated.
If you have a nice HDMI supported monitor or TV no need to worry about this. But if you are going to plug your Raspberry pi B+ to an old fashioned TV with a AV cable this post might helps you :)
Selecting a cable,
This is bit tedious task since there is no standard for AV cable pinouts. Found this post which is really helpful for this task.
FYI : I bought zune AV cable with the correct pinout configuration for Raspberry pi B+.
Even with the correct cable you won't get this to work in first attempt :(
I tried with the NOOBS installation, by default NOOBS configures HDMI output with higher priority than our poor AV out.
You can find this configuration in /boot/config.txt file,
hdmi_force_hotplug=1 config_hdmi_boost=4I have commented out above default configuration and added following, with this configuration even if you have a HDMI monitor plugged in it will use the composite output.
hdmi_ignore_hotplug=1
#hdmi_force_hotplug=1
#config_hdmi_boost=4
Saturday, November 1, 2014
Optimizing eclipse IDE on a Ubuntu box
I'm currently using eclipse Luna on my Ubuntu 13.10, IDE crashes after few seconds.
While searching google for a fix I found number of SO replies with following update to eclipse.ini ,
Eclipse issue seems to be fixed now !!
While searching google for a fix I found number of SO replies with following update to eclipse.ini ,
-Dorg.eclipse.swt.browser.DefaultType=mozillaBut it does not seem to fix my issue, then I tweaked existing eclipse.ini as follows,
I have commented out ms & mx parameters to pick my system parameters, then increased MaxPermSize to 512 MB.
-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.200.v20140603-1326
-product
org.eclipse.epp.package.java.product
--launcher.defaultAction
openFile
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
512m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.6
-XX:MaxPermSize=512m
#-Xms40m
#-Xmx512m
-Dorg.eclipse.swt.browser.DefaultType=mozilla
Eclipse issue seems to be fixed now !!
Tuesday, October 21, 2014
Talking to an Arduino from PHP
I was able to talk to my Arduino without using an Ethernet or a wireless shield.
Best part is that I only have 4 lines in my PHP script :)
Things you need to have :
Arduino board with a USB Cable
Breadboard
1 LED
Few jumper wires
220 OHM resistor
Additionally Arduino IDE, PHP, Apache2 installed Linux box :)
1. Connect Arduino's GND pin to breadboard's ground line.
2. Connect Digital pin 13 to breadboard's + line.
3. Connect LED's Anode(long leg) with the breadboard's + line using the 200 OHM resistor.
4. Connect LED's cathode(short leg) with breadboard's - line directly using a jumper cable.
You are done with the circuit prototype, Now connect the Arduino board to your PC.
Open Arduino IDE, click on tools> Serial port. You can see the device connected to a port similar to "/dev/ttyACM0".
Let's write our PHP snippet,
Upload above sketch to your Arduino and open the serial monitor window within the Arduino IDE.
In order to execute our PHP snippet,
Lets open a terminal window and change directory to the /var/www/php-arduino directory.
run sudo php switch_uno.php your LED will be on :) If you run the same command again LED will be off.
You can do the same by using PHP serial class also.
Best part is that I only have 4 lines in my PHP script :)
Things you need to have :
Arduino board with a USB Cable
Breadboard
1 LED
Few jumper wires
220 OHM resistor
Additionally Arduino IDE, PHP, Apache2 installed Linux box :)
1. Connect Arduino's GND pin to breadboard's ground line.
2. Connect Digital pin 13 to breadboard's + line.
3. Connect LED's Anode(long leg) with the breadboard's + line using the 200 OHM resistor.
4. Connect LED's cathode(short leg) with breadboard's - line directly using a jumper cable.
You are done with the circuit prototype, Now connect the Arduino board to your PC.
Open Arduino IDE, click on tools> Serial port. You can see the device connected to a port similar to "/dev/ttyACM0".
Let's write our PHP snippet,
<?php
$comPort = "/dev/ttyACM0"; /*Update to the correct port */
$fp =fopen($comPort, "w");
fwrite($fp, "switch"); /* We are going to write "switch" */
fclose($fp);
?>That is it, host this snippet switch_uno.php within /var/www/php-arduino directory. lets write our Arduino sketch.
String val;
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop()
{
while (Serial.available()){
delay(10);
char c = Serial.read();
if (c == ','){
break;
}
val+= c;
}
if (val == "switch") {
if(digitalRead(13) == LOW){
digitalWrite(13, HIGH);
delay(100);
Serial.println(1);
}else if(digitalRead(13) == HIGH){
digitalWrite(13, LOW);
delay(100);
Serial.println(0);
}
val="";
}
}
Upload above sketch to your Arduino and open the serial monitor window within the Arduino IDE.
In order to execute our PHP snippet,
Lets open a terminal window and change directory to the /var/www/php-arduino directory.
run sudo php switch_uno.php your LED will be on :) If you run the same command again LED will be off.
You can do the same by using PHP serial class also.
Monday, June 30, 2014
Publish assets using the API-Postman-WSO2 Enterprise Store
At the moment there are two ways to publish an asset to the ES back-office.
1. Using the UI
Eg: - Browse https://localhost:9443/publisher/asset/ebook
You can find the following UI and add the new asset(ebook in this case)
2. Using the API
This is the subject that I'm going to talk in this post. I'm going to use Postman- REST client for google chrome and CURL to execute this API invocation.
First lets try out with Postman,
Prerequisite :
a) google chrome browser
b) Postman chrome-extension
Steps
i) Browse https://localhost:9443/publisher/ and login in to the back-office.
ii) Browse chrome://apps/ and launch Postman REST client.
iii) Refer following screen-shot and create the POST form-data accordingly.
Note
URL : https://localhost:9443/publisher/api/asset/ebook
Type : POST
iv) Now you can invoke the API :)
You will receive the following output if it works right..
Lets browse the newly added ebook asset.
I will come up with a separate post on the topic POST multipart/form-data using CURL soon. So you can invoke the same above asset add API using CURL.
1. Using the UI
Eg: - Browse https://localhost:9443/publisher/asset/ebook
You can find the following UI and add the new asset(ebook in this case)
2. Using the API
This is the subject that I'm going to talk in this post. I'm going to use Postman- REST client for google chrome and CURL to execute this API invocation.
First lets try out with Postman,
Prerequisite :
a) google chrome browser
b) Postman chrome-extension
Steps
i) Browse https://localhost:9443/publisher/ and login in to the back-office.
ii) Browse chrome://apps/ and launch Postman REST client.
iii) Refer following screen-shot and create the POST form-data accordingly.
Note
URL : https://localhost:9443/publisher/api/asset/ebook
Type : POST
iv) Now you can invoke the API :)
You will receive the following output if it works right..
Lets browse the newly added ebook asset.
I will come up with a separate post on the topic POST multipart/form-data using CURL soon. So you can invoke the same above asset add API using CURL.
Subscribe to:
Posts (Atom)











