Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBRD-25888] Performance Enhancement for XASL Cache Memory Management #5948

Open
wants to merge 32 commits into
base: develop
Choose a base branch
from

Conversation

sohee-dgist
Copy link
Contributor

@sohee-dgist sohee-dgist commented Feb 25, 2025

http://jira.cubrid.org/browse/CBRD-25888

Purpose

XASL Cache의 메모리 사용량을 관리하는 로직과 Plan이 클 경우 Clone을 생성하지 않는 로직을 추가하였다.
Xasl Cache의 Plandump에 메모리 사용량을 보이도록 하여 User 입장에서 쉽게 Memory 사용량을 추적할 수 있도록 한다.

Implementation

  1. Hard Limit 추가
  2. Soft Limit이상이면 Clear하는 로직 추가
  3. Memory 사용량 관련 추적 변수 활성화
  4. Plan max size보다 클 경우 clone을 바로 decache하는 로직 추가

Remarks

hashmap의 iteration시 iter를 초기화 할때 bucket index의 초기화가 이루어지지 않는 부분을 별도로 수정하였다.
xasl cache는 session view와 session variable과 연관이 있으므로,
xasl cache를 아주 작게 설정하거나, invalidate할 경우 동작하지 않는다.

session variable은 result cache만 꺼도 동작하지 않는다.

다음의 내용이 메뉴얼에 추가될 예정이다.

SOHEE_JUNG added 8 commits February 17, 2025 17:39
- xasl cache memory 관리 로직 추가

  int soft_limit;
   -> hard limit의 0.8되는 size로 설정
  int hard_limit;
  int max_plan_size;
  volatile INT32 memory_usage_cache;
   -> cache memory 사용량 중 plan을 저장하는 부분
  volatile INT32 memory_usage_clone;
   -> cache memory 사용량 중 plan을 복사하는 부분

- memory가 다 차도 cache out 되도록 함.
- hard limit - soft limit 보다 큰 plan은 저장되지 못하도록 함.

- dump 에 추가

  entry의 메모리 사용량이 보이도록 함. (다만 아직 clone을 얼마만큼 사용하는지 확인 불가)
  전체 메모리 사용량이 보이도록 함.
decache 하위에서 clonesize를 계산하여 줄이도록 함.
- xasl cache clone size중 alloc buf의 사이즈는 사용하면 안 됨
- alloc_buf는 남은 사이즈를 의미함.

(feature) xasl cache memory cleanout 로직 변경

- candidate 지우는 로직 변경.
- count로 지우는 로직은 더이상 사용하지 않음.
- xasl cache cleanout 매커니즘 테스트시 entry transction id관련 버그
추후 retire 할 때 clone이 제거되므로, 해당 시점에 원래는 soft limit을 낮추는
것이 맞으나, 해당 방법으로는 계속해서 clone이 쌓여 soft limit을 넘어 memory
cleanout이 계속하여 일어난다.
cleanout시에 clone역시 지우도록 변경되었다.
This reverts commit 023140c.

# 제목: 변경 요약 (50자 이내)  (refactor, hotfix, feature)

# 본문: 변경 사항에 대한 자세한 설명
# - 주요 변경 사항 1
# - 주요 변경 사항 2

# 참고: 이 라인 아래의 내용은 커밋 메시지에서 제거됩니다.
@sohee-dgist sohee-dgist changed the title CBRD-25888 Performance Enhancement for XASL Cache Memory Management [CBRD-2588]8 Performance Enhancement for XASL Cache Memory Management Feb 25, 2025
@sohee-dgist sohee-dgist changed the title [CBRD-2588]8 Performance Enhancement for XASL Cache Memory Management [CBRD-25888] Performance Enhancement for XASL Cache Memory Management Feb 25, 2025
@sohee-dgist sohee-dgist marked this pull request as ready for review February 25, 2025 12:45
SOHEE_JUNG and others added 6 commits February 26, 2025 10:14
- soft limit 설정 누락됨
- hard limit temp 변수 원상 복구
temp size 수정정
xasl cache는 session view와 session variable과 연관이 있으므로,
xasl cache를 아주 작게 설정하거나, invalidate할 경우 동작하지 않는다.

session variable은 result cache만 꺼도 동작하지 않는다.

다음의 내용을 메뉴얼에 추가할 것.
@shparkcubrid
Copy link
Contributor

테스트 케이스 등록해주세요. 소스코드 리뷰시 테스트 케이스도 리뷰 대상입니다.

Copy link
Contributor

@xmilex-git xmilex-git left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline을 임의로 추가하거나 제거하면 git history 추적 시 혼동을 줄 우려가 있습니다. 확인하고 원래 코드대로 바꿔주시면 좋을것 같습니다.

Comment on lines +120 to +121
INT32 memory_usage_cache;
INT32 memory_usage_clone;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INT32의 최대값은 2,147,483,647입니다. xasl_cache로 2GB이상을 사용할 일이 있다면 오류 발생이 우려됩니다.

Copy link
Contributor

