• Github micro service
  • Github Mall front-end project -Vue

Performance pressure measurement and optimization

Pressure test

  • Stress testing looks at the maximum load a system can handle in its current hardware and software environment and helps identify system bottlenecks. Pressure measurement is to maintain the system’s online processing capacity and stability within a standard range, so as to know
  • With stress testing, we can hopefully find a wide variety of errors that are harder to find with other testing methods. There are two types of errors: memory leak, concurrency, and synchronization
  • An effective stress test system will apply the following key conditions: repetition, concurrency, magnitude, and random variation

Performance indicators

  • Response Time (Respone Time: RT)

    Response time refers to the time taken from the time the user initiates a request to the time the client receives a response from the server

  • HPS (Hits Per Second) : indicates the number of Hits Per Second, expressed in Hits Per Second

  • TPS (Transaction per Second) : The number of transactions processed by the system per Second

  • Query Per Second (QPS) : indicates the number of queries processed by the system Per Second. The unit is times Per Second

    For Internet services, if some services have only one connection request, then TPS=QPS=HPS. Generally, TPS is used to measure the entire business process, QPS is used to measure the number of interface queries, and HPS is used to represent the request to the server

  • Whether TPS, QPS or HPS, this indicator is a very important indicator to measure the system’s processing capacity. The larger the better. According to experience, in general:

    • Financial industry: 1000TPS~ 5000Tps, excluding internet-based activities
    • Insurance industry: 100TPS~100000TPS, excluding internet-based activities
    • Manufacturing industry: 10TPS~5000TPS
    • Internet E-commerce: 10000TPS~1000000TPS
    • Internet medium site: 1000TPS~ 5000tps
    • Internet small websites: 500TPS~10000TPS
  • Max Response Time: Indicates the maximum Response Time for a user to send a request or command to the system

  • Mininum Response Time: The minimum Time for a user to send a request or command to the system to respond

  • 90% Response Time: indicates the 90% Response Time of all users

  • Externally, performance testing focuses on the following three metrics

    • Throughput: The number of requests and tasks that the system can handle per second
    • Response time: How long it takes a service to process a request or a task
    • Error rate: The percentage of requests in a batch that result in an error

Pressure measuring tool JMeter

Download and install JMeter
  • Download address

    JMeter download

Use JMeter
  • Unpack the

  • Go to the bin directory and run jmeter.bat

JMeter pressure test example
  • 1: Add thread group (Add — thread (user) — thread group)

    Right-click the TestPlan

  • Thread attributes

    • Number of threads: How many users are simulated to access simultaneously
    • Ranp-up time (s) : The number of seconds in which threads complete the above Settings. For example, 200 threads in 10 seconds: indicates 20 requests per second
    • Loop count: represents the number of loops per thread. For example, if loop count =100, each thread requests 100 times, 200 threads equals 20000 times
  • 2: HTTP request (add — sampler –HTTP request)

    Specify the request interface, port, and parameters required for the request

  • 3: View baidu test results (add — listener — view result tree/summary report/aggregate report)

JMeter Address Already in use
  • The port access mechanism provided by Windows is faulty.

  • Windows provides ports 1024-5000 for TCP/IP connections, and it takes four minutes to recycle them, which causes us to fill up the ports while running a lot of requests in a short time

  • The solution

    • 1. In CMD, run regedit to open the registry

    • HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

Impact performance considerations

  • Databases, applications, middleware (Tomcat, Nginx), networks and operating systems, etc
  • Consider whether your application is CPU intensive or IO intensive

Performance monitoring

JVM memory model

  • JVM memory model

  • Program Counter Register

    • It records the address of the virtual machine bytecode instruction being executed
    • This memory region is the only one that does not specify any OutofMemoryErrors in the JAVA Virtual Machine specification
  • ‘Virtual Machine: VM Stack

    • It describes the memory model of JAVA method execution. Each method creates a stack frame during execution, which is used to store information such as local variable table, operand stack, dynamic link, method interface, etc
    • The local variable table stores various basic data types and object references that are known to the compiler
    • A StackOverFlowError is raised when the stack depth of thread requests is insufficient
    • An OutOfMemoryError is reported when the stack dynamic expansion capacity is insufficient
    • The virtual stack is thread-isolated, meaning that each thread has its own independent virtual stack
  • Native method: Native Stack

    • The local method stack is similar to the virtual machine stack, except that the local method stack uses local methods
  • Heap: Heap

    • Almost all object instances allocate memory on the heap

