Use Apache JMeter to test SQL optimization performance

Source: Internet
Author: User

I. Preface

      JDK--- JDK 1.4 or later must be installed. I use JDK 1.7.
    • Apache JMeter--- Used for performance testing.
    • Oracle 10gDatabase-data used for testing.
    • Oracle Instant Client 12c--- Used to test the SQL connection to the database.
    • Free Oracle Weblogic12c for Developers--- Used to test database connection over HTTP.

    The following describes how to test using SQL.

      If not, install it first.
    • After decompression, you can use it.
    • After decompression, copy ojdbc6.jar to the lib subdirectory under the JMeter directory. This is the JDBC driver of the Oracle database.

     TABLE USER_INFO(user_name varchar(),address varchar(),)

     INTO USER_INFO(user_name, address) values(, )INSERT INTO USER_INFO(user_name, address) values(, )INSERT INTO USER_INFO(user_name, address) values(, )INSERT INTO USER_INFO(user_name, address) values(, )INSERT INTO USER_INFO(user_name, address) values(, )

     
    

    Test Plan and workbenchClick "test plan" and name it "my database test plan" on the properties page on the right ".

  • \ C.csv ,)}0 indicates the 0th column of the CSV file. If our SQL query statement has multiple parameters, you can separate them with commas in "Parameter values. For example:

     
    
  • Download a free-installed Oracle Weblogic 12c for dev from the Oracle website.

    • First decompress the zip installation package and I decompress it to D: \ weblogic-12120.
    • Press windows key + R to open the "run" window, Enter cmd, and press enter to open the Command Prompt window. Run the following command:
    D:cd D:\weblogic-12120set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_21set MW_HOME=D:\weblogic-12120configure.cmd

    At this time, the Weblogic installer starts to decompress the installation package. You can check the title bar to learn the progress.

    • After decompression, the installer automatically sets the environment variables and prompts whether to configure a new domain. Enter "Y" to go to the next step.
    Do you want to configure a new domain? [Y/N] Y
    • Enter the Weblogic administrator user name. I generally use weblogic.
    Enter username to boot WebLogic server:weblogic
    • Enter the Weblogic administrator password. Generally, weblogic123 is used. Note that if you enter a pure number, the installation program may exit abnormally, the reason is that the Weblogic administrator password must contain both letters and numbers.
    Enter password to boot WebLogic server:

    After the password is entered again, a default domain "mydomain" will be created. The path is:

    D:\weblogic-12120\user_projects\domains\mydomain

    In addition, The installer will directly start this domain. You can see "The server started in RUNNING mode." On The command line interface, indicating that The mydomain domain has been started. 10. Configure the JDBC data source in Weblogic

    • Access the Weblogic Management Interface in a browser:
    http://localhost:7001/console

    You can also use weblogic/weblogic123 to log on to the weblogic management interface.

  • On the homepage, select domain configuration> data source to go to the data source configuration page.
  • Select New> General Data Source To Go To The Data Source Creation page. Set the name to testdatasource, The JNDI name to testdatasource, and the database type to Oracle.
  • Click Next, select the database driver, and retain the default value.
  • Click Next to display the transaction management method of the driver. Click Next to configure the database connection parameters. The related parameters are set as follows:
    • Database Name-usually the SID or Service_Name of the database, and set it to orcl.
    • Host Name --- host name or IP address of the database server.
    • Database username-the username used to connect to the database.
    • Password-the password of the database user.
  • Click Next and use the "test configuration" function to test whether the database connection is correct. If there is any problem, you need to go back to the previous step to modify the database connection parameters. If there is no problem, click "finish" to create the JDBC data source pointing to the Oracle database.
  • Then deploy the data source to myserver, click "testdatasource", select "target", select "myserver", and click "save ", deploy the data source to myserver.
  • 11. Create a simple JSP Project

    • Create a directory: webtest under Directory D: \ weblogic-12120 \ user_projects \ domains \ mydomain.
    • Create a subdirectory of the WEB-INF under the webtest directory and create the web. xml file in the subdirectory with the following content:
    <?xml version="1.0" encoding="UTF-8"?>  <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">    <display-name>SQLTest</display-name>  </web-app>
    • Create an index. jsp file under the webtest directory with the following content (Be sure to edit with UTF-8 ):
    <% @ Page language = "java" contentType = "text/html; charset = UTF-8 "pageEncoding =" UTF-8 "%> <meta http-equiv =" Content-Type "content =" text/html; charset = UTF-8 "/> <! -- First import some necessary packages --> <% @ page import = "java. io. * "%> <% @ page import =" java. util. * "%> <% @ page import =" java. SQL. * "%> <% @ page import =" javax. SQL. * "%> <% @ page import =" javax. naming. * "%> <! -- Set Chinese output --> 

    Here we have completed a simple JSP Web application. 12. Deploy Web applications in Weblogic

    • On the Weblogic Management page, select "deployment" To Go To The Deployment Management page.

  • Click "Install" to go to the directory selection page, select the webtest directory you just created, and click "Next ".
  • Select "deploy and install the application" and click Next.
  • Set the properties of the web application and retain the default value. Click Finish to complete the deployment of the web application. In this case, a new Web application --- webtest is added to the deployment.
  • Open a browser and enter http: // localhost: 7001/webtest/index. jsp in the address bar? Param1 = zhangsan
    The correct result is returned.
    Next we will return to JMeter and start the HTTP method creation test.13. Add a thread group to JMeter.

    • Right-click "My database test plan" on the left and choose "add"> "Threads (Users)"> "thread group" from the shortcut menu to create a new thread group.
    • On the attribute interface on the right, rename the created thread group to "HTTP mode ". Set attributes as follows:
      • Number of Threads --- set to 5.
      • Ramp-Up Period (in seconds) --- set to 5.
      • Loop Count --- set to 1.

    14. Create an HTTP test case

    • Right-click "HTTP mode" on the left and choose "add"> "Sampler"> "HTTP request" from the shortcut menu. A new HTTP test case is created. Set attributes as follows:
      • Server name or IP address --- set the IP address of the Weblogic Server. Set it to localhost.
      • Port Number --- set the port for Weblogic application listening. Set this parameter to 7001.
      • Path --- the Web page path used in the test case. Here we use the index. jsp we just created and set it to/webtest/index. jsp.
      • Parameters sent together with the request-you can specify parameters to be sent to the Web application using GET or POST methods. Here we click "add" to add a line with the name set to param1, value: $ {__ CSVRead (D: \ download \ c.csv, 0 )}

    15. Add listeners

    • Right-click "HTTP mode" on the left and choose "add"> listener ">" Aggregate Graph "from the shortcut menu to view the overview result.
    • Right-click "HTTP mode" on the left and choose "add"> "listener"> "view result tree" from the shortcut menu to view the details of each request, including parameter content, response results, and corresponding time.
    • Right-click "HTTP mode" on the left and choose "add"> "listener"> "view results in a table" from the shortcut menu. You can view the performance test results in a table.
    • Choose "run"> "start" from the menu to start the test. After the test is completed, you can use these three listeners to view the test results.
    16. Conclusion

    Finished

     

    Related Article

    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.