I use influx db to save my website's performance data。The data in my influx db like below:
//mock data
time load
---- ----
2018-11-27T08:34:46.899z 262
2018-11-27T08:35:46.899z 300
2018-11-27T08:36:46.899z 102
2018-11-27T08:37:46.899z 1000
2018-11-27T08:38:46.899z 800
2018-11-27T08:39:46.899z 6000
2018-11-27T08:40:46.899z 326
2018-11-27T08:41:46.899z 500
2018-11-27T08:42:46.899z 90
2018-11-27T08:43:46.899z 902
My purpose is to get the distribution of the load value. For example, I want to get the load time's distribution in the form like below:
load frequent
---- ----
0~100 1
100~200 1
200~300 2
300~400 2
.
.
.
5000~6000 1
I try to resolve this problem in two ways, but I thought it not the best way to get this result.
(一) Query the whole load time, and then in my nodejs server to calculate this result. I think this solution will meet performance problem when I want to get one years or more time duration's distribution.
(二) At the same time of saving my raw data into influx db , I calculate the range of load time then save it into another influx db table, calculate table like below:
// load distribute table
time 100~200 200~300 300~400 .... 5000~6000
---- ---- ---- ---- ----
08:34:46 1
08:34:47 1
08:34:48 1
08:34:49 1
08:34:50 1
// then in the future I can get the distribution like this:
select count(*) from load_distribute