forked from TechEmpower/FrameworkBenchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vapor] add sqlkit + raw postgres tests, separate fluent tests (TechE…
- Loading branch information
1 parent
00ec4c3
commit e432800
Showing
20 changed files
with
430 additions
and
40 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,79 @@ | ||
{ | ||
"framework": "vapor", | ||
"tests": [ | ||
{ | ||
"default": { | ||
"plaintext_url": "/plaintext", | ||
"json_url": "/json", | ||
"db_url": "/db", | ||
"query_url": "/queries?queries=", | ||
"port": 8080, | ||
"approach": "Realistic", | ||
"classification": "Fullstack", | ||
"database": "Postgres", | ||
"framework": "Vapor", | ||
"language": "Swift", | ||
"flavor": "None", | ||
"orm": "Full", | ||
"platform": "None", | ||
"webserver": "None", | ||
"os": "Linux", | ||
"database_os": "Linux", | ||
"display_name": "Vapor", | ||
"notes": "", | ||
"versus": "None" | ||
} | ||
"tests": [{ | ||
"default": { | ||
"plaintext_url": "/plaintext", | ||
"json_url": "/json", | ||
"port": 8080, | ||
"approach": "Realistic", | ||
"classification": "Fullstack", | ||
"framework": "Vapor", | ||
"language": "Swift", | ||
"flavor": "None", | ||
"platform": "None", | ||
"webserver": "None", | ||
"os": "Linux", | ||
"database_os": "Linux", | ||
"display_name": "Vapor", | ||
"notes": "", | ||
"versus": "None" | ||
}, | ||
"fluent": { | ||
"db_url": "/db", | ||
"query_url": "/queries?queries=", | ||
"port": 8080, | ||
"approach": "Realistic", | ||
"classification": "Fullstack", | ||
"database": "Postgres", | ||
"framework": "Vapor", | ||
"language": "Swift", | ||
"flavor": "None", | ||
"orm": "Full", | ||
"platform": "None", | ||
"webserver": "None", | ||
"os": "Linux", | ||
"database_os": "Linux", | ||
"display_name": "Vapor", | ||
"notes": "", | ||
"versus": "None" | ||
}, | ||
"sql-kit": { | ||
"db_url": "/db", | ||
"query_url": "/queries?queries=", | ||
"port": 8080, | ||
"approach": "Realistic", | ||
"classification": "Fullstack", | ||
"database": "Postgres", | ||
"framework": "Vapor", | ||
"language": "Swift", | ||
"flavor": "None", | ||
"orm": "Micro", | ||
"platform": "None", | ||
"webserver": "None", | ||
"os": "Linux", | ||
"database_os": "Linux", | ||
"display_name": "Vapor", | ||
"notes": "", | ||
"versus": "None" | ||
}, | ||
"postgres": { | ||
"db_url": "/db", | ||
"query_url": "/queries?queries=", | ||
"port": 8080, | ||
"approach": "Realistic", | ||
"classification": "Fullstack", | ||
"database": "Postgres", | ||
"framework": "Vapor", | ||
"language": "Swift", | ||
"flavor": "None", | ||
"orm": "Raw", | ||
"platform": "None", | ||
"webserver": "None", | ||
"os": "Linux", | ||
"database_os": "Linux", | ||
"display_name": "Vapor", | ||
"notes": "", | ||
"versus": "None" | ||
} | ||
] | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// swift-tools-version:5.1 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "vapor-default", | ||
platforms: [ | ||
.macOS(.v10_15) | ||
], | ||
products: [ | ||
.executable(name: "app", targets: ["App"]) | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"), | ||
], | ||
targets: [ | ||
.target(name: "App", dependencies: [ | ||
"Vapor", | ||
], path: "Sources") | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Vapor | ||
|
||
var env = try Environment.detect() | ||
try LoggingSystem.bootstrap(from: &env) | ||
|
||
let app = Application(env) | ||
defer { app.shutdown() } | ||
|
||
app.http.server.configuration.serverName = "Vapor" | ||
|
||
app.logger.notice("💧 VAPOR") | ||
app.logger.notice("System.coreCount: \(System.coreCount)") | ||
|
||
app.get("plaintext") { req in | ||
"Hello, world!" | ||
} | ||
|
||
app.get("json") { req in | ||
["message": "Hello, world!"] | ||
} | ||
|
||
try app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# ================================ | ||
# Build image | ||
# ================================ | ||
FROM vapor/swift:5.2 as build | ||
WORKDIR /build | ||
|
||
# Copy entire repo into container | ||
COPY ./vapor-fluent . | ||
|
||
# Compile with optimizations | ||
RUN swift build \ | ||
--enable-test-discovery \ | ||
-c release | ||
|
||
# ================================ | ||
# Run image | ||
# ================================ | ||
FROM vapor/ubuntu:18.04 | ||
WORKDIR /run | ||
|
||
# Copy build artifacts | ||
COPY --from=build /build/.build/release /run | ||
|
||
# Copy Swift runtime libraries | ||
COPY --from=build /usr/lib/swift/ /usr/lib/swift/ | ||
|
||
ENTRYPOINT ["./app", "serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# ================================ | ||
# Build image | ||
# ================================ | ||
FROM vapor/swift:5.2 as build | ||
WORKDIR /build | ||
|
||
# Copy entire repo into container | ||
COPY ./vapor-postgres . | ||
|
||
# Compile with optimizations | ||
RUN swift build \ | ||
--enable-test-discovery \ | ||
-c release | ||
|
||
# ================================ | ||
# Run image | ||
# ================================ | ||
FROM vapor/ubuntu:18.04 | ||
WORKDIR /run | ||
|
||
# Copy build artifacts | ||
COPY --from=build /build/.build/release /run | ||
|
||
# Copy Swift runtime libraries | ||
COPY --from=build /usr/lib/swift/ /usr/lib/swift/ | ||
|
||
ENTRYPOINT ["./app", "serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// swift-tools-version:5.1 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "vapor-sql-kit", | ||
platforms: [ | ||
.macOS(.v10_15) | ||
], | ||
products: [ | ||
.executable(name: "app", targets: ["App"]) | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"), | ||
.package(url: "https://github.com/vapor/postgres-kit.git", from: "2.0.0"), | ||
], | ||
targets: [ | ||
.target(name: "App", dependencies: [ | ||
"PostgresKit", | ||
"Vapor" | ||
], path: "Sources") | ||
] | ||
) |
25 changes: 25 additions & 0 deletions
25
frameworks/Swift/vapor/vapor-postgres/Sources/Utilities.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Vapor | ||
|
||
extension Int { | ||
func bounded(to range: ClosedRange<Int>) -> Int { | ||
switch self { | ||
case ...range.lowerBound: | ||
return range.lowerBound | ||
case range.upperBound...: | ||
return range.upperBound | ||
default: | ||
return self | ||
} | ||
} | ||
} | ||
|
||
extension System { | ||
// tfb-server (aka, citrine) uses 28 hyper-threaded cores | ||
// postgresql.conf specifies max_connections = 2000 | ||
// | ||
// 2000 / (28 * 2) = 35.7 (theoretical max) | ||
// | ||
// https://github.com/TechEmpower/FrameworkBenchmarks/wiki/Project-Information-Environment#citrine-self-hosted | ||
// https://github.com/TechEmpower/FrameworkBenchmarks/blob/master/toolset/databases/postgres/postgresql.conf#L64 | ||
static var maxConnectionsPerEventLoop: Int { 32 } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Vapor | ||
|
||
struct World: Content { | ||
var id: Int32? | ||
var randomnumber: Int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import PostgresKit | ||
import Vapor | ||
|
||
var env = try Environment.detect() | ||
try LoggingSystem.bootstrap(from: &env) | ||
|
||
let app = Application(env) | ||
defer { app.shutdown() } | ||
|
||
app.http.server.configuration.serverName = "Vapor" | ||
|
||
app.logger.notice("💧 VAPOR") | ||
app.logger.notice("System.coreCount: \(System.coreCount)") | ||
app.logger.notice("System.maxConnectionsPerEventLoop: \(System.maxConnectionsPerEventLoop)") | ||
|
||
let pools = EventLoopGroupConnectionPool( | ||
source: PostgresConnectionSource(configuration: .init( | ||
hostname: "tfb-database", | ||
username: "benchmarkdbuser", | ||
password: "benchmarkdbpass", | ||
database: "hello_world" | ||
)), | ||
maxConnectionsPerEventLoop: System.maxConnectionsPerEventLoop, | ||
on: app.eventLoopGroup | ||
) | ||
|
||
extension Request { | ||
func db(_ pools: EventLoopGroupConnectionPool<PostgresConnectionSource>) -> PostgresDatabase { | ||
pools.pool(for: self.eventLoop).database(logger: self.logger) | ||
} | ||
} | ||
|
||
app.get("db") { req in | ||
req.db(pools).query("SELECT id, randomnumber FROM World WHERE id = $1", [ | ||
PostgresData(int32: .random(in: 1...10_000)) | ||
]).map { | ||
$0.first | ||
}.unwrap(or: Abort(.notFound)).map { | ||
World( | ||
id: $0.column("id")?.int32 ?? 0, | ||
randomnumber: $0.column("randomnumber")?.int ?? 0 | ||
) | ||
} | ||
} | ||
|
||
app.get("queries") { req -> EventLoopFuture<[World]> in | ||
let queries = (req.query["queries"] ?? 1).bounded(to: 1...500) | ||
let db = req.db(pools) | ||
return (0 ..< queries).map { _ -> EventLoopFuture<World> in | ||
db.query("SELECT id, randomnumber FROM World WHERE id = $1", [ | ||
PostgresData(int32: .random(in: 1...10_000)) | ||
]).map { | ||
$0.first | ||
}.unwrap(or: Abort(.notFound)).map { | ||
World( | ||
id: $0.column("id")?.int32 ?? 0, | ||
randomnumber: $0.column("randomnumber")?.int ?? 0 | ||
) | ||
} | ||
}.flatten(on: req.eventLoop) | ||
} | ||
|
||
try app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# ================================ | ||
# Build image | ||
# ================================ | ||
FROM vapor/swift:5.2 as build | ||
WORKDIR /build | ||
|
||
# Copy entire repo into container | ||
COPY ./vapor-sql-kit . | ||
|
||
# Compile with optimizations | ||
RUN swift build \ | ||
--enable-test-discovery \ | ||
-c release | ||
|
||
# ================================ | ||
# Run image | ||
# ================================ | ||
FROM vapor/ubuntu:18.04 | ||
WORKDIR /run | ||
|
||
# Copy build artifacts | ||
COPY --from=build /build/.build/release /run | ||
|
||
# Copy Swift runtime libraries | ||
COPY --from=build /usr/lib/swift/ /usr/lib/swift/ | ||
|
||
ENTRYPOINT ["./app", "serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"] |
Oops, something went wrong.