Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions frameworks/Java/tadx/README.cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Tad.x (tadx) 基准测试

## 项目概述
Tad.x 是一个用于基准测试的 Java Web 框架项目,是 [FrameworkBenchmarks](https://github.com/TechEmpower/FrameworkBenchmarks) 的一部分,主要用于测试不同 Web 框架的性能表现。

## 技术栈
- **Java 21**:项目的主要开发语言
- **Spring Boot**:当前使用的主要框架(从代码中可以看到之前可能使用过 Vert.x,现已注释)
- **Vert.x**:用于异步事件处理和数据库操作
- **PostgreSQL**:基准测试使用的数据库
- **Thymeleaf & FreeMarker**:模板引擎,用于Fortunes测试
- **Gradle**:项目构建工具

## 项目结构
```yaml
tadx/
├── src/main/java/io/tadx/benchmark/
│ ├── Application.java # Project entry point
│ ├── controller/ # Controller classes
│ ├── entity/ # Database entity classes
│ └── route_mapper/ # Route mapping implementations
├── src/main/resources/ # Resource files
│ ├── application.yaml # Configuration file
│ └── templates/ # Template files
├── build.gradle # Gradle build configuration
├── settings.gradle # Gradle settings
└── tadx.dockerfile # Docker deployment configuration
```

## 核心功能
项目实现了以下基准测试类型:

| 测试类型 | 路由 | 实现类 | 功能描述 |
|---------|------|-------|----------|
| JSON | /json | JsonRouteMapper.java | 返回简单JSON响应 |
| 文本 | /plaintext | PlainTextRouteMapper.java | 返回简单文本响应 |
| 数据库 | /db | DbRouteMapper_Postgresql.java | 单条数据库查询 |
| 多查询 | /query | QueriesRouteMapper1_Postgresql.java | 多条数据库查询 |
| 缓存查询 | /cached_query | CachedQueriesMapper3.java | 缓存查询结果 |
| 更新 | /update | UpdateMapper.java | 数据库更新操作 |
| 幸运饼干 | /fortunes | FortunesRouteMapper1.java | 模板渲染测试 |

## 实现特点

### 路由机制
- 使用自定义的 `@RouteMapping` 注解定义路由
- 每个测试类型对应一个 `RouteMapper` 接口实现
- 路由处理直接操作 Vert.x 的响应对象,减少中间层开销

### 数据库操作
- 使用 Vert.x 的 PostgreSQL 客户端进行异步数据库操作
- 配置了数据库连接池,最大连接数为 2000
- 支持 prepared statements 缓存,提高性能
- 定义了 `World` 和 `Fortune` 两个实体类映射数据库表

### 性能优化
- 直接设置 HTTP 响应头和状态码,减少框架开销
- 使用预编译语句和连接池提高数据库性能
- 缓存常用的响应头和日期字符串

## 运行方式
1. **直接运行**:通过 `Application.java` 的 main 方法启动 Spring Boot 应用
2. **构建运行**:使用 Gradle 构建 JAR 文件后运行
3. **Docker部署**:使用提供的 tadx.dockerfile 构建镜像并运行

## 配置文件
- `application.yaml`:Spring Boot 应用配置
- `benchmark_config.json`:基准测试配置

## 测试类型实现源代码

* [JSON](src/main/java/io/tadx/benchmark/route_mapper/JsonRouteMapper.java)
* [PLAINTEXT](src/main/java/io/tadx/benchmark/route_mapper/PlainTextRouteMapper.java)
* [DB](src/main/java/io/tadx/benchmark/route_mapper/DbRouteMapper_Postgresql.java)
* [QUERY](src/main/java/io/tadx/benchmark/route_mapper/QueriesRouteMapper1_Postgresql.java)
* [CACHED QUERY](src/main/java/io/tadx/benchmark/route_mapper/CachedQueriesMapper3.java)
* [UPDATE](src/main/java/io/tadx/benchmark/route_mapper/UpdateMapper.java)
* [FORTUNES](src/main/java/io/tadx/benchmark/route_mapper/FortunesRouteMapper1.java)


## 测试URLs
### JSON

http://localhost:8000/json

### PLAINTEXT

http://localhost:8000/plaintext

### DB

http://localhost:8000/db

### QUERY

http://localhost:8000/query?queries=

### CACHED QUERY

http://localhost:8000/cached_query?queries=

### UPDATE

http://localhost:8000/update?queries=

### FORTUNES

http://localhost:8000/fortunes
111 changes: 111 additions & 0 deletions frameworks/Java/tadx/README.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Tad.x (tadx) Benchmarking Test

## Project Overview
Tad.x is a Java web framework project for benchmarking, part of the [FrameworkBenchmarks](https://github.com/TechEmpower/FrameworkBenchmarks) project, designed to test the performance of different web frameworks.

## Technology Stack
- **Java 21**: The primary development language
- **Spring Boot**: The main framework currently used (previously used Vert.x, now commented out)
- **Vert.x**: For asynchronous event handling and database operations
- **PostgreSQL**: Database used for benchmarking
- **Thymeleaf & FreeMarker**: Template engines for the Fortunes test
- **Gradle**: Project build tool

## Project Structure
```yaml
tadx/
├── src/main/java/io/tadx/benchmark/
│ ├── Application.java # Project entry point
│ ├── controller/ # Controller classes
│ ├── entity/ # Database entity classes
│ └── route_mapper/ # Route mapping implementations
├── src/main/resources/ # Resource files
│ ├── application.yaml # Configuration file
│ └── templates/ # Template files
├── build.gradle # Gradle build configuration
├── settings.gradle # Gradle settings
└── tadx.dockerfile # Docker deployment configuration
```


plainText

## Core Features
The project implements the following benchmark test types:

| Test Type | Route | Implementation Class | Description |
|---------|------|-------|----------|
| JSON | /json | JsonRouteMapper.java | Returns a simple JSON response |
| PLAINTEXT | /plaintext | PlainTextRouteMapper.java | Returns a simple text response |
| DB | /db | DbRouteMapper_Postgresql.java | Single database query |
| QUERY | /query | QueriesRouteMapper1_Postgresql.java | Multiple database queries |
| CACHED QUERY | /cached_query | CachedQueriesMapper3.java | Caches query results |
| UPDATE | /update | UpdateMapper.java | Database update operations |
| FORTUNES | /fortunes | FortunesRouteMapper1.java | Template rendering test |

## Implementation Features

### Routing Mechanism
- Uses custom `@RouteMapping` annotation to define routes
- Each test type corresponds to a `RouteMapper` interface implementation
- Route handling directly manipulates Vert.x response objects to reduce overhead

### Database Operations
- Uses Vert.x PostgreSQL client for asynchronous database operations
- Configures database connection pool with maximum 2000 connections
- Supports prepared statements caching for improved performance
- Defines `World` and `Fortune` entity classes mapping to database tables

### Performance Optimization
- Directly sets HTTP response headers and status codes to reduce framework overhead
- Uses precompiled statements and connection pooling to improve database performance
- Caches commonly used response headers and date strings

## Running Methods
1. **Direct Run**: Start the Spring Boot application through the main method in `Application.java`
2. **Build and Run**: Build JAR file using Gradle and run it
3. **Docker Deployment**: Build image using the provided tadx.dockerfile and run it

## Configuration Files
- `application.yaml`: Spring Boot application configuration
- `benchmark_config.json`: Benchmark configuration

## Test Type Implementation Source Code

* [JSON](src/main/java/io/tadx/benchmark/route_mapper/JsonRouteMapper.java)
* [PLAINTEXT](src/main/java/io/tadx/benchmark/route_mapper/PlainTextRouteMapper.java)
* [DB](src/main/java/io/tadx/benchmark/route_mapper/DbRouteMapper_Postgresql.java)
* [QUERY](src/main/java/io/tadx/benchmark/route_mapper/QueriesRouteMapper1_Postgresql.java)
* [CACHED QUERY](src/main/java/io/tadx/benchmark/route_mapper/CachedQueriesMapper3.java)
* [UPDATE](src/main/java/io/tadx/benchmark/route_mapper/UpdateMapper.java)
* [FORTUNES](src/main/java/io/tadx/benchmark/route_mapper/FortunesRouteMapper1.java)


## Test URLs
### JSON

http://localhost:8000/json

### PLAINTEXT

http://localhost:8000/plaintext

### DB

http://localhost:8000/db

### QUERY

http://localhost:8000/query?queries=

### CACHED QUERY

http://localhost:8000/cached_query?queries=

### UPDATE

http://localhost:8000/update?queries=

### FORTUNES

http://localhost:8000/fortunes
45 changes: 7 additions & 38 deletions frameworks/Java/tadx/README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,11 @@
# Tad.x (tadx) Benchmarking Test
# Tad.x (tadx) Benchmarking Test / Tad.x (tadx) 基准测试

### Test Type Implementation Source Code
## Project Overview / 项目概述
Tad.x is a Java web framework project for benchmarking, part of the [FrameworkBenchmarks](https://github.com/TechEmpower/FrameworkBenchmarks) project, designed to test the performance of different web frameworks.

* [JSON](src/main/java/io/tadx/benchmark/route_mapper/JsonRouteMapper.java)
* [PLAINTEXT](src/main/java/io/tadx/benchmark/route_mapper/PlainTextRouteMapper.java)
* [DB](src/main/java/io/tadx/benchmark/route_mapper/DbRouteMapper_Postgresql.java)
* [QUERY](src/main/java/io/tadx/benchmark/route_mapper/QueriesRouteMapper1_Postgresql.java)
* [CACHED QUERY](src/main/java/io/tadx/benchmark/route_mapper/CachedQueriesMapper3.java)
* [UPDATE](src/main/java/io/tadx/benchmark/route_mapper/UpdateMapper.java)
* [FORTUNES](src/main/java/io/tadx/benchmark/route_mapper/FortunesRouteMapper1.java)
Tad.x 是一个用于基准测试的 Java Web 框架项目,是 [FrameworkBenchmarks](https://github.com/TechEmpower/FrameworkBenchmarks) 的一部分,主要用于测试不同 Web 框架的性能表现。



## Test URLs
### JSON

http://localhost:8000/json

### PLAINTEXT

http://localhost:8000/plaintext

### DB

http://localhost:8000/db

### QUERY

http://localhost:8000/query?queries=

### CACHED QUERY

http://localhost:8000/cached_query?queries=

### UPDATE

http://localhost:8000/update?queries=

### FORTUNES

http://localhost:8000/fortunes
## Detailed Documentation / 详细文档
- [English Version](README.en.md) / [英文版本](README.en.md)
- [Chinese Version](README.cn.md) / [中文版本](README.cn.md)
9 changes: 5 additions & 4 deletions frameworks/Java/tadx/benchmark_config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"framework": "tadx",
"maintainers": ["yn-tadpole"],
"tests": [
{
"default": {
Expand All @@ -10,21 +11,21 @@
"fortune_url": "/fortunes",
"update_url": "/update?queries=",
"cached_query_url" : "/cached_queries?count=",
"port": 8000,
"port": 8080,
"approach": "Realistic",
"classification": "Fullstack",
"database": "Postgres",
"framework": "tadx",
"framework": "Tad.x",
"language": "Java",
"flavor": "None",
"orm": "Micro",
"platform": "None",
"platform": "Tad.x",
"webserver": "None",
"os": "Linux",
"database_os": "Linux",
"display_name": "tadx",
"notes": "",
"versus": "None"
"versus": ""
}
}
]
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.tadx.data.DbStorage;
import io.tadx.web.HttpMethod;
import io.tadx.web.annotation.*;
import io.vertx.sqlclient.Tuple;

import java.util.SplittableRandom;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -36,7 +37,7 @@ public World[] execute(int count) {
World[] worlds = new World[count];
for (int i = 0; i < count; i++) {
int id = randomWorld();
worlds[i] = cache.computeIfAbsent(id, k -> dbStorage.findEntity(World.class, id));
worlds[i] = cache.computeIfAbsent(id, k -> dbStorage.findEntity(World.class, Tuple.of(id)));
}
return worlds;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.tadx.web.annotation.*;
import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.sqlclient.Tuple;

import java.util.SplittableRandom;

Expand All @@ -28,14 +29,14 @@ public Db1(DbStorage dbStorage) {
//@RestFunction(method = HttpMethod.GET)
public Future<World> execute() {
Promise<World> promise = Promise.promise();
World world = dbStorage.findEntity(World.class, randomWorld());
World world = dbStorage.findEntity(World.class, Tuple.of(randomWorld()));
promise.complete(world);
return promise.future();
}

@RestFunction(method = HttpMethod.GET)
public DataMap executeSQL() {
return dbStorage.queryRow("SELECT id, randomnumber FROM world WHERE id = ?", randomWorld());
return dbStorage.queryRow("SELECT id, randomnumber FROM world WHERE id = ?", Tuple.of(randomWorld()));
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package io.tadx.benchmark.controller;

import io.tadx.benchmark.db.PgConnPool;
import io.tadx.benchmark.entity.World;
import io.tadx.core.TadxApplication;
import io.tadx.web.HttpMethod;
import io.tadx.web.annotation.RestController;
import io.tadx.web.annotation.RestFunction;
import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.core.json.JsonObject;
import io.vertx.pgclient.PgBuilder;
import io.vertx.pgclient.PgConnectOptions;
import io.vertx.sqlclient.*;

import java.util.SplittableRandom;
Expand All @@ -18,23 +15,14 @@
* EN: The entry point of the application.
*/

@RestController(mapping = "/db_rest_reactive")
@RestController(mapping = "/db2")
public class Db2 {
private static final SplittableRandom RANDOM = new SplittableRandom();
private static final String SELECT_WORLD = "SELECT id, randomnumber from WORLD where id=$1";
private final PreparedQuery<RowSet<Row>> SELECT_WORLD_QUERY;

public Db2() {
PgConnectOptions connectOptions = new PgConnectOptions().
setPort(5432).setHost("tfb-database").
setDatabase("hello_world").
setUser("benchmarkdbuser").
setPassword("benchmarkdbpass").
setCachePreparedStatements(true).
setPreparedStatementCacheMaxSize(1024).
setPipeliningLimit(100000);
PoolOptions poolOptions = new PoolOptions().setMaxSize(2000);
SqlClient client = PgBuilder.client().with(poolOptions).connectingTo(connectOptions).using(TadxApplication.vertx()).build();
SqlClient client = PgConnPool.client();
SELECT_WORLD_QUERY = client.preparedQuery(SELECT_WORLD);
}

Expand Down
Loading
Loading