Feature Installation and Usage
The ApplySrv thread optimization feature is developed for OceanBase 4.2.5.6 and is provided in the form of source code plus a patch file. To install and use this feature, you need to obtain the OceanBase 4.2.5.6 source code, apply the patch file, recompile and deploy the OBServer binary, and finally enable and tune it through the tenant-level parameter.
- Prepare the system environment.
- Create an admin user and configure SSH password-free login.
groupadd -g 500 admin useradd -u 500 -g admin admin su - admin ssh-keygen -t rsa -m PEM cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys # If the configuration is successful, you will automatically be logged back in as the admin user. ssh -v localhost
- Configure system kernel parameters. Edit the /etc/sysctl.conf file, add the following content, and then run the sysctl -p command for the modification to take effect.
net.core.somaxconn=2048 net.core.netdev_max_backlog=500 net.core.rmem_default=65536 net.core.wmem_default=65536 net.core.rmem_max=8388608 net.core.wmem_max=8388608 net.ipv4.tcp_rmem=4096 87380 16777216 net.ipv4.tcp_wmem=4096 65536 16777216 net.ipv4.tcp_max_syn_backlog=16384 net.ipv4.tcp_fin_timeout=15 net.ipv4.tcp_tw_reuse=1 net.ipv4.ip_local_port_range=3500 65535 vm.swappiness=0 vm.min_free_kbytes=2097152 vm.max_map_count=655360 fs.aio-max-nr=1048576 fs.file-max=6573688 kernel.numa_balancing=0
- Disable transparent huge pages, swap, and SELinux, start the sshd service, and then stop the firewall.
echo never > /sys/kernel/mm/transparent_hugepage/enabled echo never > /sys/kernel/mm/transparent_hugepage/defrag swapoff -a sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config systemctl start sshd systemctl enable sshd systemctl start crond systemctl enable crond systemctl stop firewalld systemctl disable firewalld
- Install build and runtime dependencies.
yum install -y net-tools nc iproute libatomic curl bind-utils binutils \ tar mtr java mysql numactl rsync python python-devel \ python3 python3-devel gcc gcc-c++ cmake git wget rpm* cpio \ make glibc-devel glibc-headers libtool libaio libstdc++* - Configure user resource limits. Create a /etc/security/limits.d/99-oceanbase_limits.conf file and write the following content into the file:
root soft nofile 655350 root hard nofile 655350 admin soft nofile 655350 admin hard nofile 655350 admin soft stack 10240 admin hard stack 10240 admin soft nproc 655360 admin hard nproc 655360 admin soft core unlimited admin hard core unlimited
- Create an admin user and configure SSH password-free login.
- Prepare the build environment, obtain the OceanBase source code, and switch to the version corresponding to 4.2.5.6.
su - admin cd ~ git clone https://github.com/oceanbase/oceanbase.git cd oceanbase/ git checkout v4.2.5_CE_BP6
- Initialize the build dependencies.build.sh init invokes deps/init/dep_create.sh to automatically download the toolchain (such as CMake, Clang/LLVM, and GCC) and third-party dependencies to the deps/3rd directory through the official OceanBase Yum repository.
cd ~/oceanbase bash build.sh init
If the network is unavailable, compile the dependencies by referring to the deps/3rd directory. After successful initialization, deps/3rd/usr/local/oceanbase/devtools/bin/cmake should exist.
- Obtain the patch file 0001-Add-log-apply-thread-factor.patch for the optimization feature and upload it to the home directory ~. For details, see Table 2.
- Apply the optimization feature patch. If no command output is displayed, the patch is successfully applied.
cd ~/oceanbase git apply --whitespace=nowarn < ~/0001-Add-log-apply-thread-factor.patch
- Compile and package the OBServer (RPM mode).
RPM mode is based on the RelWithDebInfo build type and enables related optimization options. Here you only need to obtain the relevant OBServer binary. You can use --init --make to complete dependency initialization and compilation in one step, or execute them separately.
- Method 1 (in one step, recommended):
cd ~/oceanbase bash build.sh rpm --init --make
- Method 2 (in steps):
cd ~/oceanbase bash build.sh rpm --init cd build_rpm make -j$(nproc)
The compilation results are located in the build_rpm directory, including the OBServer binary (build_rpm/src/observer/observer).
The recommended value for the -j parallelism option is min(Number of CPU cores × 2, (Memory in GB)/2), which balances build speed and stability.
- Method 1 (in one step, recommended):
- (Optional) Modify the Python version syntax.
During compilation, errors may occur because the system only has Python 3 while some files are implemented using Python 2 syntax.
Modify the ~/oceanbase/cmake/scripts/bitcode_to_elfobj file before compilation.// Modify line 72. close_fds=True, universal_newlines=True) // Modify line 75. if data == '':
- Download the OBProxy 4.3.6 RPM package from the official website, and extract it to obtain the binary.
When using --with-local-obproxy for subsequent deployment, you need to prepare the local obproxy executable file in advance. Obtain the OBProxy 4.3.6 RPM package that matches the runtime environment from the OceanBase official software download center, and then extract the binary.
- Visit the OceanBase software download center, search for and download the OBProxy 4.3.6 RPM package for the corresponding architecture (for Kunpeng environments, select ARM and el7).Upload the downloaded RPM package to the server. For example, save it as follows:
mkdir -p ~/packages # Upload the RPM package downloaded from the official website to this directory. Example package name: # obproxy-4.3.6.x-xxxx.el7.aarch64.rpm # In the command, replace it with the actual downloaded package name. Use the actual package name in the extraction path as well. ls ~/packages/obproxy-4.3.6*.rpm
- Extract the RPM package and locate the obproxy binary.
rpm2cpio ~/packages/obproxy-4.3.6*.rpm | cpio -idmv find . -type f -name obproxy
After extraction, the obproxy binary is usually located at ./home/admin/obproxy/bin/obproxy or a similar path.
- Copy the binary to the deployment directory for later use with --with-local-obproxy.
mkdir -p ~/oceanbase/tools/deploy/bin cp -f ~/packages/home/admin/obproxy/bin/obproxy \ ~/oceanbase/tools/deploy/bin/obproxy chmod +x ~/oceanbase/tools/deploy/bin/obproxy ~/oceanbase/tools/deploy/bin/obproxy --version
If the path obtained by find differs from the example above, copy the binary to the actual path. After confirming that the --version output contains 4.3.6, continue with the subsequent deployment steps.
- Visit the OceanBase software download center, search for and download the OBProxy 4.3.6 RPM package for the corresponding architecture (for Kunpeng environments, select ARM and el7).
- Prepare the deployment directory, the OBServer binary, and the YAML configuration.
The tools/deploy/obd.sh script included in the source code is the deployment entry point. prepare performs the following operations:
- Runs tools/deploy/copy.sh to copy observer from the default build directory to tools/deploy/bin/observer.
- Reads tools/deploy/obd/apply-srv.yaml.template.
- Generates the tools/deploy/apply-srv.yaml file from the template only when it does not exist. An existing file will not be overwritten.
The created configuration file must be located in tools/deploy/apply-srv.yaml.
cd ~/oceanbase vi tools/deploy/apply-srv.yaml
Its content is as follows:oceanbase-ce: servers: - name: server1 ip: 127.0.0.1 server1: mysql_port: 2882 rpc_port: 2881 home_path: /ob/data/1/obm zone: zone1 include: obd/observer.include.yaml global: production_mode: false devname: lo memory_limit: '250G' system_memory: '50G' datafile_size: '2000G' cpu_count: '32' log_disk_size: '500G' cluster_id: 1 root_password: "" obproxy: servers: - 127.0.0.1 global: listen_port: 2828 prometheus_listen_port: 2829 home_path: /ob/data/1/obm/obproxy include: obd/obproxy.include.yaml depends: - oceanbase-ceThe generation occurs in the prepare phase, not the deploy phase. Running deploy directly does not generate the YAML from the template. You must run prepare first or provide a pre-generated YAML yourself. If apply-srv.yaml already exists, prepare does not overwrite it. To regenerate it from the template, back up and delete the existing apply-srv.yaml first, and then run prepare.
Run the following commands to generate the configuration file:cd ~/oceanbase ./tools/deploy/obd.sh prepare ls -l tools/deploy/bin/observer tools/deploy/bin/obproxy tools/deploy/apply-srv.yaml tools/deploy/bin/observer -V
The value after --observer must be the full path to the OBServer executable file, not a directory path. This parameter takes effect in the deploy phase and is used to create the OBServer image. It cannot be passed in the prepare phase. For example:cd ~/oceanbase ./tools/deploy/obd.sh deploy \ -n ob2xtest \ -c ./tools/deploy/apply-srv.yaml \ --observer /absolute/path/to/observer --with-local-obproxy
If --observer is not specified, deploy uses tools/deploy/bin/observer. When --with-local-obproxy is used, the deployment automatically looks for obproxy in tools/deploy/bin/.
- Confirm and adjust apply-srv.yaml as needed.
The default configuration generated by prepare corresponds to a single-zone, single-node deployment. During deploy execution, if --with-local-obproxy is used, OBD obtains the local binary extracted in step 8 from tools/deploy/bin/obproxy. Otherwise, it attempts to obtain OBProxy automatically.
Table 1 Key parameters Category
Parameter
Default Value
Description
Topology
Node/Zone
127.0.0.1/zone1
Single zone, single node
Port
mysql_port
2882
OBServer SQL port
Port
rpc_port
2881
OBServer RPC port
Proxy
listen_port
2828
OBProxy listening port
Proxy
prometheus_listen_port
2829
OBProxy monitoring port
NIC
devname
lo
Modified based on the actual NIC of the machine
Resource
cpu_count
32
OBServer available CPUs
Resource
memory_limit
250G
OBServer memory limit
Resource
system_memory
50G
System reserved memory
Resource
datafile_size
2000G
Data file quota
Resource
log_disk_size
500G
Log drive quota
Path
OBServer home_path
/ob/data/1/obm
OBServer working directory
Path
OBProxy home_path
/ob/data/1/obm/obproxy
OBProxy working directory
When apply-srv.yaml is used in another environment, at least modify the node IP, devname, home_path, and resource specifications.
- The resource specifications in the table above are relatively large. For small-specification environments, you can reduce them according to the machine capacity, and ensure that the tenant Unit specification is smaller than the node upper limit.
- The include path is relative to the tools/deploy/ directory. The script automatically switches to this directory to perform subsequent OBD operations.
- Before deployment, ensure that the home_path drive has sufficient space and is writable by the admin user.
- Password configuration needs to distinguish between the user connection password and the OBProxy internal access credentials.
Table 2 Password configuration description Configuration or Account
Configuration in This Document
Function
root@sys
root_password: ""
Used when users connect to the sys tenant through the OBServer or OBProxy with an empty password.
proxyro@sys
Not directly written to the YAML file
Internal account used by OBProxy to query OBServer metadata, initialized by OBD after the dependent OBServer starts.
observer_sys_password
Not manually filled in
Runtime credential used when OBProxy accesses the OBServer internal account, generated and passed by the deployment process.
obproxy_sys_password
Not manually filled in
OBProxy internal system credential, which is not equivalent to the OBServer's root_password.
obproxy.depends must include oceanbase-ce. OBD uses this dependency to ensure that the OBServer starts first and completes the synchronization of the OBProxy internal account, authorization, and runtime password. Therefore, even if root_password is empty, it does not mean that the OBProxy internal credentials are empty. Do not directly copy the root password to observer_sys_password or obproxy_sys_password, and do not manually fill in the runtime password hash result. If the OBServer and OBProxy are deployed separately, you need to create proxyro@sys, grant metadata query permissions, and ensure that the OBProxy runtime credentials match the account password. This is not part of the OBD joint deployment process described in this section.
- Deploy and start the cluster.
cd ~/oceanbase ./tools/deploy/obd.sh deploy \ -n ob2xtest \ -c ./tools/deploy/apply-srv.yaml --with-local-obproxy
Command flow description:
- deploy creates a local OBServer image based on tools/deploy/bin/observer.
- It creates a local OBProxy image based on tools/deploy/bin/obproxy.
- It then executes obd cluster deploy and obd cluster start to complete the cluster startup and initialize the OBProxy internal account.
- The configuration file name remains apply-srv.yaml, and the deployment name is explicitly set through -n ob2xtest.
After deployment, the ports are as follows:
- OBServer SQL: 2882
- OBServer RPC: 2881
- OBProxy: 2828
Connection verification:obclient -h127.0.0.1 -P2828 -uroot@sys -Doceanbase -A -e 'select ob_version()'
- Initialize the service tenant and parameters.
After the cluster starts, create a service tenant (single zone, single replica). The zone name must be consistent with zone: zone1 in apply-srv.yaml.
- Connect to the sys tenant. Subsequent operations will be performed in this command line.
obclient -h127.0.0.1 -P2828 -uroot@sys -Doceanbase -A
- Create a resource unit and a resource pool.
CREATE RESOURCE UNIT mysql_tenant_unit_1 MAX_CPU 10, MEMORY_SIZE='20G', LOG_DISK_SIZE='6G', MAX_IOPS 10000000, MIN_CPU 10, MIN_IOPS 10000000; CREATE RESOURCE POOL mysql_tenant_pool_1 UNIT='mysql_tenant_unit_1', UNIT_NUM = 1, ZONE_LIST=('zone1'); - Create a MySQL tenant.
CREATE TENANT IF NOT EXISTS mysql_tenant RESOURCE_POOL_LIST=('mysql_tenant_pool_1'), PRIMARY_ZONE='RANDOM', CHARSET=utf8mb4, COLLATE=utf8mb4_general_ci, LOCALITY='F@zone1' SET VARIABLES ob_compatibility_mode='mysql', ob_tcp_invited_nodes='%', secure_file_priv='/'; - Set the configuration parameters.
ALTER TENANT mysql_tenant primary_zone = 'zone1'; ALTER SYSTEM SET enable_global_background_resource_isolation = true; ALTER SYSTEM SET net_thread_count = 12; ALTER SYSTEM SET enable_sql_audit = true;
- Exit the system tenant and set the parameters for the service tenant.
obclient -h127.0.0.1 -P2828 -uroot@mysql_tenant -Doceanbase -A
create database obtest; GRANT ALL PRIVILEGES ON *.* TO 'obtest'@'%' IDENTIFIED BY '123456'; ALTER SYSTEM SET major_compact_trigger = 0;
- Restart the cluster for the settings to take effect.
cd ~/oceanbase ./tools/deploy/obd.sh restart -n ob2xtest
- Connect to the sys tenant. Subsequent operations will be performed in this command line.
- Enable and verify the feature.
- Check the current parameter value (the default value is 0, which is the compatibility mode).
SHOW PARAMETERS LIKE 'log_apply_thread_factor' tenant = 'mysql_tenant';
- Set the ApplySrv thread factor for the target tenant (set it to 1.0 for scenario optimization).
ALTER SYSTEM SET log_apply_thread_factor = 1 tenant = 'mysql_tenant';
- Confirm that the parameter value has been updated.
SHOW PARAMETERS LIKE 'log_apply_thread_factor' tenant = 'mysql_tenant';
- Observe the actual number of ApplySrv threads. After parameter modification, the OBServer does not need to be restarted, and the number of ApplySrv threads is immediately re-adjusted according to the new factor and the upper limit of 128.The Linux thread name is generated from the thread group name in the source code and usually contains a tenant prefix, for example, T1002_ApplySrv0, with the name case being ApplySrv. Use ps -T to view the OBServer threads.
observer_pid=$(pgrep -xo observer) ps -T -p "${observer_pid}" -o tid=,comm= | grep 'ApplySrv'Count the current ApplySrv threads in the OBServer.observer_pid=$(pgrep -xo observer) ps -T -p "${observer_pid}" -o comm= | grep -c 'ApplySrv'To count the threads of a specific tenant, replace <tenant_id> with the actual tenant ID.observer_pid=$(pgrep -xo observer) ps -T -p "${observer_pid}" -o tid=,comm= \ | grep -c '^T<tenant_id>_ApplySrv'
- Check the current parameter value (the default value is 0, which is the compatibility mode).
- Perform sysbench insert tests.
This section uses oltp_insert.lua to run the insert scenario test. The test client accesses mysql_tenant through port 2828 of OBProxy. The test account password is unrelated to the empty password configuration of root@sys.
Table 3 Test specifications Item
Parameter
Description
Test scenario
oltp_insert.lua
sysbench insert scenario
LUA path
/usr/local/share/sysbench/oltp_insert.lua
Path to the standard sysbench test script
Test address
127.0.0.1:2828
Cluster access through OBProxy
Test user
obtest@mysql_tenant
Tenant: mysql_tenant; test account: obtest
Test password
123456
Password of the obtest test account
Test database
obtest
Value of sysbench --mysql-db
Concurrent threads
800
Number of sysbench client threads, not the number of ApplySrv threads
Test duration
300 seconds
--time=300
Rows per table
500000
--table_size=500000
Table count variable
1
--tables=1
Reporting interval
1 second
--report-interval=1
Request limit
Unlimited
--max-requests=0, controlled by the 300-second interval
Random type
uniform
--rand-type=uniform
Prepared statement mode
Disabled
--db-ps-mode=disable
Ignored errors
1062, 6002, 6001, 4012, 1213, 1020, 1205, 4038, 6004
--mysql-ignore-errors parameter
- Create the test account and database, and bind CPU cores to the processes.The test account and database have already been created earlier, so there is no need to create them again here. Bind CPU cores 0–31 to the OBServer process, and bind all CPU cores in NUMA node 1 to the OBProxy process.
kill -9 $(pgrep -x obproxy) numactl -N 1 -m 1 <command for starting OBProxy> kill -9 $(pgrep -x observer) numactl -C 0-31 -m 0 <command for starting OBServer>
You can use ps -ef | grep observer to view the current startup command and directly use it.
- Install sysbench.
# On the client, download the sysbench 1.0.20 source code to the /home directory. cd /home wget https://codeload.github.com/akopytov/sysbench/zip/refs/tags/1.0.20 --no-check-certificate unzip 1.0.20 # Install dependencies. yum -y install autoconf libtool mysql mysql-devel vim unzip # Download LuaJIT. wget https://github.com/LuaJIT/LuaJIT/archive/refs/heads/v2.1.zip --no-check-certificate unzip v2.1.zip # Copy luajit from the downloaded and extracted LuaJIT directory into sysbench to replace the original luajit. mv /home/sysbench-1.0.20/third_party/luajit/luajit /home/sysbench-1.0.20/third_party/luajit/luajit-bak cp -r /home/LuaJIT-2.1/ /home/sysbench-1.0.20/third_party/luajit/luajit # Modify the sysbench toolkit file sysbench.c. vim /home/sysbench-1.0.20/src/sysbench.c # Change line 86 to #define THREAD_INIT_TIMEOUT 300. # Compile and install sysbench 1.0.20. cd /home/sysbench-1.0.20 ./autogen.sh ./configure make make install # Set the maximum number of file descriptors that each user can open on the system to 1000000000. vi /etc/profile # Add the following line to the end of the file. ulimit -SHn 1000000000 # Run source to make it take effect. source /etc/profile # Check the version. sysbench --version
- Set the ApplySrv thread factor and record the baseline.When the parameter is 0, the native factor 0.5 is retained and no cap is applied. When the parameter is a non-zero value, the specified factor is used and the number of ApplySrv threads is capped at 128. Run the baseline test first:
obclient -h127.0.0.1 -P2828 -uroot@sys -Doceanbase -A \ -e "ALTER SYSTEM SET log_apply_thread_factor = 0 TENANT = 'mysql_tenant';" obclient -h127.0.0.1 -P2828 -uroot@sys -Doceanbase -A \ -e "SHOW PARAMETERS LIKE 'log_apply_thread_factor' TENANT = 'mysql_tenant';"
- Run cleanup, prepare, and run based on the current parameters.
vi sysbenchtest.sh export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/lib64/mysql:." SYSBENCH=sysbench LUA=/usr/local/share/sysbench/oltp_insert.lua HOST=127.0.0.1 PORT=2828 USER='obtest@mysql_tenant' PASSWORD=123456 DB=obtest THREADS=800 TABLE_SIZE=500000 TIME=300 "$SYSBENCH" --mysql-db="$DB" "$LUA" \ --mysql-host="$HOST" --mysql-port="$PORT" \ --mysql-user="$USER" --mysql-password="$PASSWORD" \ --db-ps-mode=disable --threads="$THREADS" \ --table_size="$TABLE_SIZE" cleanup "$SYSBENCH" --mysql-db="$DB" "$LUA" \ --mysql-host="$HOST" --mysql-port="$PORT" \ --mysql-user="$USER" --mysql-password="$PASSWORD" \ --db-ps-mode=disable --threads="$THREADS" \ --table_size="$TABLE_SIZE" prepare "$SYSBENCH" --mysql-db="$DB" "$LUA" \ --mysql-host="$HOST" --mysql-port="$PORT" \ --mysql-user="$USER" --mysql-password="$PASSWORD" \ --db-ps-mode=disable --report-interval=1 \ --mysql-ignore-errors=1062,6002,6001,4012,1213,1020,1205,4038,6004 \ --threads="$THREADS" --table_size="$TABLE_SIZE" \ --time="$TIME" --max-requests=0 --rand-type=uniform runTo save the test results, append 2>&1 | tee "sysbench_insert_$(date +%Y%m%d_%H%M%S).log" to the end of the run command. For the complete command, see run_insert_case in the next step.
- Compare the test results under different factors.After each factor adjustment, rerun the same cleanup, prepare, and run process while keeping the hardware, tenant resources, and sysbench parameters unchanged. For example, perform tests with the native baseline, factor 0.5, and factor 1.0 in sequence:
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/lib64/mysql:." SYSBENCH=sysbench LUA=/usr/local/share/sysbench/oltp_insert.lua HOST=127.0.0.1 PORT=2828 USER='obtest@mysql_tenant' PASSWORD=123456 DB=obtest THREADS=800 TABLE_SIZE=500000 TIME=300 run_insert_case() { factor="$1" log="sysbench_insert_factor_${factor}_$(date +%Y%m%d_%H%M%S).log" obclient -h127.0.0.1 -P2828 -uroot@sys -Doceanbase -A \ -e "ALTER SYSTEM SET log_apply_thread_factor = ${factor} TENANT = 'mysql_tenant';" echo "===== factor=${factor} =====" "$SYSBENCH" --mysql-db="$DB" "$LUA" \ --mysql-host="$HOST" --mysql-port="$PORT" \ --mysql-user="$USER" --mysql-password="$PASSWORD" \ --db-ps-mode=disable --threads="$THREADS" \ --table_size="$TABLE_SIZE" cleanup "$SYSBENCH" --mysql-db="$DB" "$LUA" \ --mysql-host="$HOST" --mysql-port="$PORT" \ --mysql-user="$USER" --mysql-password="$PASSWORD" \ --db-ps-mode=disable --threads="$THREADS" \ --table_size="$TABLE_SIZE" prepare "$SYSBENCH" --mysql-db="$DB" "$LUA" \ --mysql-host="$HOST" --mysql-port="$PORT" \ --mysql-user="$USER" --mysql-password="$PASSWORD" \ --db-ps-mode=disable --report-interval=1 \ --mysql-ignore-errors=1062,6002,6001,4012,1213,1020,1205,4038,6004 \ --threads="$THREADS" --table_size="$TABLE_SIZE" \ --time="$TIME" --max-requests=0 --rand-type=uniform run \ 2>&1 | tee "$log" } for factor in 0 0.5 1.0; do run_insert_case "$factor" sleep 60 doneThe parameter takes effect dynamically, so there is no need to restart the OBServer. Record the ApplySrv threads and OBServer logs before and after each test.observer_pid=$(pgrep -xo observer) ps -T -p "${observer_pid}" -o tid=,comm= | grep 'ApplySrv'Finally, use the throughput in the sysbench output as the test result, and use ps -T to confirm whether the ApplySrv thread configuration takes effect as expected.
The sysbench insert tests show a 5% improvement in QPS performance.
Figure 1 Performance comparison before and after the optimization feature is enabled
- Create the test account and database, and bind CPU cores to the processes.