Skip to content
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

Add vm concurrency support #2016

Open
kirugan opened this issue Aug 5, 2024 · 7 comments · May be fixed by #2059
Open

Add vm concurrency support #2016

kirugan opened this issue Aug 5, 2024 · 7 comments · May be fixed by #2059
Assignees
Labels
go Pull requests that update Go code no-stale rust Pull requests that update Rust code VM

Comments

@kirugan
Copy link
Contributor

kirugan commented Aug 5, 2024

We should allow users to use the latest Blockifier feature, which is concurrent execution. We should add a Go flag (boolean) vm-concurrency-mode that will trigger parallel execution in Blockifier. This will require restructuring the Rust code that handles transactions.

Keep in mind that concurrent transactions may modify shared data structures (maps, slices), and we should protect them with mutexes on the Go side (CGo).

@obasekiosa
Copy link
Contributor

obasekiosa commented Aug 7, 2024

looks interesting, If no one has taken this in a two weeks or more.
i'll take it up. @kirugan for now i'd just slowly document the process / gotchas for implementing the change.

Copy link

onlydustapp bot commented Aug 7, 2024

Hey @obasekiosa!
Thanks for showing interest.
We've created an application for you to contribute to Juno.
Go check it out on OnlyDust!

@AnkushinDaniil
Copy link
Contributor

@obasekiosa Hey there! I was wondering if you wouldn't mind if I took on this task?

Copy link

onlydustapp bot commented Aug 12, 2024

Hey @AnkushinDaniil!
Thanks for showing interest.
We've created an application for you to contribute to Juno.
Go check it out on OnlyDust!

@AnkushinDaniil AnkushinDaniil self-assigned this Aug 12, 2024
@AnkushinDaniil AnkushinDaniil added VM go Pull requests that update Go code rust Pull requests that update Rust code labels Aug 15, 2024
@AnkushinDaniil
Copy link
Contributor

If earlier we processed all transactions sequentially, at the moment we must first collect txs from txns_and_query_bits, start tx_executor, wait until it finishes and in for (txn_index, result) in res.iter().enumerate() process the results. This is the main but not the only problem at the moment.

#[no_mangle]
pub extern "C" fn cairoVMExecute(
    // ...
    concurrency_mode: c_uchar,
) {
    // ...
    for (txn_index, txn_and_query_bit) in txns_and_query_bits.iter().enumerate() {
    //    ...
        match transaction_from_api(
            // ...
        ) {
            Ok(t) => txs.push(t),
            Err(e) => {
            // ...
            }
        }
    }

    let mut tx_executor = TransactionExecutor::new(
        state,
        block_context,
        TransactionExecutorConfig {
            concurrency_config: ConcurrencyConfig {
                enabled: concurrency_mode,
                // TODO: make this configurable
                n_workers: 4,
                chunk_size: 64,
            },
        },
    );

    let res = tx_executor.execute_txs(&txs);

    for (txn_index, result) in res.iter().enumerate() {
        let minimal_l1_gas_amount_vector: Option<GasVector>;
        match result {
            Ok(mut t) => {
                // ...
            }
            Err(e) => {
            //    ...
            }
        }
    }
}

@obasekiosa
Copy link
Contributor

obasekiosa commented Aug 15, 2024

If earlier we processed all transactions sequentially, at the moment we must first collect txs from txns_and_query_bits, start tx_executor, wait until it finishes and in for (txn_index, result) in res.iter().enumerate() process the results. This is the main but not the only problem at the moment.

#[no_mangle]
pub extern "C" fn cairoVMExecute(
    // ...
    concurrency_mode: c_uchar,
) {
    // ...
    for (txn_index, txn_and_query_bit) in txns_and_query_bits.iter().enumerate() {
    //    ...
        match transaction_from_api(
            // ...
        ) {
            Ok(t) => txs.push(t),
            Err(e) => {
            // ...
            }
        }
    }

    let mut tx_executor = TransactionExecutor::new(
        state,
        block_context,
        TransactionExecutorConfig {
            concurrency_config: ConcurrencyConfig {
                enabled: concurrency_mode,
                // TODO: make this configurable
                n_workers: 4,
                chunk_size: 64,
            },
        },
    );

    let res = tx_executor.execute_txs(&txs);

    for (txn_index, result) in res.iter().enumerate() {
        let minimal_l1_gas_amount_vector: Option<GasVector>;
        match result {
            Ok(mut t) => {
                // ...
            }
            Err(e) => {
            //    ...
            }
        }
    }
}

what is and why is it a problem?

@AnkushinDaniil
Copy link
Contributor

AnkushinDaniil commented Aug 15, 2024

We have to use more memory and we can't extract transaction trace in the provided solution.

@AnkushinDaniil AnkushinDaniil linked a pull request Aug 16, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code no-stale rust Pull requests that update Rust code VM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants