Here is a sample tracking diagram (X-axis: Date, Y-axis: Response time):
Meanwhile, the data is End-End response time,not only back-end html generation time, which load testing tool usually measures.
Testing Code:
MongoDBReader conn = new MongoDBReader();
WebDriver driver = new FirefoxDriver();
long starttime = new Date().getTime();
driver.get("http://www.google.com/");
conn.InstertPermLog(starttime, "Landing_Page");
driver.close();
MongoDBReader source code:
import java.net.UnknownHostException;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.Mongo;
import com.mongodb.MongoException;
/* sample usage
* MongoDBReader conn = new MongoDBReader();
* ...
* long starttime = new Date().getTime();
* driver.get("http://www.google.com/");
* conn.InstertPermLog(starttime, "Landing_Page");
*/
public class MongoDBReader {
private DB db;
private DBCollection coll;
public MongoDBReader(String hostname) throws UnknownHostException, MongoException{
// Connect to Mongo DB server
Mongo m = new Mongo( hostname );
// Get Mongo DB Connection
db = m.getDB("perfdb");
// Prepare Collection
coll = db.getCollection("perfTestColl");
}
public MongoDBReader() throws UnknownHostException, MongoException {
//Connect to the localhost MongoDB by Default
String hostname = "localhost";
// Connect to Mongo DB server
Mongo m = new Mongo( hostname );
// Get Mongo DB Connection
db = m.getDB("perfdb");
// Prepare Collection
coll = db.getCollection("perfTestColl");
}
public DB getDB(){
return db;
}
public DBCollection getCollection(){
return coll;
}
public void InstertPermLog(long startTime, String transactionName){
long endtime = new java.util.Date().getTime();
long responsetime = endtime - startTime;
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.S");
Date date = new Date();
BasicDBObject doc = new BasicDBObject();
doc.put("TimeStamp", dateFormat.format(date));
doc.put("Rtime", responsetime);
doc.put("transaction", transactionName);
coll.insert(doc);
}
}
MongoDB Shell console:
> db.perfTestColl.find();
{ "_id" : ObjectId("4d078fbb3599030f8a412be1"), "TimeStamp" : "2010/12/14 23:39:
39.546", "Rtime" : NumberLong(4609), "transaction" : "Landing_Page" }
{ "_id" : ObjectId("4d078fc33599030f8b412be1"), "TimeStamp" : "2010/12/14 23:39:
47.953", "Rtime" : NumberLong(1641), "transaction" : "Landing_Page" }
{ "_id" : ObjectId("4d078fcb3599030f8c412be1"), "TimeStamp" : "2010/12/14 23:39:
55.578", "Rtime" : NumberLong(1360), "transaction" : "Landing_Page" }
Good article for the auto-performance testing!
ReplyDeleteIt will be interesting to let the "connection" to MongoDB as a singleton value.