The heap

  • All object instances and arrays are allocated on the heap. The heap is the main area managed by the garbage collector, also known as the “GC heap”; And that’s where we think most about optimization

    The heap can be subdivided into:

    • The new generation
      • Eden Space (Eden Park)
      • FromSurvivor space (Surviving 0 zone)
      • ToSurvivor space (Zone 1)
    • The old s
    • Permanent generation/meta-space
      • Java8 before the permanent generation, managed by the JVM, java8 after the meta space, direct use of physical memory. Therefore, by default, the size of the meta-space is limited only by local memory
  • The garbage collection

    Garbage Collection Flowchart

Jconsole and jvisualvm

  • JDK two small tools jConsole, JVisualVM (upgraded version of JConsole); You can monitor local and remote applications by using the command line. Remote applications need to be configured
jvisualvm
  • Monitor memory leaks, track garbage collection, execute memory, CPU analysis, thread analysis…

  • CMD start jvisualvm

    Run: Running thread

    Sleep, sleep

    Wait, wait

    Resident: Idle threads in a thread pool

    Monitor: blocked thread, waiting for lock

Installing plug-ins makes it easy to view GC
  • Tools — Plug-in installation — Visual GC (Install complete, restart JVisualVM)

Monitoring indicators

Middleware metrics
  • Monitor the nginx

    • Docker Stats checks container resource usage

    • Jmeter pressure test nginx (192.168.83.133:80/) 50 threads loop all the time

      It is observed that nginx is predominantly CPU intensive, with little change in memory

  • Monitoring the gateway

    • Jmeter pressure test GateWay (localhost:9527/) 50 threads loop

      Also occupies CPU, but Eden areagcExtremely frequently, this block can be modified to improve throughput

  • Pressure test home page full data

    • Static resources include HTML, JS, and CSS

Database Specifications
Optimization – Nginx static and static separation
  • Since both dynamic and static resources are currently on the server side, we put js, CSS, IMG and other static resources on the Nginx side to reduce the server pressure

  • Copy the index from the static project directory to the mount file/HTML /static of nginx

    • Modify mall. Conf in conf/conf.d/

      # add location /static/ {root /usr/share/nginx/ HTML /; }Copy the code

Pressure Measurement Report (*)
  • Data statistics for different content pressure measurement

    Pressure test content Pressure the number of threads Throughput/s 90% response time /ms 99% response time /ms
    Nginx 50 6721 14 22
    GateWay 50 16211 5 16
    Simple services



    localhost:12000/hello
    50 24715 3 8
    GateWay+ Simple services



    localhost:9527/hello
    50 6300 15 76
    Nginx+GateWay+ Simple Service (full link)

    mall.com/hello
    50 120 1644 2453
    Home page level menu rendering

    localhost:12000/
    50 445(db,thymeleaf) 163 248
    Home page level 1 menu rendering (Thymeleaf caching enabled)

    localhost:12000/
    50 528(db) 143 227
    Home page level 1 menu rendering (Open cache & Optimize database (add index)& Off log)

    localhost:12000/
    50 1244 66 116
    Three-level classification data acquisition

    localhost:12000/index/catalog.json
    50 3.8 (db cause) 13205 13519
    Three-level classified data acquisition (change from multiple database search to one database search)

    localhost:12000/index/catalog.json
    50 218 330 536
    Tertiary classification data acquisition (indexed)

    localhost:12000/index/catalog.json
    50 16.7 3314 3554
    Home page full data acquisition

    localhost:12000/
    50 7(Static Resources) 6603 6740
    Home page full data acquisition (static and static separation)

    localhost:12000/
    50 36.3 1565 2018
  • Test Conclusions:

    • The more middleware there is, the greater the performance penalty, most of it in network interaction
    • Business:
      • DB (MySQL optimization: server, index…)
      • Template rendering speed (cache)
      • Static resources (static separation)
    • Gc memory allocation is incorrect

Optimize three-level classification data acquisition

  • Previous versions used nested loops to query the database

  • Optimization idea

    • 1, change the database multiple queries into one

      com.touch.air.mall.product.service.impl.CategoryServiceImpl.getCatalogJson
      Copy the code