JMeter Test MongoDB Performance in two ways, one is to use JMeter directly to test MongoDB, there is a way to write Java code to test MongoDB performance.
The first of these methods
1. Write Java code that reads as follows:
PackageCom.test.mongodb;ImportJava.io.File; ImportJava.io.FileOutputStream; Importjava.io.IOException; ImportJava.util.UUID;ImportJava.util.concurrent.atomic.AtomicLong; Importorg.apache.jmeter.config.Arguments; Importorg.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient; ImportOrg.apache.jmeter.protocol.java.sampler.JavaSamplerContext; ImportOrg.apache.jmeter.samplers.SampleResult; ImportCom.mongodb.BasicDBObject; ImportCom.mongodb.DB; Importcom.mongodb.DBCollection; ImportCom.mongodb.Mongo; Importcom.mongodb.MongoOptions; Importcom.mongodb.ServerAddress; ImportCom.mongodb.WriteResult; /** * * @author2014-10-14 * @remark One-time insertion of multiple data test MongoDB performance*/ Public classTestmongodbextendsabstractjavasamplerclient {Private StaticMongo m; Private StaticDB DB; Private StaticAtomiclong Read_key =NewAtomiclong (0); Private StaticFileOutputStream Fos; Static { Try{fos=NewFileOutputStream (NewFile ("Jmeter_error.log")); Mongooptions Options=Newmongooptions (); Options.autoconnectretry=true; Options.connectionsperhost= 1000; Options.maxwaittime= 5000; Options.sockettimeout= 0; Options.connecttimeout= 15000; Options.threadsallowedtoblockforconnectionmultiplier= 5000; M=NewMongo (NewServerAddress ("127.0.0.1", 27017), options); DB= M.getdb ("Iflashbuy-log"); } Catch(Exception e) {Throw NewRuntimeException (e); } } PublicArguments getdefaultparameters () {Arguments params=NewArguments (); Params.addargument ("RW", "w"); returnparams; } PublicSampleresult runtest (Javasamplercontext context) {//System.out.println (Read_key.getandincrement ()); Sampleresult results =NewSampleresult (); //System.out.println (Context.getparameter ("RW")); Results.samplestart (); Dbcollection Coll= Db.getcollection ("area"); if("W". Equalsignorecase (Context.getparameter ("RW")))) { LongKey = 1; Basicdbobject Doc=NewBasicdbobject (); Doc.put ("_ID", Uuid.randomuuid ()); Doc.put ("_class", "com.iflashbuy.bi.source.pojo.AreaDataEntity"); Doc.put ("Province", "Guangdong"); Doc.put ("City", "Guangzhou"); Doc.put ("PV", 35522924); Doc.put ("UV", 52556); Doc.put ("OrderCount", 963); Doc.put ("OrderTotal", 1548563); Doc.put ("Entprisecode", "00540001"); Db.requeststart (); Writeresult RS=Coll.insert (DOC); Try { if(Rs.geterror ()! =NULL) Fos.write (Rs.geterror (). GetBytes ()); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } //System.out.println ("w error->" + rs.geterror ()); Db.requestdone (); } results.setsuccessful (true); Results.sampleend (); returnresults; //return null; } /*Public static void Main (String args[]) throws Exception {Arguments a = new Arguments (); A.addargument ("RW", "w"); Final Javasamplercontext C = new Javasamplercontext (a); Long start = System.currenttimemillis (); for (int i = 0; i < 5; i++) {new Thread () {public void run () {Tes Tmongodb t = new Testmongodb (); for (int j = 0; J < 2; J + +) {t.runtest (c); }}}.start (); } } */}
2. Build the jar package and place it under the Jmeter_home/lib/ext folder
3. Start JMeter, new thread Group, Java request, view result tree, aggregated report, graphical results
4. Perform the test
Check that MongoDB has added success data.
The second method of
1. Start JMeter, create a new thread group, set thread Group properties
2. Right-click Add-mongodb Source Config
Set Properties Server Address list:127.0.0.1
MongoDB Source:jmeterdbsource, as set:
3. Right-click to add-sampler-mongodb Script
Set Properties MongoDB Source: Refer to the good name set in MongoDB source Config, Jmeterdbsource
Database name: Iflashbuy-log
Script: Scripts
4. Right-click-listener-view result tree
Both of these methods can be used to test MongoDB performance.
Summary: Learning JMeter for a while, more and more realize that JMeter support for Java is too strong.
Report:
MongoDB billion-level data volume performance test http://www.cnblogs.com/lovecindywang/archive/2011/03/02/1969324.html
JMeter Learning (19) JMeter test MongoDB