PERFORMANCE TESTING A FLEX BLAZEDS APPLICATION
上一篇 / 下一篇 2010-07-04 19:27:43 / 个人分类:JMeter
查看( 785 ) /
评论( 0 )
In the past few years I’ve seen an increasing interest in Flex applications at our customers. I have to say that I’m not surprised about this trend. Not only do Flex applications generally look great, but they also provide a big boost to user experience. As a developer and architect I am also quite pleased with the programming model and extensive widget library. Sure, Adobe can still improve on a lot of things, but so far I have always worked with pleasure on Flex applications.
8d.~5|Q*_Sr0
)cs1C.V1c~0
$H,A ]1\@~H0Recently, at one of our customers, I bumped into another interesting side of Flex application development, namely performance testing (e.g. load-testing or stress-testing). Surprisingly enough, it is very hard to find an affordable solution for this. There are commercial tools out there that seem to do it quite well (Neoload) or reasonably well (WebLOAD) but I could not find a single viable open source alternative.51Testing软件测试网 dL8spI\N_w`~
Of course, it’s not exactly straightforward to write such a tool. The difficulty lies in the ability to generate and send AMF requests to the webserver, plus the interpretation of the AMF response you get back. The standard approach that most performance testing tools use is based on the assumption of HTTP requests and responses. While the AMF protocol technically “hitches a ride” on the HTTP protocol as well, the content is packed into a binary format (AMF) that can’t be interpreted the regular way HTTP requests and responses can. Hence the need for a dedicated tool thatcaninterpret AMF. However, not every customer has tens of thousands of dollars to spend. So, how do you cope with this?
{;Tp5L2jgK051Testing软件测试网'xW_\[e
AMF request generationAs it turns out, with a little ingenuity and the help of the BlazeDS codebase, you can create a solution that together with the excellentJMeterallows you to execute performance tests just as you are used to doing. Let’s start with the generation of AMF requests.
YMKfE!?WW0In the blazeds-core.jar there are representations of AMF messages and ways of de-/serializing them. This is actually used by BlazeDS itself to convert between AMF data to a Java Object model and vice versa. Because they kindly open sourced this code, I was able to reuse these classes to generate AMF requests and save those to a file. Here are a couple of code snippets I wrote to do this:
"P `IiHq GX0public byte[] generate(AmfRequestParameters params) { ActionMessage message = new ActionMessage(); message.addBody(createMessageBody(params)); ByteArrayOutputStream ut = new ByteArrayOutputStream(); MessageSerializer serializer = createMessageSerializer(out); try { serializer.writeMessage(message); } catch (IOException e) { throw new AmfRequestGenerationException(e); } return out.toByteArray();}First thing to note is the creation of an ActionMessage. This is actually a representation of an AMF request to which we will add a body in the second line of this method. Because we want to save this AMF request to a file we of course need to serialize it first. We do this by using the MessageSerializer class BlazeDS kindly provides. We let it serialize the message to a ByteArrayOutputStream so that we can potentially use it for other purposes than saving it to a File, but you could just as easily pass in a FileOutputStream. Finally, we return the byte array back to the client that called this method.
+ex&kR$\cH0
8d.~5|Q*_Sr0
)cs1C.V1c~0
$H,A ]1\@~H0Recently, at one of our customers, I bumped into another interesting side of Flex application development, namely performance testing (e.g. load-testing or stress-testing). Surprisingly enough, it is very hard to find an affordable solution for this. There are commercial tools out there that seem to do it quite well (Neoload) or reasonably well (WebLOAD) but I could not find a single viable open source alternative.51Testing软件测试网 dL8spI\N_w`~
Of course, it’s not exactly straightforward to write such a tool. The difficulty lies in the ability to generate and send AMF requests to the webserver, plus the interpretation of the AMF response you get back. The standard approach that most performance testing tools use is based on the assumption of HTTP requests and responses. While the AMF protocol technically “hitches a ride” on the HTTP protocol as well, the content is packed into a binary format (AMF) that can’t be interpreted the regular way HTTP requests and responses can. Hence the need for a dedicated tool thatcaninterpret AMF. However, not every customer has tens of thousands of dollars to spend. So, how do you cope with this?
{;Tp5L2jgK051Testing软件测试网'xW_\[e
AMF request generationAs it turns out, with a little ingenuity and the help of the BlazeDS codebase, you can create a solution that together with the excellentJMeterallows you to execute performance tests just as you are used to doing. Let’s start with the generation of AMF requests.
YMKfE!?WW0In the blazeds-core.jar there are representations of AMF messages and ways of de-/serializing them. This is actually used by BlazeDS itself to convert between AMF data to a Java Object model and vice versa. Because they kindly open sourced this code, I was able to reuse these classes to generate AMF requests and save those to a file. Here are a couple of code snippets I wrote to do this:
"P `IiHq GX0public byte[] generate(AmfRequestParameters params) { ActionMessage message = new ActionMessage(); message.addBody(createMessageBody(params)); ByteArrayOutputStream ut = new ByteArrayOutputStream(); MessageSerializer serializer = createMessageSerializer(out); try { serializer.writeMessage(message); } catch (IOException e) { throw new AmfRequestGenerationException(e); } return out.toByteArray();}First thing to note is the creation of an ActionMessage. This is actually a representation of an AMF request to which we will add a body in the second line of this method. Because we want to save this AMF request to a file we of course need to serialize it first. We do this by using the MessageSerializer class BlazeDS kindly provides. We let it serialize the message to a ByteArrayOutputStream so that we can potentially use it for other purposes than saving it to a File, but you could just as easily pass in a FileOutputStream. Finally, we return the byte array back to the client that called this method.
+ex&kR$\cH0