白话Elasticsearch48-深入聚合数据分析之 Percentiles Aggregation-percentiles百分比算法以及网站访问时延统计及Percentiles优化
生活随笔
收集整理的這篇文章主要介紹了
白话Elasticsearch48-深入聚合数据分析之 Percentiles Aggregation-percentiles百分比算法以及网站访问时延统计及Percentiles优化
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
文章目錄
- 概述
- 官方說明
- 示例
- Percentiles優(yōu)化 compression
概述
繼續(xù)跟中華石杉老師學習ES,第48篇
課程地址: https://www.roncoo.com/view/55
官方說明
Percentiles Aggregation: 戳這里
示例
需求: 網(wǎng)站訪問時延統(tǒng)計
為了演示該功能,我們先建個索引,模擬一批數(shù)據(jù)
#新建索引 PUT /website {"mappings": {"logs": {"properties": {"latency": {"type": "long"},"province": {"type": "keyword"},"timestamp": {"type": "date"}}}} } #模擬數(shù)據(jù) POST /website/logs/_bulk { "index": {}} { "latency" : 105, "province" : "江蘇", "timestamp" : "2018-10-28" } { "index": {}} { "latency" : 83, "province" : "江蘇", "timestamp" : "2018-10-29" } { "index": {}} { "latency" : 92, "province" : "江蘇", "timestamp" : "2018-10-29" } { "index": {}} { "latency" : 112, "province" : "江蘇", "timestamp" : "2018-10-28" } { "index": {}} { "latency" : 68, "province" : "江蘇", "timestamp" : "2018-10-28" } { "index": {}} { "latency" : 76, "province" : "江蘇", "timestamp" : "2018-10-29" } { "index": {}} { "latency" : 101, "province" : "新疆", "timestamp" : "2018-10-28" } { "index": {}} { "latency" : 275, "province" : "新疆", "timestamp" : "2018-10-29" } { "index": {}} { "latency" : 166, "province" : "新疆", "timestamp" : "2018-10-29" } { "index": {}} { "latency" : 654, "province" : "新疆", "timestamp" : "2018-10-28" } { "index": {}} { "latency" : 389, "province" : "新疆", "timestamp" : "2018-10-28" } { "index": {}} { "latency" : 302, "province" : "新疆", "timestamp" : "2018-10-29" }DSL:
#網(wǎng)站訪問時延統(tǒng)計(50% 95% 99%的請求) GET /website/logs/_search {"size": 0,"aggs": {"latency_percentiles": {"percentiles": {"field": "latency","percents": [50,95,99]}},"latency_avg": {"avg": {"field": "latency"}}} }返回:
{"took": 3,"timed_out": false,"_shards": {"total": 5,"successful": 5,"skipped": 0,"failed": 0},"hits": {"total": 12,"max_score": 0,"hits": []},"aggregations": {"latency_avg": {"value": 201.91666666666666},"latency_percentiles": {"values": {"50.0": 108.5,"95.0": 627.4999999999997,"99.0": 654}}} }可知,
- 50%的請求 在 108.5毫秒
- 95%的請求 在 627.5毫秒
- 99%的請求 在 654毫秒
- 平均時延 201.9毫秒
數(shù)值的最大的值是多少,不是完全準確的
需求二:按地區(qū)分組后看下每個地區(qū)的 網(wǎng)站訪問時延統(tǒng)計
GET /website/_search {"size": 0,"aggs": {"group_by_province": {"terms": {"field": "province"},"aggs": {"latency_percentiles": {"percentiles": {"field": "latency","percents": [50,95,99]}},"latency_avg": {"avg": {"field": "latency"}}}}} }返回:
Percentiles優(yōu)化 compression
compression 官方指導: 戳這里
TDigest算法,用很多節(jié)點來執(zhí)行百分比的計算,近似估計,有誤差,節(jié)點越多,越精準
compression ,限制節(jié)點數(shù)量最多 compression * 20 = 2000個node去計算 ,默認100
compression 越大,占用內(nèi)存越多,越精準,性能越差
一個節(jié)點占用32字節(jié),100 * 20 * 32 = 64KB
簡單來說: 如果你想要percentile算法越精準,compression可以設置的越大
總結
以上是生活随笔為你收集整理的白话Elasticsearch48-深入聚合数据分析之 Percentiles Aggregation-percentiles百分比算法以及网站访问时延统计及Percentiles优化的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 白话Elasticsearch47-深入
- 下一篇: 白话Elasticsearch49-深入