DatabaseTester
检查你的服务器是否能真正连接到数据库,并告知你它们的响应速度。
指向插件所使用的任何数据库,运行 /database test,即可获得按数据库分类的报告:
驱动程序、连接时间、Ping 值、往返延迟以及可选的读写测试。config.yml
会在每次运行时从磁盘读取,因此你可以修改密码后再次运行命令,
而无需重载或重启即可看到结果。
支持的数据库
| 类型键 |
数据库 |
通过...通信 |
mysql |
MySQL |
JDBC |
mariadb |
MariaDB |
JDBC |
postgresql |
PostgreSQL |
JDBC |
sqlserver |
Microsoft SQL Server |
JDBC |
sqlite |
SQLite |
JDBC, 基于文件 |
h2 |
H2 |
JDBC, 基于文件 |
mongodb |
MongoDB |
mongodb-driver-sync |
redis |
Redis 和 Valkey |
Jedis |
所有驱动程序均已打包。无需安装,启动时也无须下载。
命令
| 命令 |
权限 |
描述 |
/database test |
databasetester.test |
测试所有已启用的数据库 |
/database test <name> |
databasetester.test |
测试单个数据库,包括禁用的 |
/database list |
databasetester.use |
显示已配置的内容 |
/database types |
databasetester.use |
显示支持的类型键 |
别名为 /db 和 /dbtest。所有权限默认赋予管理员(operators)。
测试过程
- Driver 加载指定类型的 JDBC 驱动程序或客户端。
- Connect 打开一个新连接并计时。
- Ping 执行
SELECT 1、Mongo ping 命令或 Redis PING。
- Latency 重复该往返操作数次,报告最小值、平均值和最大值。
- Write test 创建一个临时表、集合或键,写入一行数据,读回它,
删除它并再次丢弃容器。如果账户是只读的,请关闭此功能。
所有内容均在服务器线程之外运行,一个接一个地处理数据库,并设有硬性超时限制。
挂起的数据库不会阻塞服务器或后续的运行。
重启后的第一次运行会比其余几次慢,因为驱动程序类是在此次运行中加载的。
请以第二次运行的数据为准,而非第一次。
测试环境
以下每种类型均在 Paper 1.21.11 和 Java 21 上的实时服务器中进行了测试,包含写测试:MySQL 8.4.6 (caching_sha2_password)、MariaDB 11.4.4、PostgreSQL 16.15、SQL Server
2022 (16.0.4275)、SQLite 3.49.1、H2 2.3.232、MongoDB 8.0.4 和 Redis 7.4.1。
其中有一个数字值得重申,因为这正是本插件旨在揭示的问题类型:相同的 SQLite 写测试在 ext4 上耗时 6 ms,而在 NTFS 卷上耗时 3.4 秒。数据库本身没有问题;其底层的文件系统才有问题。
配置
databases 下的每个条目都是一个目标,其键是你传递给
/database test <name> 的名称。随插件附带的文件会对每个选项进行内联解释。
settings:
connect-timeout-seconds: 5
query-timeout-seconds: 5
latency-samples: 5
write-test: true
test-table-prefix: dbtester_
log-to-console: true
databases:
survival-mysql:
enabled: true
type: mysql
host: localhost
port: 3306
database: minecraft
username: root
password: ''
properties:
useSSL: false
properties 会原封不动地传递给驱动程序,因此驱动程序接受的任何内容均可生效。对于无法通过字段表达的连接设置,请改为设置 url,它将替换 host、port 和 database。
SQLite 和 H2 使用 file 代替主机名。相对路径相对于服务器目录解析,因此 plugins/SomePlugin/database.db 指向另一个插件的数据库,让你可以在不触碰该插件的情况下检查它。Redis 对数据库进行编号,因此其 database 字段接受字符串形式的数字,且 username 仅用于 Redis 6 ACL 用户。
要求
需要 Paper 1.20 或更高版本,并使用 Java 21。支持 Folia。不支持 Spigot,因为该插件使用 Paper 的全局区域调度器将结果返回给服务器线程。
DatabaseTester
Checks that your server can actually reach its databases, and tells you how fast they answer.
Point it at whatever your plugins use, run /database test, and you get a per-database report:
driver, connect time, ping, round trip latency and an optional read/write check. config.yml
is read from disk on every single run, so you can fix a password, run the command again, and
see the result without a reload or a restart.
Supported databases
| Type key |
Database |
Talks over |
mysql |
MySQL |
JDBC |
mariadb |
MariaDB |
JDBC |
postgresql |
PostgreSQL |
JDBC |
sqlserver |
Microsoft SQL Server |
JDBC |
sqlite |
SQLite |
JDBC, file based |
h2 |
H2 |
JDBC, file based |
mongodb |
MongoDB |
mongodb-driver-sync |
redis |
Redis and Valkey |
Jedis |
Every driver is bundled. Nothing to install, nothing to download at startup.
Commands
| Command |
Permission |
Description |
/database test |
databasetester.test |
Test every enabled database |
/database test <name> |
databasetester.test |
Test one database, even a disabled one |
/database list |
databasetester.use |
Show what is configured |
/database types |
databasetester.use |
Show the supported type keys |
Aliases are /db and /dbtest. All permissions default to operators.
What a test does
- Driver loads the JDBC driver or client for the configured type.
- Connect opens a fresh connection and times it.
- Ping runs
SELECT 1, a Mongo ping command or a Redis PING.
- Latency repeats that round trip a few times and reports min, average and max.
- Write test creates a throwaway table, collection or key, writes a row, reads it back,
deletes it and drops the container again. Turn it off if the account is read only.
Everything runs off the server thread, one database after another, under a hard timeout. A
database that hangs cannot stall the server or the rest of the run.
The first run after a restart is slower than the rest, because the driver classes are loaded
during it. Read the second run for real numbers, not the first.
Tested against
Every type below was tested against a live server on Paper 1.21.11 and Java 21, write test
included: MySQL 8.4.6 (caching_sha2_password), MariaDB 11.4.4, PostgreSQL 16.15, SQL Server
2022 (16.0.4275), SQLite 3.49.1, H2 2.3.232, MongoDB 8.0.4 and Redis 7.4.1.
One number from that run is worth repeating, because it is the kind of thing this plugin
exists to surface: the same SQLite write test took 6 ms on ext4 and 3.4 seconds on an NTFS
volume. The database was fine; the filesystem underneath it was not.
Configuration
Each entry under databases is one target, and the key is the name you pass to
/database test <name>. The file shipped with the plugin explains every option inline.
settings:
connect-timeout-seconds: 5
query-timeout-seconds: 5
latency-samples: 5
write-test: true
test-table-prefix: dbtester_
log-to-console: true
databases:
survival-mysql:
enabled: true
type: mysql
host: localhost
port: 3306
database: minecraft
username: root
password: ''
properties:
useSSL: false
properties is handed to the driver untouched, so anything the driver accepts works. For
connections those fields cannot express, set url instead and it replaces host, port and
database.
SQLite and H2 take a file instead of a host. Relative paths resolve against the server
directory, so plugins/SomePlugin/database.db points at another plugin's database and lets
you check it without touching that plugin. Redis numbers its databases, so its database
field takes a number as a string, and username is only needed for Redis 6 ACL users.
Requirements
Paper 1.20 or newer on Java 21. Folia is supported. Spigot is not, because the plugin uses
Paper's global region scheduler to hand results back to the server thread.
评论 0
登录后参与评分
还没有评论,来抢沙发吧