2013.09.23 – I’ve been working with our local Legal Aid office for most of my career – their website was one of the first ones I ever worked on, in fact. Over the last few months, I’ve been working with Charmed Designworks to create a new site for LAJC. Behind the scenes, we’ve switched over to WordPress and are using some really nice <a href=”http://sass-lang.com” SASS CSS Preprocessor”>SASS</a> + Compass to make styling a breeze. Legal Aid Justice Center new website
Let’s say you’ve already gotten through the basics of JMeter and you’re ready to start setting up your testing. If you’re doing any sort of remote testing, you’ll inevitably need to know how to setup your client/server relationships.
The vast majority of JMeter’s configuration is done through a single file, the
jmeter.properties file (which lives inside of the JMeter
bin/ directory). Any of the properties in this file can be overridden by options on the command line – but since this is Java we’re talking about, the method is ridiculous (code for Linux/Mac):
jmeter -J<em>propertyname1=value1</em> -J<em>propertyname1=value1</em><br />
Of course, that doesn’t work for every option. For instance, to tell the server that you want it to listen for the initial request on a port that’s not random, you have to do so as an environment variable set on the same line before you make the call to the server. Truly and utterly bizarre:
SERVER_PORT=1660 jmeter-server<br />
As noted below, the server_port only sets the port used for the initial request from the client to the server to begin testing, the response from the server to the client will be sent on a totally random port. I also found that the setting above did not work for setting the listening port at all!
Server (Slave) ConfigurationThe server configuration is ridiculously easy. The server just does what it’s told, so you only have to tell it what port to listen on. In the
jmeter.propertiesfile, you only need to set the
server.rmi.localportvalue to whatever port you want. (You can also set this from the command line using
-J, see the example above.) Note that you MUST set this option to keep the server from listening on a random port! The jquery “default” is 1099. Also note that if you’re having trouble with the Client not being able to talk to the Server, you need to restart the Client after you’ve made any changes to the Server. This is very counter-intuitive! Now, you may encounter a case where the server is trying to respond to the client (master) but looking up the wrong IP address for the hostname. The fix is easy, simply add a record in your hosts file (often /etc/hosts) for the correct address. Last, you should be aware that the server responds to the client’s request on a different port than the server_port specified – it will return test results on a random high-numbered port (45000-70000?). If you haven’t opened up your firewall to account for this, it may cause the server to throw a nasty connection error. Note that there is no way to set the response port by default in JMeter. However, if you feel like getting your hands dirty, you can hack the source to add this option
Client (Master) ConfigurationThe client configuration is only a little more difficult. You’ll need to set the
server_portto the same value you used for the server, again in the
jmeter.propertiesfile. You’ll also need to set the
remote_hosts– this should be a comma-separated list of all of the servers’ hostnames or IP addresses. For example:
<br /> remote_hosts=ec2-50-17-92-85.compute-1.amazonaws.com,ec2-50-17-94-90.compute-1.amazonaws <a href="http://biturlz.com/otO2oiE">team task management</a>.com<br />That’s it! Once you’ve got that all setup, you should be able to start jmeter and have the list of servers appear under the
Run > Remote Startmenu. Note that this does not start up the servers – you’ll still need to start them manually on each machine – it merely runs the current test on the already-running servers. You can also use
Run > Remote Start Allto run the current test on all servers at once. As a final note, you might need to take a look at
jmeter.log, also under the
JMeter bin/ directoryto debug anything that’s not working correctly. There are often a few useful messages in there to help you along the way.
Recently, I’ve been doing a bit of load testing on Amazon AWS after reading cloud storage reviews to determine how much abuse our web application can take without killing the server. I’ve been attempting to use Apache JMeter to do the hard part, but came up against a slew of problems. The documentation provided seems targetted at dyed-in-the-wool Java developers (that “J” at the beginning is clearly a warning shot), and makes pretty big assumptions about the knowledge of the audience. Here are the basic concepts of how to get started using it, targeted for us LAMP developers.
The first thing to understand is that there are two main to go about using Jmeter. By default, Jmeter runs as a free-standing (GUI) application on which you run Tests directly from the machine it’s running on. You do this with the
Run > Start option.
You can also, however set it up to run on other machines, reporting the results back to the original GUI. In JMeter terms, the Master from which you send the tests is called the Client, and the Slaves that run the tests are the Hosts. You have to configure which hosts to run on – afterward you can use
Run > Remote Start > <em>slave address</em> to run the test on a single machine, or
Run > Remote Start All to run on all slaves.
To get started, try running JMeter on your local machine, and writing a basic test. If you’re working locally, just running the bin/jmeter (or bin/jmeter.sh on Mac, bin/jmeter.bat on Windows) script should start up a java session and run the program on your machine. If you’re working remotely, Jmeter runs in an X-Windows environment – so if you’re on a Mac you’ll need to have X11 installed and running.
Writing TestsThere’s actually very good documentation on setting up a test by recording your actions clicking through a site, but here’s the short version. To create a new test, you really only need a few elements. Note: adding elements (Nodes) to a test is tricky because the elements are all context-sensitive. If you haven’t selected the right parent in the list, you won’t be able to add certain children. I’ve listed the correct element to click on as the parent below.
- A Thread Group. Used to set the number of virtual users (Threads) and number of Loops (iterations, obv) for *each* slave to perform (if you’re using the local machine) Click on the Test Plan and then chose
Add > Threads (Users) > Thread Groupfrom the
Editmenu or the right-click contextual menu. For the trial run, you might just give it 1
User, 1 for
Ramp Up Periodand 1
- A Listener of some type. This is the what shows you the results of the test, either by a chart, table, or other medium. The simplest one is probably the Summary Report – to add it, click on the Thread Group and choose
Add > Listener > Summary Reportfrom the menu. No additional configuration is necessary for this type of Listener.
- A Sampler – an actual test element. For instance, if you want to just grab one page off of a site to see if it’s working, you’ll add an HTTP Request Sampler. Click on the Thread Group again, then choose
Add > Sampler > HTTP Request. We’ll want to test with a site we know is working first, so enter google.com for the
Server Name or IP.
Run > Startoption. If you have not saved your test, JMeter will prompt you to do so. After that, if you click on the Summary Report you should see that there has been 1 Sample, with (hopefully) an Error % of 0. If you’re getting an Error % greater than 0, you should probably check that you’re properly connected to the internet and you’ve followed all the steps correctly. Now that they system is working, you can try entering your own domain in, and maybe enter a Path of a particular page that you want to test. Note: be very careful when testing against your live site. Increasing your thread or loops too high can cause the server to stop responding. (Which is what we want to test in the first place!) It’s best to perform your load testing against a non-production machine. Like, say, one set up on Amazon AWS. From here, this would be a good time to read that above article on setting up a test by recording your actions with a proxy server, to create more complicated an thorough tests.
2010.04.09 – As a web developer, the greater part of my job is not creating new apps, but hacking together disparate software packages into Frankensteinian amalgamations that (supposedly) work together seamlessly. This is universally a headache, as the original authors tend to write code thinking that their app is the only one that will be installed. WordPress, Vanilla, and Interspire’s Email Marketer are some of the worst offenders that I struggle with regularly. When coding your own brilliant application, there are a few simple things you can do to avoid potential collisions and headaches later, especially if anyone else will be using your code. Here are a few areas to pay attention to.
NamespaceFirst and foremost, you need to watch out for collisions. If you’re not using a language with built-in namespacing (e.g. PHP <5.3), you’ll need to manage this manually. Some areas that you need to watch out for are:
- Class Names
- Session Variables
- Local Variables
- Constants & Globals
- Database Tables
Program FlowWhen writing code, it’s always a good idea to keep everything to small, reusable functions. This is especially true of published apps, because your users are very likely to be using your code in ways that your original app is not. Try to break things down to the smallest possible chunks, even if it looks pedantic in your application. For instance, break up your createUser() function into separate functions to add the user to the user table, subscribing the user to an email list, adding the user to the default group, etc. Assume that your code will be executing inside of someone else’s code. Try not to use print and echo statements when you can simply pass returned values – only print as the final step. (An easy way to fake this is to use output buffering.) You never know where your output is going anyway – so don’t assume that it will be a particular format – it may end up as HTML, an email body, or in the error log depending on how it’s implemented. Pay special attention to any implicit defaults or rules that your code expects. Don’t force the code to expect complicated series of objects or parameters that any one else wouldn’t immediately understand. Don’t rely on database restrictions to impose your business rules. Assume that your code will be glued into an existing user system at some point – make your user system as user-friendly as possible. Create big wide hooks that anyone can use later to interact with your user system. Actually, do this for everything. (Ok, WordPress, you got that one right at least.) Keep things wrapped up in nice containers. Don’t just leave large procedural chunks lying around for others to trip over. Don’t forget to give some attention to your configuration files on this front. Don’t use globals. Don’t use globals. For the love of God, don’t use globals. I don’t care how clever you think you are (I’m looking at you, WordPress), you’re going to screw everyone else up if you use globals.
Don’t Step On ToesWhen you’re managing your resources, it’s a good idea to be courteous of others. If you’re using a database connection or local file, keep a copy of the handle around instead of relying on the implicit “last opened” scheme many languages offer. And since you’re all such brilliant developers, I don’t have to remind you to make sure to clean up after yourself – closing any connections that you opened, deleting any temporary files you’ve created, and cleaning up any objects you’re done using. Even better, write error handling into all of your code so these things are done automatically even if something fails! One particularly abused area is Session/Cookie management. I cannot begin to list the number of applications that hijack the session and fill/clear it wantonly. In general, you should never be destroying a session, or blanking out the entire cookie. Always sandbox off your content into a hash (using namespaces again), so that you can remove only the content you added. Also, don’t ever set the session name directly – just use the default. (At least, in PHP you can’t use two different sessions simultaneously – setting the session name removes the ability to use any other session).
In conclusion…Do be a considerate programmer. Do keep good fences (as they make for good neighbors). Don’t build giant monoliths (as they attract groups of violent monkeys). Stick to these rules and you’ll save everyone a lot of trouble in the long run.
So, one us pilots was trying to use Doctrine migrations to update a database on one of our servers. However, Doctrine was sternly refusing to use the correct database, as configured in the
database.yml file. As it turns out, using Symfony from the command line skips the usual route through the
/web/yourapplication.php file (e.g.
frontend.php). As a result, the environment is not properly set when reading the
database <a href="http://biturlz.com/Bmg5FIK">team management app</a>.yml file, and instead the last database connection specified is used. Lame. The trick is to specify the environment from the command line, so this file (and the other config files) do what they’re supposed to:
symfony doctrine:migrate --env=staging frontend 119<br />
where “staging” is whatever the environment is you want to use (to match the name in the
Like a good programmer, I try to be good about unit testing More Info. And also as a good programmer, I throw errors in my PHP where appropriate. I just learned today after a bit of digging through the codebase, that SimpleTest can be told to expect an Exception (or error) to be thrown in the test.
trigger_error(), you can use the
expectError() as follows:
$this->expectError( $errorMessageToExpect, 'My message about this test case' );<br />
Note that there is an internal queue of errors in SimpleTest, so it will expect precisely one error for each call to
If, however, you’re using
throw you use
$this->expectException( $exceptionclass, 'My message about this test case' );<br />
You can specify the class of exception to expect in the first parameter – the usual type would be
Exception, of course. If you set the first parameter to
false, it defaults to this type.