 I'm a senior technical evangelist with Microsoft a bit about myself I've been developing applications for more than 16 years now and as a part of my job I work with startups customers help them build scalable applications on the cloud in case you're wondering about the t-shirt I'm also the Docker community mentor for the Mumbai Docker user group. So today's talk I'm going to be talking about using jmeter for load testing and what we can achieve using jmeter combine combining it with the power of web driver plugin and why we should do that some of my experiences working with startups I'll share those along the way. So very quickly I'm just going to discuss I think we've many of the sessions have already covered the aspects of why measuring performance I just had a couple of points from my perspective then we look at jmeter what Apache jmeter is what Selenium web driver is how they work in tandem we'll spend most of our time there and there'll be I'll show quite a few demos of things how they work after that we'll discuss that ideally in most cases why we should use cloud based jmeter testing we'll discuss some tooling in that space and towards the end we'll discuss that why it's not sufficient to just you know worry about performance at the end when you see the performance issues tools like jmeter they're open source they're free so just you know test using them and include these tests as a part of your automated build process or your release pipelines that will really help so we look at how we can do that as well so before you so why measure performance I mean if you can't measure something you can't improve it and normally we develop code based on best practices and that doesn't always work so the GitHub repository which I'll be sharing in the next few slides that has a link to a presentation by the likes of Kyle Simpson which is called javascript midbusters where they bust a lot of javascript optimization myths one of them being string.concat versus array.join so till you don't actually test it you know things you cannot not be sure of the performance and many times I've seen it so in the startup world you build a site and then it becomes popular and then you start getting the load and then you find out that at that load you have some things which are breaking right so earlier you find that out the better how do you measure performance in a repeatable way well this is maybe level two but basically if you're comparing application configuration so you change some javascript code and then you want to compare that with the previous version so to do that in a repeatable way there are two things first is that the test should be automated right and the second one is the environments themselves should be created using some kind of infrastructure as code because that is the only way you'll be sure that both these tests are run against the same environment or you're aware of exactly the difference in the environment so one of the jmeter test show is using docker containers for that part jmeter apache jmeter is a load testing tool so you can simulate user load so you can say that first you define your test in a jmeter file where in you can define okay call this particular API then do this then this next task and then repeat this for thousand users and ramp up the user over five minutes so basically now what you're doing is when you ramp up the users from zero to thousand you will see the difference in the response times right so when my application had ten users the response time was a millisecond right less than a second but when the number of concurrent users goes to 300 or even 100 that's when you'll see the response time going or you'll see errors appearing that is what happens and that's why we should test early right jmeter does some things which a browser can for instance you can follow redirects but it is not a browser in the sense that it does not execute client side JavaScript and that's where we use the web driver plugin so using the selenium basically automates the browsers using the selenium client libraries will have a look at the examples of this in the next slide but using the selenium client libraries you can do tasks like okay load the page go to this text box at this value submitted so you can actually simulate what the user and how the user interacts with the your site and using the jmeter plugin all that you can capture using your response times so this is the GitHub repository I'll quickly go to the different sections of this towards end but this has all the application code which I'm for the applications I'll be load testing as well as the jmeter tests for all the tests I'm going to demo so the application which we use for most of these tests it's called it's the chirp application which is basically it's a mean stack application it's a kind of like a very very light Twitter like application which basically just show it to you so you can log in you can register right and then you can just type a very short message right so this is the application will be testing and if I was to just test this using jmeter how I would traditionally do it is I would test the APIs right so this particular jmeter test which I've loaded what I do here is for one once this I do once I randomly create username and password then using the STTP sampler I register the user right then the user logs in and then for five times he posts a message right so this is how I simulate so if I run this test okay what it will do is it'll actually start firing these STTP requests right so this is the login the request the response and it will start monitoring all kinds of statistics how long it took to load and one key part of this test was I mentioned that you ramp up to 10 users in a period of 20 seconds when you actually do this for your site it'll perhaps be 100 users over five minutes right so that it ramps up gradually and you know at what point your site is going to crash and then you know the break points and you investigate further if you look at some of the reports so this test is finished running so it's given me for each of the operations what is the average time what is the 95th percentile which is a key metric which people look at so the 95th percentile what is the response time so for one of these operations is 480 milliseconds and the error rate which is again a key metric so normally if you test your site for the first time I've seen it happening most often you will see the error rate spiking when you first time you load test your application I'm just going to open another load test so this time I've included the web driver sampler right so till this runs what what is actually happening is in this test we are actually simulating the user interacting with the browser how do we how did we do that we did that using the web driver plugin okay here in the config I mentioned okay I want to test with Firefox and in the sampler the code which I've written is open the login page then in the find the username field add the username okay and then submit normally when you're adding in a load test you would perhaps only want the web driver test to check the load time for key pages in your application okay but this is just to demonstrate what all you can do right I mean of course with selenium this has always been there maybe we'll just look at another one so both these JavaScript files are there on as I said on my GitHub repository so I'm just I've deployed this array join in a separate Docker container and the string dot concat in a separate one and I'm just you know testing that using using web driver so the loop count I've kept it low right so if you look at the name of the page name of the host that will be different for the two calls but what we are doing is this is one way in which you you can compare this is a quick one I wanted to show in the demo so at the end the aggregate report will show us that okay so how much time so the string not concat is constantly for you know faster so as I said that was one of the myths busted in that tutorial so yeah another thing I wanted to show you guys is the selenium IDE okay so what we can do with the selenium IDE suppose I go to bing.com okay I search for jmeter go to images I go to videos I come back to web so basically the selenium IDE is recording all this okay now I will stop recording okay and so all the clicks it identifies basically each of the buttons each of the elements I click I can now actually replay this so yeah it'll do exactly that and the really cool part is here so now we have a jmeter plugin for the selenium IDE so you can actually just record and download the jmx file for the load test right from here but this creates a lot of extra requests I don't I write my own but yeah you can do this to quickly get started to record your journeys and get going I'm going to go back switch over to the slides again I'm going to just quickly go through the slides and then again I'll go to some of the tools which I will be discussing so why do we need cloud-based jmeter tests even I mean you need these at a later stage initially you can just start with the jmeter but what happens is can you generate 10,000 concurrent connections from your local machine no right because your bandwidth locally will become a constraint you will not be able to generate that much of load traditionally how this was done was using you know test tracks with several induces which generated the load which was quite expensive both in terms of maintenance cost but now with the power of cloud so blaze meter is one very popular tool which I've used where you can just upload the jmx file and you can then choose the location you want to run the test from and then fire the test you'll get a good response you'll get an indication of when your application really needs to scale how well it does that which used to do team services is again Microsoft's cloud-based tool which cloud DevOps tool which can do anything from iOS to Android builds to all tasks it also has a jmx load testing where you upload the jmx file and you run the load tests and you get all these cool metrics about your error rates with that high performance when you have a lot of load of against your websites so as I said when you need to test your application against really heavy load you need this right also when you want to test from a particular location region where your users typically log in from it's a good option this is like why you need to include it in your build pipelines so if you don't have a build pipeline I mean then it's fine but if you are if you have a you deliver you have a nightly build going somewhere it is a good idea to have the basic jmeter assertions which are like your response time assertion and your size assertion which basically tell you that what is the size of your response so if I hit a particular your home page what is the size in bytes of your response and you can set a threshold for that beyond that the build will fail I mean the jmeter assertion will fail and the build will fail and it's really simple to do it is not expensive at all so you know I would suggest at least those basic tests can be included in your build pipeline so in this example this is a case of a java app which using visual studio team services where we do a maven package we build the docker container deploy to the docker containers in a different environment and then before going to prod we do a load test so but again this totally depends on what your situation is whether you want to go in for such an extensive pipeline to start with maybe not what I'll do is I'll just show you some of these so this is the GitHub repo I'll just quickly show you so all the jmex files are here this is the if you just do a installation instructions for the mean the job application installation are provided below so this is the repository you do a npm install I mean I've given the installation instructions and then you can just fire the jmeter test against that the other one where I'm doing the string concat versus a rejoin that is again over here okay I've given the link to that as well yeah here this is the presentation kyle simpson's presentation and this is the repository where I'm just writing that JavaScript so this is the just wanted to take you through this repository and just a quick view of visual studio team services so as I told you this is a build where I'm doing a npm install a gulp and if I just list of tasks available here you can do jmeter test you can do Android Android build you can do iOS build I mean a lot of the stuff so as I said it's a cloud based DevOps tool if you have a Jenkins build you can use get the Jenkins build and use VSTS for release management that is also possible there are of course a free time free free tier for you guys to try it out if you want to and here I'm using this is the whole QA PVT prod I'm using a different tool for the load testing here but we can use jmeter as well I think I'll take questions now that's pretty much what I wanted to cover if you have any questions so when you say JS you mean JS on the server side or the front end so normally the jmeter samplers they just give you they don't execute the client side JavaScript but when you include the web driver plug-in so you saw that user ID password being tapped typed in that was a that is angular app right so it won't work so with the web driver plug-in it executes the client side JavaScript as well and you you can capture the responses you can capture everything which is done by Angular by anything which is done by the browser so basically what web driver does is it it drives so the web driver executables are provided by the browser manufacturers so I mean Firefox provides it's executable you can do same from crowing so what I'm trying to ask is if you have a dialogue which is coming up using JavaScript yes web driver wouldn't get no right how would web driver come into place so how will the user interact with that you say he's clicking there's an Ajax request come there's a response exactly so you can handle Ajax through web driver as well right but when you are writing your load test do you want to capture those things or you just want to capture the client side JavaScript execution time or load times that is up to you but you can do that you can do Ajax pretty much to that you can do this with Selenium but the thing is when I'm doing load testing right your JavaScript is executing very well right but as soon as you reach 100 100 users if you've got everything say in a CDN your static content everything is fine but if everything is being served by the same server including your static content you don't have the correct expires headers even the static content request will go there and you'll see errors so that's why with load you just using Selenium you can't don't induce load right absolutely correct correct that's why so I mean you don't for every few requests if you include this you'll need with whether the client side JavaScript it might test some parts which are not tested by a jmeter API tests so so for instance you don't have any API test you don't have any unit test where you normally start is the UI Selenium test right so if you write that Selenium test and you it will cover a lot of the parts which your API test do not cover so you will identify those errors is nothing is foolproof this is a good way to have this kind of load testing is a good way to include in your I mean normal build process to keep a tab on how your page look page load times for your key pages don't exceed a certain threshold because anyway you're running these jmeter tests as a part of that even testing the JavaScript client side performance thank you