Helio Intro


Intro

Helio - io_uring과 epoll 이벤트 루프를 사용하는 C++로 작성된 백엔드 개발 프레임워크입니다.
Helio - backend development framework in C++ using io_uring and epoll event-loop.
• 프로젝트 원본: github.com/romange/helio by Roman Gershman(로만 거쉬먼)
• helio는 리눅스 커널 5.8 이상에서 작동합니다. -> RHEL 9.0(Rocky Linux 9.0, CentOS-9)이상


Async는 Linux 시스템에서 C++17로 효율적이고 신속한 개발을 가능하게 하는 C++ 기본 요소 세트입니다.
주로 백엔드 개발, 데이터 처리 등에 중점을 두고 있습니다.
1. abseil(앱세일)-cpp에 대한 의존성
2. Boost(부스트) 1.71에 대한 의존성
3. cmake 위에 ninja-build를 사용합니다.
4. 빌드된 아티팩트는 Docker 친화적입니다.
5. HTTP 서버 구현.
6. Fibers 라이브러리 및 파이버 친화적인(fiber-friendly) 동기화 기본 요소.

Async is a set of C++ primitives that allows you efficient and rapid development in c++17 on Linux systems.
The focus is mostly on backend development, data processing, etc.
1. Dependency on abseil-cpp
2. Dependency on Boost 1.71
3. Uses ninja-build on top of cmake
4. Built artifacts are docker-friendly.
5. HTTP server implementation.
6. Fibers library and fiber-friendly synchronization primitives.


⬛️ 감사의 말 - Acknowledgments

Helio는 2023년 5월까지 Boost.Fiber를 활용했습니다.
이 기간 이후에는 Fiber 기능이 Helio 코드에 직접 통합되었습니다.
이 전환에는 Helio의 코딩 규칙 및 아키텍처에 맞게 원래 Boost.Fiber 코드의 일부를 조정하고 재작업하는 작업이 포함되었습니다.

Helio Fiber의 디자인과 구현은 Boost.Fiber에서 중요한 영감을 얻습니다.
Boost.Fiber 코드의 특정 세그먼트는 Helio에 원활하게 통합되도록 선택적으로 채택되고 수정되었습니다.
우리는 기본 작업에 대해 @olk와 Boost.Fiber의 모든 기여자에게 깊은 감사와 감사를 표합니다.

원본 코드를 복제하고 수정하기로 한 결정은 더 큰 유연성이 필요했기 때문입니다.
특히, 파이버 내부 인터페이스를 완전히 제어할 수 있을 때 Helio의 폴링(polling) 메커니즘을 발전시키는 것이 더 쉬웠습니다.

Helio has utilized Boost.Fiber until May 2023.
After this period, the fibers functionality was integrated directly into Helio code.
This transition involved adapting and reworking portions of the original Boost.Fiber code to align with Helio's coding conventions and architecture.

The design and implementation of Helio fibers draw significant inspiration from Boost.Fiber.
Certain segments of the Boost.Fiber code were selectively adopted and modified for seamless incorporation into Helio.
We extend our deepest gratitude and recognition to @olk and all the contributors of Boost.Fiber for their foundational work.

The decision to replicate and modify the original code was driven by the necessity for greater flexibility.
Specifically, it was easier to evolve Helio's polling mechanism when we had full control over the fibers internal interfaces.


⬛️ Boost.Fiber와 Helio fb2 파이버의 차이점. - Differrences between Boost.Fiber and helio fb2 fibers.

Helio fb2 라이브러리는 Boost.Fiber와 유사한 비침해적(non-intrusive), 공유 없음 디자인을 채택합니다.
그러나 helio의 fb2 라이브러리는 좀 더 독선적이며(opinionated) 비동기 멀티스레드 실행을 위한 완전한 네트워킹 지원도 제공합니다.
helio 파이버를 사용하면 사용자 정의 배정(dispatch) 정책 "util::fb2::DispatchPolicy"를 배정(dispatching) 파이버에 직접 주입할 수 있는 반면 Boost.Fiber는 I/O 폴링을 처리하기 위해 별도의 파이버를 사용해야 합니다.
또한 Helio Fiber는 잠금 없는 대기열(lockless queue)을 사용하는 반면 Boost.Fiber 스레드 간 알림 메커니즘(원격 준비 대기열이라고도 함)에는 잠금이 필요합니다.

