Notes
  • Introduce
  • Go
    • Grammar
      • Basic
      • Goroutines & Channels
      • Test
    • System Library
      • Module
      • sync
      • context
      • net
    • Concurrency in Go
    • The Go Memory Model
    • Code Snippet
  • Rust
    • The Rust Programming Language
    • Rust by Example
  • JAVA
    • Preface
    • Grammar
      • Basic
      • Data Types
      • Operator
      • Exceptions
    • Class Libraries
      • Collection
      • Stream
      • IO
      • NIO
      • RMI
    • Concurrency
      • Preface
      • JMM
      • Synchronized & CAS
      • Deadlock
      • Thread
      • Lock & Condition
      • Utility Class
      • Thread-safe Collection
      • Atomic Class
      • Fork/Join
      • Concurrency Design Patterns
        • Immutable
        • Copy-on-Write
        • ThreadLocal
        • Multitheading If
        • Division
    • JVM
      • Class & Instance Initialization
      • Runtime Data Area
      • Garbage Collection
    • Web Container
      • Tomcat Architecture
      • Jetty Architecture
    • Spring
    • Tuning
      • Programming
  • Computer Science
    • Computer Organization
    • Algorithm
      • Complexity
      • Linear List
      • Sort
      • Binary Search
      • Skip List
      • Hash Table
      • Tree
      • Graph
      • String Matching
      • Bloom Filter
      • Greedy Algorithm
      • Divide and Conquer
      • Back Tracking
      • Dynamic Programming
    • Network Protocol
      • Pysical Layer
      • Data Link Layer
      • Network Layer
      • Transport Layer
      • Application layer
      • HTTP
      • HTTP/2 in Action
    • Operating System
      • Basic
      • System Initialization
      • Diagnostic Tools
      • CPU Diagnosis
      • Memory Diagnosis
      • Disk Diagnosis
      • Network Diagnosis
      • Monitor System
    • Design Patterns
      • UML
      • OOP
      • Principle
      • Refactoring & Specification
      • Creational
        • Singleton
        • Factory
        • Builder
        • Prototype
      • Structural
        • Proxy
        • Bridge
        • Decorator
        • Adapter
        • Facade
        • Composite
        • FlyWeight
      • Behavioral
        • Observer
        • Template Method
        • Strategy
        • State
        • Iterator
        • Chain of Responsibility
    • Distributed System
      • Protocol & Algorithm
      • Transcation
      • Theory
      • Resource Management
      • Scheduling
      • Computing
      • Message Queue
      • Cache
      • Consistent Hashing
  • database
    • InfluxDB
      • In-Memory Index
      • Meta
    • MySQL
      • SQL
      • Architecture
      • Log
      • Transaction
      • Indexing
      • Lock
      • Storage
    • Redis
    • Elasticsearch
      • Local Debug
    • HBase
    • Kafka
    • ZooKeeper
  • Reading
    • RocketMQ
    • 演说之禅
    • So Good They Can't Ignore You
    • 学会提问
    • Lecture
  • Other
    • v2ray
    • Kubernetes
    • Git
    • Maven
    • Anaconda And Conda
    • Fuck! Shit!
      • Remove Final by Reflection
      • Ingress Host
      • ExecuterService submit
  • Open source contribution
Powered by GitBook
On this page
  • 性能指标
  • 性能参考因素
  • 指标
  • 性能测试
  • 性能优化
  • 兜底策略
  • 性能测试工具

Was this helpful?

  1. JAVA

Tuning

PreviousSpringNextProgramming

Last updated 5 years ago

Was this helpful?

Java 性能调优主要从 、多线程、JVM、设计模式、数据库等多个方面来介绍。

不过在调优之前先需要了解、、等,见下文。

性能指标

性能参考因素

  • CPU:计算型引用、FullGC、无限循环、多线程大量上下文切换都可能造成 CPU 繁忙。

  • 内存:

  • 磁盘 I/O:

  • 异常:构建异常栈非常消耗资源。

  • 数据库:

  • 锁竞争:

指标

  • 响应时间:

    • 数据库响应时间

    • 服务端响应时间

    • 网络响应时间

    • 客户端响应时间

  • 吞吐量

    • 磁盘吞吐量

      • IOPS:随机读写,如 OLTP 数据库、小文件存储等。

      • 吞吐量:顺序读写,如视频点播等。

    • 网络吞吐量:涉及 CPU、网卡、宽带等。

  • 计算机资源使用率

    • CPU 占用率

    • 内存使用率

    • 磁盘 I/O 使用率

    • 网络 I/O 使用率

  • 系统负载

系统负载 vs CPU 利用率。系统负载表示正在运行或等待的进程或线程数,CPU 利用率表示单位时间内实时占用 CPU 的百分比。如计算密集型,CPU 利用率会很高,但是系统负载可能为 0.1;I/O 密集型,CPU 利用率可能很低,但是系统负载很高,因为很多线程可能在阻塞。

TPS vs QPS。TPS(transaction per second),QPS(query per second)。一个事务可能包含多个请求,若一个用户操作只有一个请求,那么 TPS 和 QPS 就没有区别。

性能测试

  • 微基准测试

  • 宏基准测试

性能测试注意的问题:

  • 热身

  • 结果不稳定

性能优化

  • 代码

  • 设计

  • 算法

  • 时间换空间

  • 空间换时间

  • 参数调优

兜底策略

  • 限流

  • 熔断

  • 自动扩容

  • 提前扩容

性能测试工具

工具

适用场景

优点

缺点

ab

单个接口的性能测试

简单实用

不能对整个业务流程测试

JMeter

简单并发测试、整个业务流程测试、组合并发测试、csv 动态导入变量

功能全,可扩展性高

性能不稳定,高并发容易造成界面卡死

LoadRunner

包括JMeter 的常用功能,可以 IP 欺骗

专业、稳定、高效

价格高

Java 编程
性能指标
性能测试
常用手段