Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Limit iter v2 #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: second-iteration
Choose a base branch
Loading
from
Draft
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
17 changes: 14 additions & 3 deletions 17 benchmark/logic_rust/concurrent_insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,34 @@ use scylla::client::session::Session;
use scylla::client::session_builder::SessionBuilder;
use scylla::statement::prepared::PreparedStatement;
use std::env;
use std::sync::atomic::AtomicI32;
use std::sync::Arc;
use tokio::sync::Barrier;
use uuid::Uuid;

const CONCURRENCY: usize = 2000;
const CONCURRENCY: usize = 500;
const STEP: usize = 200000;
static COUNTER: AtomicI32 = AtomicI32::new(0);

async fn insert_data(
session: Arc<Session>,
start_index: usize,
n: i32,
insert_query: &PreparedStatement,
barrier: Arc<Barrier>,
) -> Result<(), Box<dyn std::error::Error>> {
let mut index = start_index;

while index < n as usize {
let id = Uuid::new_v4();
session.execute_unpaged(insert_query, (id, 100)).await?;
if index / STEP != (index + CONCURRENCY) / STEP {
let w = COUNTER.fetch_add(1, std::sync::atomic::Ordering::Acquire);
println!("Waiting: {w}");
barrier.wait().await;
}
index += CONCURRENCY;
}

Ok(())
}

Expand Down Expand Up @@ -60,12 +69,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let mut handles = vec![];
let session = Arc::new(session);
let barrier = Arc::new(Barrier::new(CONCURRENCY));

for i in 0..CONCURRENCY {
let session_clone = Arc::clone(&session);
let insert_query_clone = insert_query.clone();
let barrier_clone = barrier.clone();
handles.push(tokio::spawn(async move {
insert_data(session_clone, i, n, &insert_query_clone)
insert_data(session_clone, i, n, &insert_query_clone, barrier_clone)
.await
.unwrap();
}));
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.