높은 사용률(Hotness) 기록
현재 사용량이 높은 테이블이 무엇인지 보여주는 hotness_current라고 유용한 도구가 있지만, 더 오랜 기간 동안 사용량이 높은 테이블을 조회할 수 있는 테이블이 있습니다. 이것는 CLUSTRIX_STATD.HOTNESS_HISTORY 테이블입니다.
mysql> show create table hotness_history \G
*************************** 1. row ***************************
Table: hotness_history
Create Table: CREATE TABLE `hotness_history` (
`timestamp` timestamp not null default current_timestamp,
`read_rank` int(11) unsigned,
`write_rank` int(11) unsigned,
`node` int(11) unsigned not null,
`database` varchar(256) CHARACTER SET utf8 not null,
`table` varchar(256) CHARACTER SET utf8 not null,
`index` varchar(256) CHARACTER SET utf8 not null,
`reads` int(11) unsigned,
`writes` int(11) unsigned,
`replicas` int(11) unsigned,
`ranked_replicas` int(11) unsigned,
`total_replicas` int(11) unsigned,
PRIMARY KEY (`timestamp`,`node`,`database`,`table`,`index`) /*$ DISTRIBUTE=5 */,
KEY `timestamp_2` (`timestamp`,`write_rank`) /*$ DISTRIBUTE=2 */,
KEY `timestamp` (`timestamp`,`read_rank`) /*$ DISTRIBUTE=2 */
) CHARACTER SET utf8 /*$ REPLICAS=2 SLICES=4 CONTAINER=btree */
1 row in set (0.00 sec)
주요 필드는 다음과 같습니다.
- timestamp: 지난 5분 동안의 테이블 또는 인덱스에 대한 통계.
- read_rank: 그 시간 동안 테이블 또는 인덱스가 얼마나 읽기가 많았는지 표시.
- write_rank: 그 시간 동안 테이블 또는 인덱스가 얼마나 쓰기가 많았는지 표시.
- table: 사용율이 높은 테이블.
- index: 인덱스가 또는 base representation이 될 수 있습니다. Base representation은 _PRIMARY가 끝에 붙습니다.
- replicas: 해당 테이블 또는 인덱스의 복제본 수. 일반적으로 슬라이스 수는 데이터가 노드에 고루 분산되도록 노드 수와 같거나 커야 합니다.
클러스터는 통계를 낼 때 read_rank와 a write_rank를 가지고 각 테이블 또는 인덱스에 대해 순위를 매깁니다. 순위가 높은 테이블 또는 인덱스는 다른 representation보단 더 많은 읽기 또는 쓰기가 있었을 것입니다.
지난 24시간 동안의 평균 read_rank에 기초해 읽기가 높은 테이블을 찾으려면 다음을 쿼리를 사용하십시오.
SELECT Round(Avg(read_rank)) AS read_rank,
Round(Avg(write_rank)) AS write_rank,
Sum(reads) AS reads,
Sum(writes) AS writes,
DATABASE,
`table`,
`index`,
total_replicas
FROM clustrix_statd.hotness_history
WHERE timestamp >now() - INTERVAL 1 day
AND DATABASE NOT IN ('clustrix_statd', '_replication', 'clustrix_ui', 'system')
AND read_rank IS NOT NULL
GROUP BY `table`, `index`
ORDER BY read_rank ASC, write_rank ASC;
마찬가지로, 평균 write_rank에 기초해 쓰기가 높은 테이블에 대해서도 다음 쿼리를 사용할 수 있습니다.
SELECT Round(Avg(read_rank)) AS read_rank,
Round(Avg(write_rank)) AS write_rank,
Sum(reads) AS reads,
Sum(writes) AS writes,
DATABASE,
`table`,
`index`,
total_replicas
FROM clustrix_statd.hotness_history
WHERE timestamp >now() - INTERVAL 1 day
AND DATABASE NOT IN ('clustrix_statd', '_replication', 'clustrix_ui', 'system')
AND write_rank IS NOT NULL
GROUP BY `table`, `index`
ORDER BY write_rank ASC, read_rank ASC;
이러한 변형된 쿼리는 일정 시간동안 총 읽기 및 쓰기를 살펴보기 위한 것입니다.
읽기 합계별 높은 읽기:
SELECT Round(Avg(read_rank)) AS read_rank, Round(Avg(write_rank)) AS write_rank, Sum(reads) AS reads, Sum(writes) AS writes, DATABASE, `table`, `index`, total_replicas FROM clustrix_statd.hotness_history WHERE timestamp >now() - INTERVAL 1 day AND DATABASE NOT IN ('clustrix_statd', '_replication', 'clustrix_ui', 'system') AND read_rank IS NOT NULL GROUP BY `table`, `index` ORDER BY 3 DESC, 4 DESC;
쓰기 합계별 높은 쓰기:
SELECT Round(Avg(read_rank)) AS read_rank,
Round(Avg(write_rank)) AS write_rank,
Sum(reads) AS reads,
Sum(writes) AS writes,
DATABASE,
`table`,
`index`,
total_replicas
FROM clustrix_statd.hotness_history
WHERE timestamp >now() - INTERVAL 1 day
AND DATABASE NOT IN ('clustrix_statd', '_replication', 'clustrix_ui', 'system')
AND write_rank IS NOT NULL
GROUP BY `table`, `index`
ORDER BY 4 DESC, 3 DESC;
테이블 사용률이 높고 복제본의 수가 노드 수의 두배 이하이면 로드 불균형이 발생할 수 있습니다.
사용률이 높은 테이블은 누락된 최적화되지 못한 쿼리를 나타낼 수 있으며 추가 조사가 필요할 수 있습니다.
0 댓글