2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2020-03-27 00:07:39 -04:00
|
|
|
|
|
|
|
package disk
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
2020-04-12 22:37:09 -04:00
|
|
|
"github.com/dustin/go-humanize"
|
2021-05-06 11:52:02 -04:00
|
|
|
"github.com/minio/madmin-go"
|
2020-03-27 00:07:39 -04:00
|
|
|
"github.com/montanaflynn/stats"
|
|
|
|
)
|
|
|
|
|
2020-11-20 15:52:53 -05:00
|
|
|
// GetHealthInfo about the drive
|
2021-05-06 11:52:02 -04:00
|
|
|
func GetHealthInfo(ctx context.Context, drive, fsPath string) (madmin.DiskLatency, madmin.DiskThroughput, error) {
|
2020-03-27 00:07:39 -04:00
|
|
|
|
2020-04-12 22:37:09 -04:00
|
|
|
// Create a file with O_DIRECT flag, choose default umask and also make sure
|
|
|
|
// we are exclusively writing to a new file using O_EXCL.
|
|
|
|
w, err := OpenFileDirectIO(fsPath, os.O_CREATE|os.O_WRONLY|os.O_EXCL, 0666)
|
2020-03-27 00:07:39 -04:00
|
|
|
if err != nil {
|
2021-05-06 11:52:02 -04:00
|
|
|
return madmin.DiskLatency{}, madmin.DiskThroughput{}, err
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
2020-04-12 22:37:09 -04:00
|
|
|
|
2020-03-27 00:07:39 -04:00
|
|
|
defer func() {
|
2020-04-12 22:37:09 -04:00
|
|
|
w.Close()
|
|
|
|
os.Remove(fsPath)
|
2020-03-27 00:07:39 -04:00
|
|
|
}()
|
|
|
|
|
2020-04-12 22:37:09 -04:00
|
|
|
blockSize := 4 * humanize.MiByte
|
|
|
|
fileSize := 256 * humanize.MiByte
|
2020-03-27 00:07:39 -04:00
|
|
|
|
|
|
|
latencies := make([]float64, fileSize/blockSize)
|
|
|
|
throughputs := make([]float64, fileSize/blockSize)
|
|
|
|
|
2020-04-12 22:37:09 -04:00
|
|
|
data := AlignedBlock(blockSize)
|
2020-03-27 00:07:39 -04:00
|
|
|
|
2020-04-12 22:37:09 -04:00
|
|
|
for i := 0; i < (fileSize / blockSize); i++ {
|
2020-03-27 00:07:39 -04:00
|
|
|
if ctx.Err() != nil {
|
2021-05-06 11:52:02 -04:00
|
|
|
return madmin.DiskLatency{}, madmin.DiskThroughput{}, ctx.Err()
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
startTime := time.Now()
|
2020-04-12 22:37:09 -04:00
|
|
|
if n, err := w.Write(data); err != nil {
|
2021-05-06 11:52:02 -04:00
|
|
|
return madmin.DiskLatency{}, madmin.DiskThroughput{}, err
|
2020-04-12 22:37:09 -04:00
|
|
|
} else if n != blockSize {
|
2021-05-06 11:52:02 -04:00
|
|
|
return madmin.DiskLatency{}, madmin.DiskThroughput{}, fmt.Errorf("Expected to write %d, but only wrote %d", blockSize, n)
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
2020-04-12 22:37:09 -04:00
|
|
|
latencyInSecs := time.Since(startTime).Seconds()
|
2020-08-24 15:11:20 -04:00
|
|
|
latencies[i] = latencyInSecs
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
|
2020-07-27 17:51:59 -04:00
|
|
|
// Sync every full writes fdatasync
|
|
|
|
Fdatasync(w)
|
|
|
|
|
2020-03-27 00:07:39 -04:00
|
|
|
for i := range latencies {
|
|
|
|
throughput := float64(blockSize) / latencies[i]
|
|
|
|
throughputs[i] = throughput
|
|
|
|
}
|
|
|
|
|
|
|
|
var avgLatency float64
|
|
|
|
var percentile50Latency float64
|
|
|
|
var percentile90Latency float64
|
|
|
|
var percentile99Latency float64
|
|
|
|
var minLatency float64
|
|
|
|
var maxLatency float64
|
|
|
|
|
|
|
|
var avgThroughput float64
|
|
|
|
var percentile50Throughput float64
|
|
|
|
var percentile90Throughput float64
|
|
|
|
var percentile99Throughput float64
|
|
|
|
var minThroughput float64
|
|
|
|
var maxThroughput float64
|
|
|
|
|
|
|
|
if avgLatency, err = stats.Mean(latencies); err != nil {
|
2021-05-06 11:52:02 -04:00
|
|
|
return madmin.DiskLatency{}, madmin.DiskThroughput{}, err
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
if percentile50Latency, err = stats.Percentile(latencies, 50); err != nil {
|
2021-05-06 11:52:02 -04:00
|
|
|
return madmin.DiskLatency{}, madmin.DiskThroughput{}, err
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
if percentile90Latency, err = stats.Percentile(latencies, 90); err != nil {
|
2021-05-06 11:52:02 -04:00
|
|
|
return madmin.DiskLatency{}, madmin.DiskThroughput{}, err
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
if percentile99Latency, err = stats.Percentile(latencies, 99); err != nil {
|
2021-05-06 11:52:02 -04:00
|
|
|
return madmin.DiskLatency{}, madmin.DiskThroughput{}, err
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
if maxLatency, err = stats.Max(latencies); err != nil {
|
2021-05-06 11:52:02 -04:00
|
|
|
return madmin.DiskLatency{}, madmin.DiskThroughput{}, err
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
if minLatency, err = stats.Min(latencies); err != nil {
|
2021-05-06 11:52:02 -04:00
|
|
|
return madmin.DiskLatency{}, madmin.DiskThroughput{}, err
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
2021-05-06 11:52:02 -04:00
|
|
|
l := madmin.DiskLatency{
|
2020-03-27 00:07:39 -04:00
|
|
|
Avg: avgLatency,
|
|
|
|
Percentile50: percentile50Latency,
|
|
|
|
Percentile90: percentile90Latency,
|
|
|
|
Percentile99: percentile99Latency,
|
|
|
|
Min: minLatency,
|
|
|
|
Max: maxLatency,
|
|
|
|
}
|
|
|
|
|
|
|
|
if avgThroughput, err = stats.Mean(throughputs); err != nil {
|
2021-05-06 11:52:02 -04:00
|
|
|
return madmin.DiskLatency{}, madmin.DiskThroughput{}, err
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
if percentile50Throughput, err = stats.Percentile(throughputs, 50); err != nil {
|
2021-05-06 11:52:02 -04:00
|
|
|
return madmin.DiskLatency{}, madmin.DiskThroughput{}, err
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
if percentile90Throughput, err = stats.Percentile(throughputs, 90); err != nil {
|
2021-05-06 11:52:02 -04:00
|
|
|
return madmin.DiskLatency{}, madmin.DiskThroughput{}, err
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
if percentile99Throughput, err = stats.Percentile(throughputs, 99); err != nil {
|
2021-05-06 11:52:02 -04:00
|
|
|
return madmin.DiskLatency{}, madmin.DiskThroughput{}, err
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
if maxThroughput, err = stats.Max(throughputs); err != nil {
|
2021-05-06 11:52:02 -04:00
|
|
|
return madmin.DiskLatency{}, madmin.DiskThroughput{}, err
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
if minThroughput, err = stats.Min(throughputs); err != nil {
|
2021-05-06 11:52:02 -04:00
|
|
|
return madmin.DiskLatency{}, madmin.DiskThroughput{}, err
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
2020-10-01 12:50:08 -04:00
|
|
|
|
2021-05-06 11:52:02 -04:00
|
|
|
t := madmin.DiskThroughput{
|
2020-03-27 00:07:39 -04:00
|
|
|
Avg: avgThroughput,
|
|
|
|
Percentile50: percentile50Throughput,
|
|
|
|
Percentile90: percentile90Throughput,
|
|
|
|
Percentile99: percentile99Throughput,
|
|
|
|
Min: minThroughput,
|
|
|
|
Max: maxThroughput,
|
|
|
|
}
|
|
|
|
|
|
|
|
return l, t, nil
|
|
|
|
}
|