@xmilex-git xmilex-git Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 max_plan_cache_entries는 상한값이 없습니다. 기본값은 1000이므로 128MB 정도이지만 16384 이상으로 더 늘린다면 문제가 될 수도 있겠네요.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/* src/base/system_parameter.c, 3671 line */
  {PRM_ID_XASL_CACHE_MAX_ENTRIES,
   PRM_NAME_XASL_CACHE_MAX_ENTRIES,
   (PRM_FOR_CLIENT | PRM_FOR_SERVER | PRM_FORCE_SERVER),
   PRM_INTEGER,
   &prm_xasl_cache_max_entries_flag,
   (void *) &prm_xasl_cache_max_entries_default,
   (void *) &PRM_XASL_CACHE_MAX_ENTRIES,
   /* TODO: define a maximum value. We cannot have any size hash table. */
   (void *) NULL, (void *) NULL,
   (char *) NULL,
   (DUP_PRM_FUNC) NULL,
   (DUP_PRM_FUNC) NULL},

현재 상한선이 없는 파라미터라 적절한 조치가 필요할 듯 합니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파라미터에 대해서 상한과 하한을 정하고 낮을 경우나 높을경우 bad parameters 적용하도록 하겠습니다.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100(500?)~16000 정도의 범위로 설정하는 것으로 회의 때 논의하였습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

상한선 설정 완료 하였습니다. 하한은 적용하지 않았습니다.

@@ -2320,6 +2465,14 @@ xcache_cleanup (THREAD_ENTRY * thread_p)
XCACHE_STAT_INC (deletes_at_cleanup);
perfmon_inc_stat (thread_p, PSTAT_PC_NUM_DELETE);
ATOMIC_INC_32 (&xcache_Entry_count, -1);
ATOMIC_INC_32 (&xcache_Memory_usage_cache, -xcache_entry_get_entrysize (candidate.xcache));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그리고 위 2456라인의 주석은 삭제 혹은 적절하게 수정해 주세요.

@@ -2320,6 +2465,14 @@ xcache_cleanup (THREAD_ENTRY * thread_p)
XCACHE_STAT_INC (deletes_at_cleanup);
perfmon_inc_stat (thread_p, PSTAT_PC_NUM_DELETE);
ATOMIC_INC_32 (&xcache_Entry_count, -1);
ATOMIC_INC_32 (&xcache_Memory_usage_cache, -xcache_entry_get_entrysize (candidate.xcache));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

candidate가 꼭 삭제되지 않습니다. xcache_compare_key() 를 보면 cache_flag가 0인 경우에만 동일한 값으로 취급하고 삭제됩니다. fix된 entry는 삭제되지 않습니다. 오랜 기간 운영을 하다 보면 문제가 될 수 있겠네요. xcache_entry_uninit()에 추가하는 것이 좋아 보입니다.


int soft_limit;
int hard_limit;
int max_plan_size;
Copy link
Contributor

@youngjinj youngjinj Mar 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 값을 xcache_entry_get_one_clonesize ()와 비교하는데
저는 plan이라는 용어에서 혼란이 있습니다.
max_clone_size는 어떤가요?
혹시 plan이라는 용어를 사용해야 했던 이유가 있어서 공유해주시면
이 부분을 이해하는데 도움이 될 것 같습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

잘못 비교한 걸로 보입니다 수정하겠습니다

}
delete_xids[n_delete_xids++] = xcache_entry->xasl_id;
}
ATOMIC_INC_32 (&xcache_Memory_usage_cache, -xcache_entry_get_entrysize (xcache_entry));
Copy link
Contributor

@youngjinj youngjinj Mar 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 XASL을 사용 중인 상태에서 cubrid plandump -d demodb를 반복 실행하면 xcache_Memory_usage_cache가 반복해서 감소하는 것으로 확인됩니다. del_mark 시 최초 1회만 감소하게 하거나 실제로 제거하는 부분에서 감소시켜야 하는 것으로 보입니다.

drop table if exists t1;
create table t1 (c1 int, c2 int);
insert into t1 values (1, 1);

-- max_plan_cache_entries=10
-- max_plan_cache_clones=10

/* 세션1 - 모니터링 */
watch -n 1 cubrid plandump demodb

/* 세션2 - 실행 후 세션3 진행 */
csql -u dba demodb -c 'select c2 from t1 where c1 = 1 and sleep (10) != 1'

/* 세션3 */
cubrid plandump -d demodb
cubrid plandump -d demodb
cubrid plandump -d demodb

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해결했습니다. 곧 기타 수정 후 푸시할 예정이니 푸시 후 한번 더 알림 드릴테니 확인 부탁드려요.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해결했습니다.

sohee-dgist and others added 4 commits March 24, 2025 12:39
- new line 제거 및 복구
- plandump -d 시 일어날 수 있는 상황에 대한 오류 해결 완료
SOHEE_JUNG added 3 commits March 24, 2025 14:09
- xasl cache del mark시 무조건 true인 상황에 확실히 반환하도록 수정
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants