In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how JAVA + LR implements the performance testing of apache streaming media. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
There are no more than three methods for multi-client simulation:
1. The general mobilization of the whole company, watch it together.
two。 A machine opens multiple playback pages (or multiple players embedded on one page) and calls multiple machines.
3. Abandon the decoding and playback process of the client and download the video file directly.
The first method is needless to say, although it is the most authentic, it is too primitive and has no technical content, and it may not be enough if it is a small company.
The second method is OK when the number of users to be tested is small, otherwise it will take up more resources and the technical content is low. In this way, the number of users that can be simulated on a machine is very limited, because CPU can quickly become a bottleneck.
The third method is the most efficient, in a gigabit network environment, one machine can simulate many users, when the network bandwidth is the bottleneck (if the bandwidth is larger, it is estimated that the hard disk IO is the bottleneck). But without decoding and playback, how to judge the effect of the client? There are two ways, one is to compare the download speed and bitrate, in theory, as long as the download speed is enough; the other is to open several real playback windows to verify the playback effect during the test, because the pressure is on the server. It can be considered that every client is equivalent.
This article is going to talk about the third test method.
Previously also tested FMS streaming media, the Internet can find ready-made tools to achieve this method, as long as it is called. But HTTP also searched this time for two days, and it seemed that there was no such thing, so I had no choice but to do it myself. It seems that the most efficient method is the most troublesome to implement. The basic idea is to realize the download function of JAVA and to realize the control of multi-users with the JAVA Vuser of LR. Sort out a need for yourself before you do it.
Features:
Simulated download √
Playlist √
Download speed record: total average speed, speed per second √
* connect as a player
* client speed limit
Test results:
Apache speed limit
Download speed
File integrity
Function expansion
Pass parameters to jar package or exe file (playlist)
The ticks are already implemented, and those with asterisks are advanced features that are not implemented and do not necessarily need to be implemented. Through the test program, the result you need to get is whether the download is completed correctly. Is the download speed fast enough? Does the speed limit module of apache work (if turned on)? There may be a problem here, if the download program breaks the apache speed limit, it may be the problem of the test program, which leads to the above advanced features "disguised as a player".
Paste the code directly below and put the instructions in the comments as far as possible.
Download the class to provide static methods.
Package com.test;import java.io.*;import java.net.*;import java.util.*;public class DownloadFile {/ * * download the specified URL file * userid is the identity used to save the local file * * / public static int getHttpFileByUrl (String address, String userid) {int bufferSize = 1024; int size = 0; byte [] buf = new byte [bufferSize] / * * download time string * for file identification * format 201210260130 * * / Date date = new Date (); SimpleDateFormat formatDate = new SimpleDateFormat ("yyyyMMddHHmmss"); String downloadTime = formatDate.format (date) / * * calculate download speed correlation * / int totalDownloadSize = 0; int lastDownloadSize = 0; long lastCheckTime = 0; long startDownloadTime = 0; int sec = 0; / * * download and calculation process * / try {URL url = new URL (address) URLConnection conn = url.openConnection (); BufferedInputStream bis = new BufferedInputStream (conn.getInputStream ()); FileOutputStream fos = new FileOutputStream ("e:\ test\ testvideo" + "_" + downloadTime + "_" + userid); System.out.println ("File Size:" + conn.getContentLength () / 1024 + "KB"); startDownloadTime = System.currentTimeMillis () LastCheckTime = startDownloadTime; while ((size = bis.read (buf))! =-1) {fos.write (buf,0,size); totalDownloadSize + = size / * * calculate the download speed per second * / if (System.currentTimeMillis ()-lastCheckTime > 1000) {System.out.println (sec + ":" + (totalDownloadSize-lastDownloadSize) / 1024 + "KB"); lastCheckTime = System.currentTimeMillis () LastDownloadSize = totalDownloadSize; sec++;}} System.out.println ("Vuser" + userid + "Download Completed!"); System.out.println ("Average Download Speed:" + (totalDownloadSize/1024) / ((System.currentTimeMillis ()-startDownloadTime) / 1000) + "KB/s") Fos.close (); bis.close ();} catch (MalformedURLException e) {e.printStackTrace ();} catch (IOException e) {e.printStackTrace ();} return totalDownloadSize/1024;}}
Test driven.
Import com.test.*;import java.util.*;import java.io.*;public class DownloadDrive {public static void main (String [] args) {/ / System.out.println ("test"); / / DownloadFile.test (); / * caller measurement * self-implemented * / int DownLoadSize = 0; double DownLoadTime = 0 Int Speed = 0; String url; ArrayList urlList = new ArrayList (); / * * read the URL address to be downloaded * save it to list * / try {BufferedReader br = new BufferedReader (new FileReader ("url.txt")) While ((url = br.readLine ())! = null) {urlList.add (url);}} catch (IOException ie) {ie.printStackTrace ();} System.out.println ("Total URLs:" + urlList.size ()) / * * download the files in list in turn * / for (int I = 0; I
< urlList.size(); i++){ url = (String)urlList.get(i); System.out.println(url); //传入url和每个调用者的标识 DownloadFile.getHttpFileByUrl(url, "1"); } } } 将待下载的URL保存到url.txt中,每行一个地址。文件放到DownloadDrive.class同目录中。 到这,主要代码已经实现了。下一步需要做的是和LR整合,用LR的Java Vuser对下载功能进行控制,模拟多用户。其实也就是重写一个测试驱动,只不过这个驱动是需要LR内部方法了,应该没有什么技术上的难点了。 接下来,通过LoadRunner来实现多线程的模拟和控制。 新建LR的JAVA Vuser脚本,这里可以直接进行JAVA编码,又可以调用LR的内部方法,如事务、思考时间、集合点等等。到了这步已经没有任何难点了,开发人员只要花1个小时了解下LR的基本使用和常用方法即可,测试人员如果不会JAVA……那还是算了吧。 Action.java内容如下: import lrapi.lr;import com.test.*;import java.util.*;import java.io.*;public class Actions{ public int init() throws Throwable { return 0; }//end of init public int action() throws Throwable { /* 调用者测量 */ int downloadSize = 0; int downloadTime = 0; long startTime = 0; long endTime = 0; int speed = 0; int vid; vid = lr.get_vuser_id(); /* 从url文件生成arraylist */ String url; ArrayList urlList = new ArrayList(); try{ BufferedReader br = new BufferedReader(new FileReader("url.txt")); while((url = br.readLine()) != null){ urlList.add(url); } }catch(IOException ie){ ie.printStackTrace(); } lr.enable_redirection(true); lr.set_debug_message(lr.MSG_CLASS_JIT_LOG_ON_ERROR, lr.SWITCH_OFF); System.out.println("Total URLs: " + urlList.size()); for(int i = 0; i < urlList.size(); i++){ url = (String)urlList.get(i); System.out.println(url); //事务名称 String trxName = "URL" + (i+1); startTime = System.currentTimeMillis(); lr.start_transaction(trxName); //传入url和每个调用者的标识 downloadSize = DownloadFile.getHttpFileByUrl(url, Integer.toString(vid)); lr.end_transaction(trxName, lr.AUTO); endTime = System.currentTimeMillis(); downloadTime = (int)(endTime - startTime)/1000; speed = downloadSize / downloadTime; lr.output_message(trxName + ": completed"); lr.output_message("time cost: " + downloadTime + "s"); lr.output_message("average speed: " + speed + "KB/s"); lr.output_message(""); } lr.set_debug_message(lr.MSG_CLASS_JIT_LOG_ON_ERROR, lr.SWITCH_ON); return 0; }//end of action public int end() throws Throwable { return 0; }//end of end} 所有以lr开头的方法都是LR内部方法,这里只用到了事务、日志等几个。 编译之前我们的JAVA下载代码,将包(com.test)放入LR脚本的目录中,如图:Open the LR script and run it.
You can see that the log is output normally, and then verify that the downloaded file is complete, find the output path, such as "h:testtestvideo_20121106194419_-1", open the file with the player and play it normally. It means that our script is already OK, so we are going to do a multi-user test.
Open controller, set up to run two VUSER simultaneously (to ensure that the network of the loader does not become a bottleneck), and run the scenario.
As you can see, both VUSER completed as expected.
Verify the effectiveness of the test from several aspects:
1 is the network utilization of the loader, the download speed of the above single user is 5M/s when executing the script (the apache server has made a speed limit), this time the two users have downloaded 10m at the same time.
2 is the output log for each VUSER.
3 is the integrity of the downloaded file.
Thank you for reading! This is the end of this article on "JAVA + LR how to achieve the performance test of apache streaming media". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.