Performance Testing Flex Remoting (AMF) with JMeter

7 May, 2008 – 7:08 pm

[UPDATE] this has since been resolved! JMeter support rocks :D
URL: http://svn.apache.org/viewvc?rev=661141&view=rev
Log: Bugs 44808 & 39641 - Proxy support for binary requests

You may still find the ruby proxy idea interesting …

The Action Message Format (AMF) is a binary protocol that Flex applications use to remotely communicate with the server. I’ve tested recording of this using LoadRunner which picks up the binary format nicely as part of the HTTP POST.

It will look a little like this:

  web_custom_request("amf_3",
    "URL=http://host.under.test.com/messagebroker/amf",
    "Method=POST",
    "Resource=0",
    "RecContentType=application/x-amf",
    "Referer=http://ost.under.test.com/messagebroker/client/main.swf",
    "Snapshot=t13.inf",
    "Mode=HTML",
    "EncType=application/x-amf",
  "BodyBinary=\\x00\\x03\\x00\\x00\\x00\\x02\\x00\\x04null\\x00\\x02/3\\x00\\x00\\x01\\x0F\n\\x00\\x00\\x00\\x01\\x11\n\\x81\\x13Mflex.messaging.messages.CommandMessage\\x13operation\\x1BcorrelationId\tbody\\x13messageId\\x11clientId\\x15timeToLive\\x13timestamp\\x0Fheaders\\x17destination\\x04\\x08\\x06\\x01×06\r"
    "my-amf\\x01\\x06#labelPrintService",
    LAST);

I understand that Segue Silk Performer also has this capability to natively record binary protocols arbitrarily attached to the POST. Unfortunately the native JMeter proxy (when used for recording) doesn’t pick up this data reliably.

This defect is current being tracked at the ASF Bugzilla

After looking around for some proxying software that would assist, products such as Charles Proxy looked tempting. But to be honest, if you’re reading this and using JMeter, you’re probably not interested in paying any license fees.

Read on for a free alternative when using JMeter.

The first thing I wanted to setup was a proxy that could catch the necessary HTTP header requests (and responses), and store a copy of any amf content types to the filesystem when recording a typical user transaction. I did this using Ruby and the webrick/httpproxy gem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'webrick/httpproxy'
 
i= 1
server = WEBrick::HTTPProxyServer.new(
  :Port=> 9090, 
  :RequestCallback => Proc.new{   
  |req,res| 
    if req.raw_header.to_s.match(/x-amf/) == nil
		  puts req.request_line,req.raw_header
		else
	    amf = req.body
	    file = File.new("./#{i}.amf","w")
	    file.write(amf)
	    file.close
		  res['Content-Type'] = "application/x-amf"
		  i = i+1
		end
    puts "------------------"
  }) 
trap "INT" do server.shutdown end
server.start

So if you run that proxy from a terminal, it will listen on port 9090 (or whatever you like) for any traffic. Then I just use Firefox (with the FoxyProxy add-on for fast proxy switching :) ) and conduct my normal transactions through the flex app via the browser.

What you will then see in the terminal, is a copy of all the headers for the requests/responses printed to screen. If it sees any headers with an x-amf content type, it will save a copy of the AMF data to a sequentially number file called #{n}.amf

Once you’ve run the transactions, you can create a thread group in JMeter and start adding all the HTTP Request samplers that have POST actions with AMF data. You might still want to use the standard JMeter proxy to record all the normal HTTP stuff (minus the AMF) to save time. Then just amend your test plan to include the POST actions with AMF, such that they look something like this.
http request post with amf

Of importance is the file that you are sending with the post. This should be the full path to the AMF file previously recorded. Also make sure the MIME type is applicaton/x-amf.

Make sure you add the AMF files you saved earlier with the proxy in the correct order to the test plan. That should be all you need to do to test from JMeter. In my case I also had to add standard config elements such as the HTTP Cookie Manager and a User Parameters (to correlate jsessionids).

Share it: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netscape
  • Reddit
  • Slashdot
  • Technorati
  • YahooMyWeb
  1. 5 Responses to “Performance Testing Flex Remoting (AMF) with JMeter”

  2. Cool! I am having the same problem to make loading/stress tests in Flex apps… any other experience you have discovered since them? Have you added all by hand in JMeter? Thanks

    By Bruno on May 27, 2008

  3. No I haven’t progressed beyond this post. The app I was looking at was quite simple, perhaps 5 - 10 unique binary blobs of data that I had to capture, so it didn’t warrant any further development. You could if you were interested look at perhaps modifying the HTTP recording proxy code in JMeter to cater for the amf mime type. Or alternatively knock up a Ruby or Perl script to help create template jmx files (after all, they are just an xml text file).

    Regards,
    Tim

    By Tim on May 27, 2008

  4. Thanks Tim. Have you seen this ticket (https://issues.apache.org/bugzilla/show_bug.cgi?id=39641)? They say AMF can be recorded in JMeter, but I could not make it work.
    Thanks.

    By Bruno on May 28, 2008

  5. Thanks for the bug reference, I wasn’t aware it was being tracked. Good to see progressive development continuing with JMeter. As you’ve highlighted, it looks like the HTTP proxy does not yet support recording of binary data, so hopefully someone with more nouse than me can fix that up in JMeter.

    Although that would just solve one problem. The correlation or parametization of data inside those binary blobs might be difficult to achieve once JMeter successfully records it using the proxy. You would then have to perhaps modify the pre/post-processors to modify the data in the correct format. I’m not sure just running the regular expression extractor for example would work as intended on binary data … In other words, there’s still probably some manual work to do at the end in any case.

    Regards,
    Tim

    By Tim on May 28, 2008

  6. You are right! The first step is make the proxy save the binary data. A second problem would be handle these data that could be needed in some special cases. Thanks.

    By Bruno Ghisi on May 28, 2008

Post a Comment

*
To prove that you're not a bot, enter this code
Anti-Spam Image