Flex Performance Test Based on AMF Protocol

Source: Internet
Author: User

I have been familiar with Flex applications, and I am very appreciative of the visual effects of the presentation layer. It is precisely because of its gorgeous appearance that it masks many of its internal defects, for example, performance problems such as response speed and Memory leakage are a headache for most flex developers or testers. I recently encountered a performance test based on the flex application. Due to its particularity, the communication establishment and protocols are basically developed by Adobe, therefore, the general test tool is not ideal for his support. Through a series of explorations, we finally have to focus on flex and fully parse the AMF protocol. In fact, the AMF Protocol still adopts the HTTP protocol, but in terms of execution efficiency, we cannot simply simulate the execution process through the HTTP protocol, because the AMF protocol must be used in the middle. Although LoadRunner also supports the AMF protocol, AMF itself needs flash.
The recorded script is not easy to understand and analyze. We cannot analyze the execution process well, and its packets and packages are in binary format. If this scheme is used for execution, we need to parse each packet and package settlement process, which is equivalent to going deep into the AMF protocol package parsing process, so as to complicate the simple problem. The biggest problem in the performance test of C/S applications is packet parsing. packet loss may occur when the stress test is performed by LoadRunner. Therefore, to ensure the integrity of protocol data packets, we usually try to avoid directly dealing with protocol data packets and request through upper-layer encapsulation, instead of interfering with the complicated internal process, this ensures the integrity of data transmission and the consistency with the business logic implementation mode to achieve a real-world stress testing solution.

Next we will learn more about the AMF protocol, and simulate the connection between the client and the server to implement the AMF Protocol Communication to complete the stress test of high concurrency.

AMF is an exclusive communication protocol developed by Adobe. It adopts binary compression, serialization, deserialization, and data transmission, this provides a lightweight and efficient communication mode for the flash player to communicate with the flash remoting gateway.

Simulate AMF requests to establish communication with the server. Adobe officially provides a server-side communication service, namely, blazeds. Flex converts data to binary format through AMF protocol and transmits the data to the blazeds service on the server, then, blazeds parses the data into the format required by Java to complete the communication process between the flex client and the server. Therefore, further analysis shows that our goal is to simulate the connection between AMF and blazeds to solve the problem. Here, we use Java to simulate AMF requests and connect to the blazeds interface through amfconnection. The Demo code is as follows:

Package Org. test. service. testlogin; import flex. messaging. io. AMF. client. amfconnection; import flex. messaging. io. AMF. client. exceptions. clientstatusexception; import flex. messaging. io. AMF. client. exceptions. serverstatusexception; public class amfdemo {public static void main (string [] ARGs) {// create AMF connection amfconnection amfcon = new amfconnection (); // connect to remote URL string url = "http: // localhost: 8080/testlog In/messagebroker/AMF "; try {amfcon. connect (URL);} catch (clientstatusexception CSE) {system. out. println (CSE); return;} testlogin result; try {result = (testlogin) amfcon. call ("testlogin. login "," username "," passwd "); // transmission object parameters, Login User, password} catch (clientstatusexception CE) {system. out. println (CE);} catch (serverstatusexception SE) {system. out. println (SE);} amfcon. close (); system. out. println ("sucessfull !!! ");}}
If the above connection test is successful, the next problem will be solved, that is, simulating concurrency. For Java, It is a multi-threaded problem. The number of concurrent users can be controlled through multiple threads, complete the stress test for the blaseds interface. Multi-threaded code implementation is as follows:
Package Org. test. service. testlogin; import flex. messaging. io. AMF. client. amfconnection; import flex. messaging. io. AMF. client. exceptions. clientstatusexception; import flex. messaging. io. AMF. client. exceptions. serverstatusexception; public class amfdemo implements runnable {public void run () {// create AMF connection amfconnection amfcon = new amfconnection (); // connect to remote URL string url = "http: /// localhost: 8080/testlogin/ Messagebroker/AMF "; try {amfcon. connect (URL);} catch (clientstatusexception CSE) {system. out. println (CSE); return;} // 100 cycles for (INT I = 0; I <100; I ++) {testlogin result; try {thread. sleep (1000l); long teststart = system. currenttimemillis (); Result = (testlogin) amfcon. call ("testlogin. login "," username "," passwd "); // transmission object parameters, Login User, password system. out. println ("login:" + (system. currenttimemillis ()-teststar T); // print the logon response time} catch (clientstatusexception CE) {system. out. println (CE);} catch (serverstatusexception SE) {system. out. println (SE);} catch (final interruptedexception e) {e. printstacktrace () ;}} amfcon. close (); system. out. println ("sucessfull !!! ") ;}} Public class amfdemotest {// create 100 threads public static void main (string [] ARGs) throws exception {for (INT I = 0; I <100; I ++) {runnable = new amfdemo (); New thread (runnable ). start ();}}}

Simulate AMF requests in Java to establish a communication connection with blazeds to test the stress of flex applications based on the AMF protocol, to find the best performance testing solution for flex itself. Of course, this is only implemented in pure code mode. We can also use common tools to complete the above Code implementation process at least, you can call the Java code through LoadRunner or jmeter, but it seems that jmeter is more convenient for Java support. The purpose of using the tool is to sample the stress test data for easy analysis, and to truly implement the stress test, whether it is a tool or a script, it is actually achieved by simulating the underlying interaction method to achieve the same purpose.

As a tester, the communication between Java and flex is far inferior to that between developers. Therefore, the above description of the communication mechanism of blazeds may be incorrect. However, it is not just to record how to implement a stress test, but to express my understanding of the performance test idea. In many cases, do not blindly pursue the power of automation tools, this ignores the idea of performance testing. I hope to gradually improve myself through continuous summarization!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.