Saturday, 19 January 2013

mongometer v2.0

A while back I knocked up mongometer to compare the relative performance of MongoDB scripts. I then made some minor changes, and since then - and only recently - made additional changes based on feedback.

I've now made slightly more significant changes. I'll now cover them briefly.

The minimum JMeter version is now 2.8, this is because it is dependent on a change introduce in JMeter 2.8.

I've created a MongoSourceElement which is accessible from the context menu; Add -> Config Element -> MongoDB Source Config

This pulls all the MongoDB connection details up a level and allows you to share it between multiple MongoScriptSamplers. This means you only need to define the connection once and associate a source name with the instance. When you create a MongoScriptSampler you can then reference the source name as defined in MongoSourceElement.

MongoScriptSampler now only includes the fields that you need. It allows you to specify the mongo source, the database, the database credentials and of course the script to run.

The way I'm currently using it is to create a MongoSourceElement.
Under that I create a ThreadGroup.
And under that I add the MongoDB Script v2.0, View Results Tree, and Graph Results.

If I have multiple script to run, I use the same grouping of, MongoDB Script v2.0, View Results Tree, and Graph Results. See the image below for an example.



There is the added MongoUtils class which has a static method which allows you to specify multiple hosts (if you want) and breaks it out into each host and port, returning an ServerAddress, which to be honest, I'm surprised isn't available under the Java MongoDB driver.

The other semi-useful addition is the QuickEnvironment. It basically allows you to start up mongod, mongo, jmeter and a tail of the jmeter log. You could do this in a script, but hey ho, I did it in a helper class.

The latest version is available on github.

Please have a play, try and break it, make suggestions, give me feedback.