Helio fb2 library adopts similar non-intrusive, shared nothing design similarly to Boost.Fiber. However, helio's fb2 library is more opinionated and also provides full networking support for asynchronous multi-threaded execution. helio fibers allows injecting a custom dispatch policy "util::fb2::DispatchPolicy" directly into a dispatching fiber, while Boost.Fiber requires using a separate fiber to handle the I/O polling. In addition, Boost.Fiber inter-thread notification mechanism (aka remote ready queue) required locking while helio fibers use a lockless queue.


⬛️ 설정, 빌드 - Setting Up & Building

$ git clone https://github.com/romange/helio.git -> helio
$ sudo ./install-dependencies.sh
$ ./blaze.sh -release
$ cd build-opt && ninja -j4 echo_server

third_party 폴더는 빌드 디렉터리 아래에서 체크아웃됩니다.
third_party folder is checked out under build directories.

그런 다음 2개의 탭에서 다음을 실행합니다.
Then, from 2 tabs run:

$ ./echo_server --logtostderr     -> 서버 실행
$ ./echo_server --connect=localhost --n 100000 --c=4     -> 클라이언트 실행


⬛️ HTTP

HTTP 핸들러는 Boost.Beast 라이브러리를 사용하여 구현됩니다.
io_uring 기반 'ProactorPool'과 통합되어 있습니다. 예를 들어 http_main.cc를 참조하세요.
HTTP는 또한 백엔드 모니터링(Varz 상태 페이지) 및 확장 가능한 디버깅 인터페이스에 대한 지원을 제공합니다.
모니터링 C++ 백엔드는 브라우저의 상태 페이지 내부에 형식이 지정된 JSON 개체를 반환합니다.
어떻게 보이는지 확인하려면 'echo_server'가 실행되는 동안 localhost:8080으로 이동하세요.

HTTP handler is implemented using Boost.Beast library.
It's integrated with the io_uring-based ProactorPool. Please see http_main.cc, for example.
HTTP also provides support for backend monitoring (Varz status page) and for an extensible debugging interface.
With monitoring C++ backend returns JSON object that is formatted inside status page in the browser.
To check how it looks, please go to localhost:8080 while echo_server is running.


⬛️ 셀프 프로파일링 - Self-profiling

모든 http 기반 백엔드에는 'gperf-tools'를 사용하는 통합 CPU 프로파일링 기능이 있으며, pprof 프로파일링은 magic-url 명령을 사용하여 'prod'에서 트리거될 수 있습니다.
활성화된 프로파일링은 일반적으로 실행 중인 백엔드의 CPU 성능에 최소한의 영향을 미칩니다.

Every http-powered backend has integrated CPU profiling capabilities using gperf-tools and pprof Profiling can be triggered in prod using magic-url commands.
Enabled profiling usually has a very minimal impact on CPU performance of the running backend.


⬛️ 로깅(기록) - Logging

로깅은 Google의 glog 라이브러리를 기반으로 합니다.
라이브러리는 매우 안정적이고 성능이 뛰어나며 견고합니다.
탄력적인 백엔드 개발을 가능하게 하는 많은 기능이 있습니다.
불행히도 Google 버전에는 몇 가지 버그가 있어서 수정했습니다(검토를 기다리는 중...).
그래서 자체 포크를 사용합니다.
Glog 라이브러리를 사용하면 백엔드를 다시 시작하지 않고도 런타임 시 백엔드의 로깅 수준을 제어할 수 있습니다.

Logging is based on Google's glog library.
The library is very reliable, performant, and solid.
It has many features that allow resilient backend development.
Unfortunately, Google's version has some bugs, which I fixed (waiting for review...), so I use my own fork.
Glog library gives me the ability to control the logging levels of a backend at run-time without restarting it.


