Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into uniffi-kotlin
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand committed Oct 13, 2023
2 parents 00d289a + 43a3137 commit 1089194
Show file tree
Hide file tree
Showing 61 changed files with 1,385 additions and 220 deletions.
14 changes: 10 additions & 4 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
module.exports = {
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/warnings",
],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint", 'eslint-plugin-tsdoc'],
plugins: ["@typescript-eslint", "eslint-plugin-tsdoc", "import"],
root: true,
env: {
browser: true,
node: true,
jest: true,
},
rules: {
'tsdoc/syntax': 'error'
}
"tsdoc/syntax": "error",
"import/no-unresolved": "off",
},
};
46 changes: 46 additions & 0 deletions .github/workflows/java-benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Java client benchmarks

on:
workflow_dispatch:
inputs:
name:
required: false
type: string

run-name: ${{ inputs.name == '' && format('{0} @ {1}', github.ref_name, github.sha) || inputs.name }}

jobs:
java-benchmark:
strategy:
matrix:
java:
- 11
- 17
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: ${{ matrix.java }}

- name: Start Redis
run: docker run -p 6379:6379 -p 8001:8001 -d redis/redis-stack

- name: Run benchmarks
working-directory: java
run: ./gradlew :benchmark:run

- name: Upload test reports
if: always()
continue-on-error: true
uses: actions/upload-artifact@v3
with:
name: test-reports-${{ matrix.java }}
path: |
java/benchmarks/build/reports/**
62 changes: 62 additions & 0 deletions .github/workflows/java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Java CI

on:
pull_request:
push:
paths:
- "java/**"
- ".github/workflows/java.yml"

# Run only most latest job on a branch and cancel previous ones
concurrency:
group: ${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
build-and-test-java-client:
strategy:
# Run all jobs
fail-fast: false
matrix:
java:
- 11
- 17
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: ${{ matrix.java }}

- name: Install and run protoc (protobuf)
run: |
sudo apt update
sudo apt install -y protobuf-compiler
mkdir -p java/client/src/main/java/org/babushka/javababushka/generated
protoc -Iprotobuf=babushka-core/src/protobuf/ --java_out=java/client/src/main/java/org/babushka/javababushka/generated babushka-core/src/protobuf/*.proto
- name: Build rust part
working-directory: java
run: cargo build

- name: Start Redis
run: docker run -p 6379:6379 -p 8001:8001 -d redis/redis-stack

- name: Build java part
working-directory: java
run: ./gradlew --continue build

- name: Upload test reports
if: always()
continue-on-error: true
uses: actions/upload-artifact@v3
with:
name: test-reports-${{ matrix.java }}
path: |
java/client/build/reports/**
java/integTest/build/reports/**
18 changes: 17 additions & 1 deletion .github/workflows/lint-ts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,24 @@ jobs:
timeout-minutes: 10
steps:
- uses: actions/checkout@v4

- uses: ./.github/workflows/lint-ts
with:
package-folder: ./node
name: lint node

- uses: ./.github/workflows/lint-ts
with:
package-folder: ./benchmarks/node
name: lint benchmark

- uses: ./.github/workflows/lint-ts
with:
package-folder: ./benchmarks/utilities
name: lint benchmark utilities

- name: lint ts
run: |
npm install @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-tsdoc eslint typescript
npm install @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-tsdoc eslint typescript eslint-plugin-import@latest eslint-config-prettier
npm i
npx eslint .
23 changes: 23 additions & 0 deletions .github/workflows/lint-ts/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Lint TypeScript

inputs:
package-folder:
description: "folder that contains the target Cargo.toml file"
required: true
type: string

runs:
using: "composite"

steps:
- uses: actions/checkout@v4

- run: cp .eslintrc.cjs ${{ inputs.package-folder }}
shell: bash

- run: |
npm install @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-tsdoc eslint typescript eslint-plugin-import@latest eslint-config-prettier
npm i
npx eslint . --max-warnings=0
working-directory: ${{ inputs.package-folder }}
shell: bash
7 changes: 6 additions & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
working-directory: ./python
run: |
python -m pip install --upgrade pip
pip install flake8 isort black mypy-protobuf
pip install flake8 isort black mypy-protobuf deadcode
- name: Lint with isort
working-directory: ./python
Expand All @@ -71,6 +71,11 @@ jobs:
run: |
black --target-version py36 --check --diff .
- name: Lint with deadcode
working-directory: .
run: |
deadcode . --ignore-definitions=InfoSection,Level,*protobuf*,*pytest*
- name: Start redis server
working-directory: ./python
run: redis-server &
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 20
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
Expand Down
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
debug/
target/

# Git stuff
.worktrees

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
Expand All @@ -17,6 +20,14 @@ dump.rdb
.env
benchmarks/results

# IDE generaged files
.vs
.vscode
.idea

# MacOS metadata
.DS_Store

# lock files

yarn.lock
Expand Down
2 changes: 1 addition & 1 deletion babushka-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ criterion = { version = "^0.5", features = ["html_reports", "async_tokio"] }
which = "4.4.0"
ctor = "0.2.2"
redis = { path = "../submodules/redis-rs/redis", features = ["tls-rustls-insecure"] }
iai-callgrind = "0.6"
iai-callgrind = "0.7"
tokio = { version = "1", features = ["rt-multi-thread"] }
once_cell = "1.18.0"

Expand Down
51 changes: 43 additions & 8 deletions babushka-core/benches/memory_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use babushka::{
client::Client,
connection_request::{AddressInfo, ConnectionRequest, TlsMode},
};
use iai_callgrind::{black_box, main};
use iai_callgrind::{black_box, library_benchmark, library_benchmark_group, main};
use redis::{cmd, Value};
use tokio::runtime::Builder;

Expand All @@ -28,14 +28,12 @@ where
});
}

// Don't forget the `#[inline(never)]`
#[inline(never)]
#[library_benchmark]
fn just_setup() {
runner(|_| async {});
}

// Don't forget the `#[inline(never)]`
#[inline(never)]
#[library_benchmark]
fn send_message() {
runner(|mut client| async move {
client
Expand All @@ -45,8 +43,7 @@ fn send_message() {
});
}

// Don't forget the `#[inline(never)]`
#[inline(never)]
#[library_benchmark]
fn send_and_receive_messages() {
runner(|mut client| async move {
let mut command = cmd("SET");
Expand Down Expand Up @@ -77,4 +74,42 @@ fn send_and_receive_messages() {
});
}

main!(just_setup, send_message, send_and_receive_messages);
#[library_benchmark]
fn lots_of_messages() {
runner(|mut client| async move {
for _ in 0..1000 {
let mut command = cmd("SET");
command.arg("foo").arg("bar");
client
.req_packed_command(&black_box(command), None)
.await
.unwrap();
let mut command = cmd("SET");
command.arg("baz").arg("foo");
client
.req_packed_command(&black_box(command), None)
.await
.unwrap();
let mut command = cmd("MGET");
command.arg("baz").arg("foo");
let result = client
.req_packed_command(&black_box(command), None)
.await
.unwrap();
assert!(
result
== Value::Bulk(vec![
Value::Data(b"foo".to_vec()),
Value::Data(b"bar".to_vec())
])
)
}
});
}

library_benchmark_group!(
name = cluster;
benchmarks = just_setup, send_message, send_and_receive_messages, lots_of_messages
);

main!(library_benchmark_groups = cluster);
42 changes: 41 additions & 1 deletion babushka-core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::connection_request::{
AddressInfo, AuthenticationInfo, ConnectionRequest, ReadFromReplicaStrategy, TlsMode,
};
use futures::FutureExt;
use logger_core::log_info;
use redis::cluster_async::ClusterConnection;
use redis::cluster_routing::{RoutingInfo, SingleNodeRoutingInfo};
use redis::{
Expand Down Expand Up @@ -165,7 +166,7 @@ async fn create_cluster_client(
request: ConnectionRequest,
) -> RedisResult<redis::cluster_async::ClusterConnection> {
// TODO - implement timeout for each connection attempt
let tls_mode = request.tls_mode.enum_value_or(TlsMode::NoTls);
let tls_mode = request.tls_mode.enum_value_or_default();
let redis_connection_info = get_redis_connection_info(request.authentication_info.0, 0);
let initial_nodes = request
.addresses
Expand Down Expand Up @@ -224,10 +225,49 @@ impl std::fmt::Display for ConnectionError {
}
}

fn format_non_zero_value(name: &'static str, value: u32) -> String {
if value > 0 {
format!("\n{name}: {value}")
} else {
String::new()
}
}

fn sanitized_request_string(request: &ConnectionRequest) -> String {
let addresses = request
.addresses
.iter()
.map(|address| format!("{}:{}", address.host, address.port))
.collect::<Vec<_>>()
.join(", ");
let tls_mode = request.tls_mode.enum_value_or_default();
let cluster_mode = request.cluster_mode_enabled;
let response_timeout = format_non_zero_value("response timeout", request.response_timeout);
let client_creation_timeout =
format_non_zero_value("client creation timeout", request.client_creation_timeout);
let database_id = format_non_zero_value("database ID", request.database_id);
let rfr_strategy = request.read_from_replica_strategy.enum_value_or_default();
let connection_retry_strategy = match &request.connection_retry_strategy.0 {
Some(strategy) => {
format!("\nreconnect backoff strategy: number of increasing duration retries: {}, base: {}, factor: {}",
strategy.number_of_retries, strategy.exponent_base, strategy.factor)
}
None => String::new(),
};

format!(
"\naddresses: {addresses}\nTLS mode: {tls_mode:?}\ncluster mode: {cluster_mode}{response_timeout}{client_creation_timeout}\nRead from replica strategy: {rfr_strategy:?}{database_id}{connection_retry_strategy}",
)
}

impl Client {
pub async fn new(request: ConnectionRequest) -> Result<Self, ConnectionError> {
const DEFAULT_CLIENT_CREATION_TIMEOUT: Duration = Duration::from_millis(2500);

log_info(
"Connection configuration",
sanitized_request_string(&request),
);
let response_timeout = to_duration(request.response_timeout, DEFAULT_RESPONSE_TIMEOUT);
let total_connection_timeout = to_duration(
request.client_creation_timeout,
Expand Down
Loading

0 comments on commit 1089194

Please sign in to comment.