25 comments:

  1. Hello Jan,
    With this new config element your plugin is much more powerful.
    This is an issue I found:
    If I connect to MongoDB not providing username and password everything works excellent.
    If I have to provide credentials, I am getting this error for the next mongo sample (in logs and sample response):

    2013/01/24 12:18:20 WARN - jan.mongometer.sampler.MongoScriptSampler: java.lang.IllegalStateException: can't call authenticate twice on the same DBObject
    at com.mongodb.DB.authenticate(DB.java:489)
    at jan.mongometer.mongo.MongoDB.getDB(MongoDB.java:46)
    at jan.mongometer.sampler.MongoScriptSampler.sample(MongoScriptSampler.java:55)
    at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:426)
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:255)
    at java.lang.Thread.run(Unknown Source)


    I tried to set SocketKeepAlive to False, I tried to send credentials only with the first sample, leaving cred fields empty for the next sample(s), but getting the same error.

    Maybe you have any suggestions?

    ReplyDelete
    Replies
    1. Hi archie.

      Could you send me the jmx file you're using please - obviously with the credentials obfuscated.

      I'll fix it over the weekend.

      Delete
    2. Actually, try it now. I've added a check to see if the connection has already been authenticated.

      Delete
    3. Hello Jan,
      Yes, it works now.
      Excellent extension!
      Thank you very much for it.

      Delete
    4. No problem. Let me know if there is anything else you think may be useful.

      Delete
  2. Hello Jan,
    Just want to thank you once more for the work you have done.
    It is excellent extension!

    ReplyDelete
    Replies
    1. Thank you for taking the time to say that; it's appreciated.
      This extension is now available as part of the core application, so if you download the latest (nightly) build, #mongometer is already there. Not sure on the timetable with regards to the next major/minor #jmeter release.

      If you have any requests for additional functionality, I'll be happy to take a look.

      Delete
  3. Hi ,

    Very nice work .

    I had a question . I was unable to get the authentication thing working . tried to follow the png's that you have posted . I get this error

    command failed [command failed [$eval] { "serverUsed" : "xxx.xxx.xxx:10077" , "ok" : 0.0 , "errmsg" : "unauthorized"}

    This seems to be the sampler code which barfs with an error showing up as 500 in Visualiser

    MongoScriptSampler.java
    ==========================
    ............

    try {
    MongoDB mon = MongoSourceElement.getMongoDB(getSource());
    DB db = mon.getDB(getDatabase(), getUsername(), getPassword());
    MongoScriptRunner runner = new MongoScriptRunner(db, getUsername(), getPassword());
    res.latencyEnd();
    res.setResponseData(runner.evaluate(db, data).getBytes());
    }
    ....

    I see that you use 2.7.2 . Did you use auth . From the code it seems it should work for you . I am not a MongoDB novice so dont have a clue .

    I have been able to get it to run as a standalone chunk of code , so wonder whats wrong here

    I have a few ideas on the lines of Monitoring AND Script development friendliness that can be added to MongoMeter .

    Have a connect in the sampler which could pouplate a list of Columns .
    Instead of just having a text have some basic validation JSON Validation I mean so that the sampler/script can be tested

    Thank you a lot for you work in this area.










    ReplyDelete
    Replies
    1. If you could go into your jmeter.properties file and set your log level for mongometer to debug, then try again.
      log_level.jan=DEBUG

      Then you can check the jmeter.log file. It will give more information on the issue.

      Are you using the latest version of the mongometer.jar available on github (https://github.com/JanPaulEttles/mongometer/tree/master/out/artifacts)
      What version of jmeter are you using?

      #mongometer has been added to the core jmter project so you can download it straught from the jenkins server https://builds.apache.org/job/JMeter-trunk/lastSuccessfulBuild/artifact/trunk/dist/

      I like the idea of a JSON validator, although I think you mean a JavaScript validator, or a MongoDB specific JS validator. Do you mean, you'd want to verify that the script that will be passed to the MongoDB eval function is sensibly formatted and validated?

      Delete
  4. does this plugin work windows jmeter. based on the readme provided some of the directory paths do not match Example /org/apache/jmeter/resources/messages.properties

    ReplyDelete
    Replies
    1. The path you refer to is within the jar file and not OS specific.

      You can find mongometer as part of the core product, so yes, it works on any OS jmeter runs on.

      Delete
    2. This comment has been removed by the author.

      Delete
    3. I've just downloaded the same build and everything is there as expected.

      The server address is the address where you server is running. If it's on the same machine you can add 127.0.0.1, if it is on a different machine on the network such as 192.168.06, then add that.

      Delete
  5. Hi,

    When I try to run the script it shows the following error:

    2013/05/27 10:42:56 INFO - jmeter.engine.StandardJMeterEngine: Running the test!
    2013/05/27 10:42:56 DEBUG - jan.mongometer.config.MongoSourceElement: MongoDB Source Config testStarted
    2013/05/27 10:42:56 ERROR - jmeter.JMeter: Uncaught exception: java.lang.NoClassDefFoundError: com/mongodb/MongoOptions
    at jan.mongometer.config.MongoSourceElement.testStarted(MongoSourceElement.java:204)
    at org.apache.jmeter.engine.StandardJMeterEngine.notifyTestListenersOfStart(StandardJMeterEngine.java:212)
    at org.apache.jmeter.engine.StandardJMeterEngine.run(StandardJMeterEngine.java:324)
    at java.lang.Thread.run(Thread.java:722)

    am I missing some configuration here?

    ReplyDelete
    Replies
    1. This is not a mongometer specific error, it looks like you haven't added the mongodb jar to the classpath.

      Why not download the nightly build of jmeter, mongometer has been added as a plugin and you won't have to concern yourself with any 'config' issues

      Delete
  6. I tried this both with JMeter 2.8 and 2.9, using latest version of mongometer.

    ReplyDelete
  7. ok thanks. using one of jmeter nightly builds worked fine.

    could you please explain a bit more abt meaning of MongoDB Source. what does it mean exactly?

    ReplyDelete
  8. When I wanted to query a sharded collection, it is showing this error:

    { "serverUsed" : "/xxxIP:27017" , "errmsg" : "exception: JavaScript execution failed: Error: can't use sharded collection from db.eval near '{return db.collectionName.find().count' " , "code" : 16722 , "ok" : 0.0}

    ReplyDelete
    Replies
    1. http://docs.mongodb.org/manual/reference/limits/

      db.eval() is incompatible with sharded collections. You may use db.eval() with un-sharded collections in a shard cluster.

      Delete
  9. I am not using db.eval() directly. i am simply sending this request via Mongo DB Script sampler function() {return db.collection.find().count();}

    ReplyDelete
  10. does this mean this mongometer plugin does not support sending queries to sharded collection?

    thanks

    ReplyDelete
    Replies
    1. The plugin uses db.eval() under the covers; it was the only was that I could pass in arbitrary scripts without having to implement a parser. The plugin was only ever written to compare scripts relative to each other, and shards weren't in my thoughts. So in short, no, the plugin was never intended to work with sharding.
      If you have any ideas on how db.eval() can be replaced, then I'm happy to look at it.

      Delete
    2. This comment has been removed by a blog administrator.

      Delete
  11. Best casinos for UK players to play slots - DRMCD
    Play slots online 안성 출장마사지 for free 김천 출장마사지 at best casinos in the 전주 출장마사지 UK. Safe and 제주도 출장마사지 secure deposits & withdrawals. Find trusted UK casino sites.Are there UK online slots 전라남도 출장샵 to play with?

    ReplyDelete