⬛️ 테스트 - Tests

ASYNC uses a googletest+gmock unit-test environment.
ASYNC는 googletest+gmock 단위 테스트 환경을 사용합니다.


⬛️ 규칙 - Conventions

Third_party 패키지 CMakeLists.txt에 TRDP:: 접두사가 있습니다.
absl 라이브러리에는 접두사가 있습니다 absl::....
Third_party packages have TRDP:: prefix in CMakeLists.txt.
absl libraries have prefix absl::....



소스 파일

◼️ examples: cc: 5개 파일

  • echo_server.cc -> 받은 메시지를 그대로 리턴한다. Server/Client 두 가지 기능을 한다.
  • raw_echo_server.cc -> 받은 메시지를 그대로 리턴한다.
  • https_client_cli.cc
  • proactor_stress.cc
  • s3_demo.cc

◼️ examples/pingserver: 3개 파일

  • ping_iouring_server.cc -> PING을 받으며 PONG를 리턴한다. RESP(레디스 프로토콜)을 사용한다.
  • resp_parser.h -> RESP(REdis Serialization Protocol) 함수
  • resp_parser.cc

◼️ examples/redis_dict: 8개 파일

  • alloc.h
  • alloc.c
  • dict.h
  • dict.c
  • fmacros.h
  • sdsalloc.h
  • sds.h
  • sds.c

◼️ base: 58개 파일

  • abseil_test.cc
  • aquahash.h
  • bits.h
  • cuckoo_map.h
  • cuckoo_map-internal.h
  • cuckoo_map.cc
  • cuckoo_map_test.cc
  • cxx_test.cc
  • endian.h
  • expected.hpp
  • flags.h
  • flit.h
  • flit_test.cc
  • function2.hpp
  • gtest.h
  • gtest_main.cc
  • hash.h
  • hash.cc
  • hash_test.cc
  • histogram.h
  • histogram.cc
  • histogram_test.cc
  • init.h
  • init.cc
  • integral_types.h
  • io_buf.h
  • io_buf.cc
  • libdivide.h
  • logging.h
  • logging.cc
  • malloc_test.cc
  • mpmc_bounded_queue.h
  • mpmc_bounded_queue_test.cc
  • mpsc_intrusive_queue.h
  • mpsc_intrusive_queue_test.cc
  • pod_array.h
  • port.h
  • proc_util.h
  • proc_util.cc
  • ProducerConsumerQueue.h
  • pthread_utils.h
  • pthread_utils.cc
  • random.h
  • ring_buffer.h
  • ring_buffer_test.cc
  • RWSpinLock.h
  • segment_pool.h
  • segment_pool.cc
  • spinlock.h
  • sse2neon.h
  • stl_util.h
  • string_view_sso.h
  • string_view_sso_test.cc
  • type_traits.h
  • varz_node.h
  • varz_node.cc
  • varz_value.h
  • zipf_gen.h

◼️ base/pmr: 8개 파일

  • arena.h
  • arena.cc
  • arena_test.cc
  • memory_resource.h
  • pod_array.h
  • pod_array_test.cc

◼️ io: 13개 파일

  • file.h
  • file.cc
  • file_test.cc
  • file_util.h
  • file_util.cc
  • io_buf.h
  • io.h
  • io.cc
  • io_test.cc
  • line_reader.h
  • line_reader.cc
  • proc_reader.h
  • proc_reader.cc

◼️ strings: 3개 파일

  • human_readable.h
  • human_readable.cc
  • strings_test.cc

◼️ util: 10개 파일

  • accept_server.h
  • accept_server_test.cc
  • asio_stream_adapter.h
  • connection.h
  • fiber_socket_base.h
  • listener_interface.h
  • proactor_pool.h
  • sliding_counter.h
  • varz.h

