{"id":21090273,"url":"https://github.com/jun-labs/async-parallel-scan","last_synced_at":"2026-04-28T09:05:36.249Z","repository":{"id":229941451,"uuid":"769576811","full_name":"jun-labs/async-parallel-scan","owner":"jun-labs","description":"🐳 테이블 풀스캔과 비동기/멀티 쓰레드를 활용한 데이터 처리.","archived":false,"fork":false,"pushed_at":"2024-03-26T16:30:47.000Z","size":330,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-01T03:41:22.861Z","etag":null,"topics":["async","async-parallel","full-scans","parallel","table"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jun-labs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-09T13:23:36.000Z","updated_at":"2024-04-05T16:59:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"3f57dc08-08f9-46de-85cd-d2e0e2077ddf","html_url":"https://github.com/jun-labs/async-parallel-scan","commit_stats":null,"previous_names":["jun-labs/async-parallel-scan"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jun-labs/async-parallel-scan","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jun-labs%2Fasync-parallel-scan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jun-labs%2Fasync-parallel-scan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jun-labs%2Fasync-parallel-scan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jun-labs%2Fasync-parallel-scan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jun-labs","download_url":"https://codeload.github.com/jun-labs/async-parallel-scan/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jun-labs%2Fasync-parallel-scan/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32373548,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-27T20:07:02.737Z","status":"online","status_checked_at":"2026-04-28T02:00:07.250Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","async-parallel","full-scans","parallel","table"],"created_at":"2024-11-19T21:35:07.432Z","updated_at":"2026-04-28T09:05:36.226Z","avatar_url":"https://github.com/jun-labs.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Full Table Scan with Async \u0026 Parallel\n\n비동기를 활용한 테이블 풀 스캔 성능 테스트.\n\n\u003e 테이블 풀 스캔은 테이블의 모든 row를 조회하기 때문에, 데이터가 많을 경우 일반적으로 권장되지 않습니다. 하지만 데이터가 많더라도 `분할`과 `비동기를 활용한 병렬 처리`를 하면 특정 상황에서는 꽤 좋은\n\u003e 성능을 낼 수 있습니다.\n\n\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\n\n## 1. 요구 사항\n\n이벤트 플로우는 다음과 같습니다. 알림 송신은 별도의 시스템이 필요하기 때문에 고려하지 않습니다.\n\n1. 알림 메시지를 전송한다.\n2. 전체 사용자는 2,000 만 명이며, 알림 수신에 동의한 사용자에게만 알림을 전송한다.\n3. 단일 애플리케이션/데이터베이스를 사용한다.\n\n\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\n\n### Step1. 비동기를 활용해 알림을 전송한다.\n\n데이터가 많을 경우, 테이블 풀 스캔을 사용하면 모든 row를 읽기 때문에 시간이 오래 걸릴 수 있으므로, `비동기`를 활용해 이를 개선한다.\n\n1. 비동기로 데이터를 처리한다.\n2. 모니터링을 통해 자원 사용률을 체크한다.\n\n\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\n\n### Step2. 태스크 유실을 대비한다.\n\n메세지 큐(Message Queue)를 사용하는 경우, 의도치 않게 태스크가 유실되는 경우 가 발생한다. 메시지가 유실될 경우, 이를 대비할 수 있도록 한다.\n\n1. 메시지 유실을 대비한다.\n2. 메시지 큐는 어떤 것을 사용해도 상관없다.\n3. 외부 메시징 시스템을 도입했을 시, 성능 변화를 측정한다.\n\n\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\n\n## 2. 아이디어\n\n아이디어는 `분할`과 `비동기를 활용한 병렬 처리` 입니다.\n\n- 분할\n- 비동기를 활용한 병렬 처리\n\n\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\n\n먼저 하나의 큰 태스크를 적절한 단위(chunk)로 분할합니다.\n\n![image](image/task-seperation.png)\n\n\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\n\n각 태스크는 자신이 처리할 작업의 시작/끝점을 알고 있습니다. 이를 통해 `데이터 중복 처리를 방지`하며, `인덱스(Index)를 활용`할 수 있게 됩니다.\n\n![image](image/task-range.png)\n\n\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\n\n이후 각 태스크를 `비동기를 통한 병렬로 처리`합니다.\n\n![image](image/async-parallel.png)\n\n\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\n\n## 3. 결과\n\n2,000만 건 처리 시 1분 ~ 1분 45초. \n\n```shell\n# 약, 1분 31초(91.16)\n127.0.0.1:6379\u003e get time::string::startTime\n\"1710619193857\"\n127.0.0.1:6379\u003e get time::string::endTime\n\"1710619285018\"\n```\n\n```shell\n# 약 1분 26초(86.45)\n127.0.0.1:6379\u003e get time::string::startTime\n\"1710619455453\"\n127.0.0.1:6379\u003e get time::string::endTime\n\"1710619541899\"\n```\n\n```shell\n# 약 1분 38초(98.73)\n127.0.0.1:6379\u003e get time::string::startTime\n\"1710619665364\"\n127.0.0.1:6379\u003e get time::string::endTime\n\"1710619764089\"\n```\n\n\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\n\n## 4. 한계\n\n태스크 실행 중 새로운 데이터가 추가 됐을 때, 이를 처리할 수 있는 방안이 없습니다. 예를 들어, 2,000만 사용자에게 알림을 발송하는 도중 새로운 사용자가 가입을 한다면 이를 대처할 방법이 없습니다. 따라서\n모든 로직이 끝난 후, 새로 추가된 사용자들은 별도의 로직으로 처리해줘야 합니다.\n\n```kotlin\ninterface UserRepository : JpaRepository\u003cUser, Long\u003e {\n    @Query(\"SELECT u FROM user u WHERE u.id \u003e maxUserId\")\n    fun findByIdOver(maxUserId: Long): List\u003cUser\u003e\n}\n```\n\n\u003e 또한 이 외에도 쓰레드 풀 개수 설정, 커넥션 관리, 모니터링 등의 추가 이슈가 있습니다. 상세 내용은 블로그를 참조해주세요.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjun-labs%2Fasync-parallel-scan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjun-labs%2Fasync-parallel-scan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjun-labs%2Fasync-parallel-scan/lists"}