diff --git a/bcos-executor/src/executive/TransactionExecutive.cpp b/bcos-executor/src/executive/TransactionExecutive.cpp index 1411b787d9..9849c9e5a6 100644 --- a/bcos-executor/src/executive/TransactionExecutive.cpp +++ b/bcos-executor/src/executive/TransactionExecutive.cpp @@ -522,8 +522,8 @@ std::tuple, CallParameters::UniquePtr> TransactionE try { m_storageWrapper->createTable(tableName, std::string(STORAGE_VALUE)); - EXECUTIVE_LOG(INFO) << "create contract table " << LOG_KV("table", tableName) - << LOG_KV("sender", callParameters->senderAddress); + EXECUTIVE_LOG(DEBUG) << "create contract table " << LOG_KV("table", tableName) + << LOG_KV("sender", callParameters->senderAddress); if (m_blockContext.isAuthCheck() || (!m_blockContext.isWasm() && m_blockContext.blockVersion() >= BlockVersion::V3_3_VERSION)) diff --git a/bcos-sdk/sample/tars/CMakeLists.txt b/bcos-sdk/sample/tars/CMakeLists.txt index 100936fba9..02163bd660 100644 --- a/bcos-sdk/sample/tars/CMakeLists.txt +++ b/bcos-sdk/sample/tars/CMakeLists.txt @@ -3,3 +3,7 @@ target_link_libraries(performanceHelloWorld PUBLIC ${BCOS_CPP_SDK_TARGET} ${TARS add_executable(performanceTransfer performanceTransfer.cpp Common.cpp) target_link_libraries(performanceTransfer PUBLIC ${BCOS_CPP_SDK_TARGET} ${TARS_PROTOCOL_TARGET} bcos-crypto bcos-boostssl bcos-utilities) + +add_executable(performanceQuery performanceQuery.cpp Common.cpp) +target_link_libraries(performanceQuery PUBLIC ${BCOS_CPP_SDK_TARGET} ${TARS_PROTOCOL_TARGET} bcos-crypto bcos-boostssl bcos-utilities) + diff --git a/bcos-sdk/sample/tars/performanceQuery.cpp b/bcos-sdk/sample/tars/performanceQuery.cpp new file mode 100644 index 0000000000..137189d576 --- /dev/null +++ b/bcos-sdk/sample/tars/performanceQuery.cpp @@ -0,0 +1,307 @@ +#include "Common.h" +#include "bcos-cpp-sdk/tarsRPC/Handle.h" +#include "bcos-cpp-sdk/tarsRPC/RPCClient.h" +#include "bcos-crypto/interfaces/crypto/KeyPairInterface.h" +#include "bcos-framework/protocol/Transaction.h" +#include "bcos-utilities/FixedBytes.h" +#include "bcos-utilities/ratelimiter/TimeWindowRateLimiter.h" +#include "bcos-utilities/ratelimiter/TokenBucketRateLimiter.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __APPLE__ +#include +#endif +#include +#include +#include + +std::atomic_long blockNumber = 0; +constexpr static long blockLimit = 900; +constexpr static int64_t initialValue = 1000000000; +const static std::string DAG_TRANSFER_ADDRESS = "000000000000000000000000000000000000100c"; + +class PerformanceCallback : public bcos::sdk::Callback +{ +private: + std::latch& m_latch; + bcos::sample::Collector& m_collector; + long m_startTime; + +public: + PerformanceCallback(std::latch& latch, bcos::sample::Collector& collector) + : m_latch(latch), m_collector(collector), m_startTime(bcos::sample::currentTime()) + {} + + void onMessage([[maybe_unused]] int seq) override + { + m_latch.count_down(); + m_collector.receive(true, bcos::sample::currentTime() - m_startTime); + } +}; + +std::vector query(bcos::sdk::RPCClient& rpcClient, + std::shared_ptr cryptoSuite, std::string contractAddress, + int userCount) +{ + bcostars::protocol::TransactionFactoryImpl transactionFactory(cryptoSuite); + std::latch latch(userCount); + std::vector> handles(userCount); + + bcos::sample::Collector collector(userCount, "Query"); + tbb::parallel_for(tbb::blocked_range(0LU, (size_t)userCount), [&](const auto& range) { + for (auto it = range.begin(); it != range.end(); ++it) + { + bcos::codec::abi::ContractABICodec abiCodec(cryptoSuite->hashImpl()); + bcos::bytes input; + if (contractAddress == DAG_TRANSFER_ADDRESS) + { + input = abiCodec.abiIn("userBalance(string)", std::to_string(it)); + } + else + { + input = abiCodec.abiIn("balance(address)", bcos::Address(it)); + } + auto transaction = transactionFactory.createTransaction(0, contractAddress, input, + rpcClient.generateNonce(), blockNumber + blockLimit, "chain0", "group0", 0); + + handles[it].emplace(rpcClient); + auto& call = *(handles[it]); + call.setCallback(std::make_shared(latch, collector)); + call.send(*transaction); + + collector.send(true, 0); + } + }); + collector.finishSend(); + latch.wait(); + collector.report(); + + std::vector balances(userCount); + // Check result + tbb::parallel_for(tbb::blocked_range(0LU, (size_t)userCount), [&](const auto& range) { + for (auto it = range.begin(); it != range.end(); ++it) + { + auto receipt = handles[it]->get(); + if (receipt->status() != 0) + { + std::cout << "Query with error! " << receipt->status() << std::endl; + BOOST_THROW_EXCEPTION(std::runtime_error("Query with error!")); + } + + auto output = receipt->output(); + bcos::codec::abi::ContractABICodec abiCodec(cryptoSuite->hashImpl()); + bcos::s256 balance; + abiCodec.abiOut(output, balance); + + balances[it] = balance.convert_to(); + } + }); + + return balances; +} + +int issue(bcos::sdk::RPCClient& rpcClient, std::shared_ptr cryptoSuite, + std::shared_ptr keyPair, std::string contractAddress, + int userCount, [[maybe_unused]] int qps) +{ + bcostars::protocol::TransactionFactoryImpl transactionFactory(cryptoSuite); + std::latch latch(userCount); + std::vector> handles(userCount); + + bcos::sample::Collector collector(userCount, "Issue"); + tbb::parallel_for(tbb::blocked_range(0LU, (size_t)userCount), [&](const auto& range) { + for (auto it = range.begin(); it != range.end(); ++it) + { + bcos::codec::abi::ContractABICodec abiCodec(cryptoSuite->hashImpl()); + bcos::bytes input; + if (contractAddress == DAG_TRANSFER_ADDRESS) + { + input = abiCodec.abiIn( + "userAdd(string,uint256)", std::to_string(it), bcos::u256(initialValue)); + } + else + { + input = abiCodec.abiIn( + "issue(address,int256)", bcos::Address(it), bcos::s256(initialValue)); + } + auto transaction = transactionFactory.createTransaction(0, contractAddress, input, + rpcClient.generateNonce(), blockNumber + blockLimit, "chain0", "group0", 0, + *keyPair); + transaction->setAttribute(bcos::protocol::Transaction::Attribute::EVM_ABI_CODEC | + bcos::protocol::Transaction::Attribute::DAG); + + handles[it].emplace(rpcClient); + auto& sendTransaction = *(handles[it]); + sendTransaction.setCallback(std::make_shared(latch, collector)); + sendTransaction.send(*transaction); + + collector.send(true, 0); + } + }); + collector.finishSend(); + latch.wait(); + collector.report(); + + // Check result + tbb::parallel_for(tbb::blocked_range(0LU, (size_t)userCount), [&](const auto& range) { + for (auto it = range.begin(); it != range.end(); ++it) + { + auto receipt = handles[it]->get(); + if (receipt->status() != 0) + { + std::cout << "Issue with error! " << receipt->status() << std::endl; + BOOST_THROW_EXCEPTION(std::runtime_error("Issue with error!")); + } + } + }); + + return 0; +} + +void perfQuery(bcos::sdk::RPCClient& rpcClient, + std::shared_ptr cryptoSuite, std::string contractAddress, + int userCount, int total, int qps) +{ + bcostars::protocol::TransactionFactoryImpl transactionFactory(cryptoSuite); + std::latch latch(total); + std::vector> handles(total); + + bcos::ratelimiter::TimeWindowRateLimiter limiter(qps); + bcos::sample::Collector collector(total, "Query"); + tbb::parallel_for(tbb::blocked_range(0LU, (size_t)total), [&](const auto& range) { + for (auto it = range.begin(); it != range.end(); ++it) + { + limiter.acquire(1); + auto userIndex = it % userCount; + bcos::codec::abi::ContractABICodec abiCodec(cryptoSuite->hashImpl()); + bcos::bytes input; + if (contractAddress == DAG_TRANSFER_ADDRESS) + { + input = abiCodec.abiIn("userBalance(string)", std::to_string(userIndex)); + } + else + { + input = abiCodec.abiIn("balance(address)", bcos::Address(userIndex)); + } + auto transaction = transactionFactory.createTransaction(0, contractAddress, input, + rpcClient.generateNonce(), blockNumber + blockLimit, "chain0", "group0", 0); + + handles[it].emplace(rpcClient); + auto& call = *(handles[it]); + call.setCallback(std::make_shared(latch, collector)); + call.send(*transaction); + + collector.send(true, 0); + } + }); + collector.finishSend(); + latch.wait(); + collector.report(); + + std::vector balances(userCount); + // Check result + tbb::parallel_for(tbb::blocked_range(0LU, (size_t)userCount), [&](const auto& range) { + for (auto it = range.begin(); it != range.end(); ++it) + { + auto receipt = handles[it]->get(); + if (receipt->status() != 0) + { + std::cout << "Query with error! " << receipt->status() << std::endl; + BOOST_THROW_EXCEPTION(std::runtime_error("Query with error!")); + } + + auto output = receipt->output(); + bcos::codec::abi::ContractABICodec abiCodec(cryptoSuite->hashImpl()); + bcos::s256 balance; + abiCodec.abiOut(output, balance); + + balances[it] = balance.convert_to(); + } + }); +} + + +void loopFetchBlockNumber(std::stop_token& token, bcos::sdk::RPCClient& rpcClient) +{ + while (!token.stop_requested()) + { + try + { + blockNumber = bcos::sdk::BlockNumber(rpcClient).send().get(); + } + catch (std::exception& e) + { + std::cout << boost::diagnostic_information(e); + } + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + } +} + +int main(int argc, char* argv[]) +{ + if (argc < 6) + { + std::cout + << "Usage: " << argv[0] + << " " + << std::endl + << "Example: " << argv[0] + << " \"fiscobcos.rpc.RPCObj@tcp -h 127.0.0.1 -p 20021\" 100 1000 0 " << std::endl; + + return 1; + } + std::string connectionString = argv[1]; + std::string type = argv[2]; + int userCount = boost::lexical_cast(argv[3]); + int transactionCount = boost::lexical_cast(argv[4]); + int qps = boost::lexical_cast(argv[5]); + + bcos::sdk::Config config = { + .connectionString = connectionString, + .sendQueueSize = std::max(userCount, transactionCount), + .timeoutMs = 600000, + }; + bcos::sdk::RPCClient rpcClient(config); + + auto cryptoSuite = + std::make_shared(std::make_shared(), + std::make_shared(), nullptr); + auto keyPair = std::shared_ptr( + cryptoSuite->signatureImpl()->generateKeyPair()); + + bcostars::protocol::TransactionFactoryImpl transactionFactory(cryptoSuite); + std::string contractAddress = DAG_TRANSFER_ADDRESS; + if (type == "solidity") + { + bcos::bytes deployBin = bcos::sample::getContractBin(); + auto deployTransaction = transactionFactory.createTransaction(0, "", deployBin, + rpcClient.generateNonce(), blockNumber + blockLimit, "chain0", "group0", 0, *keyPair, + std::string{bcos::sample::getContractABI()}); + auto receipt = bcos::sdk::SendTransaction(rpcClient).send(*deployTransaction).get(); + + if (receipt->status() != 0) + { + std::cout << "Deploy contract failed" << receipt->status() << std::endl; + return 1; + } + contractAddress = receipt->contractAddress(); + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + std::cout << "Contract address is:" << contractAddress << std::endl; + issue(rpcClient, cryptoSuite, keyPair, std::string(contractAddress), userCount, qps); + perfQuery( + rpcClient, cryptoSuite, std::string(contractAddress), userCount, transactionCount, qps); + + return 0; +} \ No newline at end of file diff --git a/bcos-storage/bcos-storage/RocksDBStorage.cpp b/bcos-storage/bcos-storage/RocksDBStorage.cpp index d40a814db9..aea91d6f2b 100644 --- a/bcos-storage/bcos-storage/RocksDBStorage.cpp +++ b/bcos-storage/bcos-storage/RocksDBStorage.cpp @@ -472,10 +472,10 @@ void RocksDBStorage::asyncCommit( m_db->GetProperty("rocksdb.cur-size-all-mem-tables", ¤t); STORAGE_ROCKSDB_LOG(INFO) << LOG_DESC("RocksDB statistics") << LOG_KV("blockNumber", params.number) - << LOG_KV( - "block_cache_usage", tableOptions->block_cache->GetUsage()) - << LOG_KV("block_cache_pinned_usage", - tableOptions->block_cache->GetPinnedUsage()) + // << LOG_KV( + // "block_cache_usage", tableOptions->block_cache->GetUsage()) + // << LOG_KV("block_cache_pinned_usage", + // tableOptions->block_cache->GetPinnedUsage()) << LOG_KV("estimate-table-readers-mem", out) << LOG_KV("cur-size-all-mem-tables", current); }