Tsung study notes (HTTP)

Let's test a static web page first.

This can be regarded as the most pitted place in tsung's documentation. If you follow the getting started guide on the official website step by step, I can tell you that it will not work! The reason is that the configuration file generated by the tool tsung-recorder given by tsung is not a complete configuration file! ! If you want to get started, forget tsung-recorder and follow the steps exactly, otherwise you will end up with all kinds of runtime exceptions.

1. Create a file~/.tsung/tsung.xml

The content is as follows:

<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd">
<tsung>
  <clients>
    <!-- 在这里添加测试主机(客户端) -->
  </clients>

  <servers>
    <!-- 在这里添加被测试的主机(服务端) -->
  </servers>

  <load>
    <!-- 在这里添加加载过程配置 -->
  </load>

  <sessions>
    <!-- 在这里添加会话(即一系列HTTP请求) -->
  </sessions>
</tsung>

The above is the skeleton of the minimum configuration of tsung. There cannot be one thing in it, and it must be configured in this order! ! (Damn the official documentation, when I read it, there is a rush to see the trees but not the forest).

2. Add client

A client (client) is a system process (Erlang/Elixir programmers note that it is a system process, not a BEAM process. A system process is an Erlang virtual machine).

<clients>
  <client host="localhost" cpu="4" maxusers="30000"/>
</clients>

A client is defined here, which opens 4 processes on the localhost host to send requests at the same time. It is best to set cputhe value equal to the number of CPUs of the host, too low to fully utilize the performance of the test host, and too high to have some concurrency problems. Tsung guarantees that these processes will be distributed on different CPU cores. Note: Tsung will start the process remotely via SSH, even if the client is on the local machine, and will not use a password. So make sure SSH is configured for PublicKey authentication and add localhost to known_hosts. If you really don't want to use SSH to open a new process, you can configure it as follows:

<client host="localhost" use_controller_vm="true" maxusers="30000"/>

The parameter maxuserssets the maximum number of users that the client can virtualize at the same time, which is equivalent to the amount of concurrency. Note that if this value is greater than yours ulimit -Sn, tsung will open multiple system processes to ensure this value.

3. Add server (tested host)

The configuration of the server is relatively simple:

<servers>
  <server host="localhost" port="80" type="tcp"/>
</servers>

Since the application of the server (under test) can be any HTTP application, there is no Erlang process configuration, and friends who are familiar with HTTP should understand it at a glance.

4. Add load process configuration

The so-called loading process is how many (virtual) users are generated in how long.

<load>
  <arrivalphase phase="1" duration="1" unit="minute">
    <users arrivalrate="10000" unit="second"/>
  </arrivalphase>
</load>

A user arrival phase is defined here. The total duration of this phase is 1 minute. During this minute, 10,000 virtual users will visit every second. You can add more stages and configure more user arrival patterns in each stage.

5. Add a session

The so-called session is what each user does successively. For HTTP testing, of course, it means sending requests and receiving responses. Tsung automatically manages cookies for each session.

<sessions>
  <session name="s1" type="ts_http">
    <request>
      <http url="/" method="GET" version="1.1"/>
    </request>
    <thinktime min="2" max="10" random="true">
  </session>
</session>

In this example, each user's session will do two things:

  1. Send an HTTP 1.1 GET request to /, and receive a response
  2. After receiving the response, "thinking" for a while (can be used to simulate the time to read a web page), the time varies from 2 seconds to 10 seconds (evenly distributed)

At this point, the entire configuration is complete. Here is the content of the complete configuration file ( ~/.tsung/tsung.xml):

<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd">
<tsung>
  <clients>
    <client host="localhost" cpu="4" maxusers="30000"/>
  </clients>

  <servers>
    <server host="localhost" port="80" type="tcp"/>
  </servers>

  <load>
    <arrivalphase phase="1" duration="1" unit="minute">
      <users arrivalrate="10000" unit="second"/>
    </arrivalphase>
  </load>

  <sessions>
    <session name="s1" type="ts_http" weight="1">
      <request>
        <http url="/" method="GET" version="1.1"/>
      </request>
      <thinktime min="2" max="10" random="true"/>
    </session>
  </sessions>
</tsung>

Regarding weight=1this configuration, it has no effect in the case of a single session, but it still has to be configured. If you have multiple sessions, the weight indicates the relative proportion of each session. For example, if you have two sessions, s1:weight=1and s2:weight=2, and there are a total of 30,000 users, the session type used for 10,000 is s1, and the session type used for 20,000 is s2.

If you want to configure more advanced configuration (such as random request parameters, virtual IP, etc.), please refer to the official documentation .

6. Run the test

Let's run

$ tsung start

While running, we can open a browser and visit http://localhost:8091/ to see the summary. But to be honest, this thing is useless, because when the test is finished, the built-in server of this tsung will be shut down (you can use it tsung -k startto prevent this server from shutting down automatically). And the webpage will not be updated in real time, and you have to brush it manually.

Pay attention to the prompt information on the tsung command line, it will tell you where the log is located, usually ~/.tsung/log/xxxx. This is very important, because we are going to enter this directory to generate the chart!

7. Generate visual reports

First cdgo to the above log location, then run the following command:

$ tsplot "Nginx" ./tsung.log -d .

This will generate a bunch of graphs in the current directory, including the number of connections, users, requests, etc., and each indicator has two graphs, large and small. Check it out for yourself. If you want to export the report to another location, just modify -dthe parameters.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324937893&siteId=291194637