◼️ util/aws: 16개 파일

  • aws.h
  • aws.cc
  • credentials_provider_chain.h
  • credentials_provider_chain.cc
  • http_client.cc
  • http_client_factory.h
  • http_client_factory.cc
  • http_client.h
  • logger.h
  • logger.cc
  • s3_endpoint_provider.h
  • s3_endpoint_provider.cc
  • s3_read_file.h
  • s3_read_file.cc
  • s3_write_file.h
  • s3_write_file.cc

◼️ util/fibers: 39개 파일

  • accept_server.cc
  • dns_resolve.h
  • dns_resolve.cc
  • epoll_proactor.h
  • epoll_proactor.cc
  • epoll_socket.h
  • epoll_socket.cc
  • fiber_file.h
  • fiber_file.cc
  • fiberqueue_threadpool.h
  • fiberqueue_threadpool.cc
  • fibers.h
  • fibers.cc
  • fiber_socket_base.cc
  • fiber_socket_test.cc
  • fibers_test.cc
  • future.h
  • listener_interface.cc
  • pool.h
  • pool.cc
  • prebuilt_asio.cc
  • proactor_base.h
  • proactor_base.cc
  • proactor_pool.cc
  • simple_channel.h
  • sliding_counter.cc
  • stacktrace.h
  • stacktrace.cc
  • submit_entry.h
  • synchronization.h
  • synchronization.cc
  • uring_file.h
  • uring_file.cc
  • uring_file_test.cc
  • uring_proactor.h
  • uring_proactor.cc
  • uring_socket.h
  • uring_socket.cc
  • varz.cc

◼️ util/fibers/detail: 10개 파일

  • fiber_interface.h
  • fiber_interface.cc
  • fiber_interface_impl.h
  • result_mover.h
  • scheduler.h
  • scheduler.cc
  • utils.h
  • utils.cc
  • wait_queue.h
  • wait_queue.cc

◼️ util/html: 2개 파일

  • sorted_table.cc
  • sorted_table.h

◼️ util/http: 25개 파일

  • beast_rj_utils.h
  • encoding.h
  • encoding.cc
  • http_client.h
  • http_client.cc
  • http_common.h
  • http_common.cc
  • http_handler.h
  • http_handler.cc
  • http_main.cc
  • https_client.h
  • https_client.cc
  • https_client_pool.h
  • https_client_pool.cc
  • http_server_utils.h
  • http_status_code.h
  • http_status_code.cc
  • http_test.cc
  • http_testing.h
  • http_testing.cc
  • prebuilt_beast.cc
  • profilez_handler.cc
  • status_page.cc
  • status_page.css
  • status_page.js

◼️ util/metrics: 4개 파일

  • family.h
  • family.cc
  • metrics.h
  • metrics.cc

◼️ util/tls: 5개 파일

  • tls_engine.h
  • tls_engine.cc
  • tls_engine_test.cc
  • tls_socket.h
  • tls_socket.cc

보충 설명

📦 absl

absl은 Google의 Abseil 라이브러리(abseil.io)를 의미합니다.
Abseil(앱세일)은 C++용으로 설계된 오픈 소스 라이브러리로, Google 내부에서 사용되는 다양한 유틸리티, 데이터 구조, 알고리즘, 그리고 다른 기본적인 프로그래밍 구성 요소들을 제공합니다.
Abseil은 특히 Google의 많은 프로젝트에서 사용되며, 다음과 같은 기능들을 포함합니다:

  • Container Libraries: 다양한 데이터 구조와 컨테이너들을 제공합니다. 예를 들어, absl::flat_hash_map와 absl::flat_hash_set은 효율적인 해시 테이블 구현입니다.
  • Strings: 문자열 조작을 위한 다양한 함수들과 클래스들을 제공합니다.
  • Time: 시간과 날짜를 다루기 위한 다양한 유틸리티를 제공합니다.
  • Memory Management: 스마트 포인터와 같은 메모리 관리 유틸리티를 제공합니다.
  • Concurrency: 멀티스레딩과 동시성 프로그래밍을 위한 다양한 툴들을 제공합니다.
  • Utilities: 다양한 유틸리티 함수와 클래스들이 포함되어 있습니다.


Email 답글이 올라오면 이메일로 알려드리겠습니다.