Last active
August 21, 2018 02:24
-
-
Save luchenqun/513f2c84a309cf34cf5b8b3fe6de2fd7 to your computer and use it in GitHub Desktop.
eth_getTransactionReceipt 压测
This file contains hidden or 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
| Json::Value Eth::eth_getTransactionByHash(string const& _transactionHash) | |
| { | |
| static int count = 0; | |
| static int totalSpend = 0; | |
| try | |
| { | |
| h256 h = jsToFixed<32>(_transactionHash); | |
| std::chrono:: steady_clock :: time_point t1 = std::chrono:: steady_clock ::now(); | |
| bool ret = client()->isKnownTransaction(h); | |
| std::chrono:: steady_clock :: time_point t2 = std::chrono:: steady_clock ::now(); | |
| int curSpend = std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count(); | |
| totalSpend += curSpend; | |
| count++; | |
| cinfo << "curSpend " << curSpend << " us, perSpend " << totalSpend / count << " us"; | |
| if (!ret) | |
| return Json::Value(Json::nullValue); | |
| return toJson(client()->localisedTransaction(h)); | |
| } | |
| catch (...) | |
| { | |
| BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); | |
| } | |
| } |
This file contains hidden or 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
| const axios = require("axios"); | |
| const hostname = "http://192.168.37.131:6789"; | |
| const http = axios.create({ | |
| baseURL: hostname | |
| }); | |
| var eth_getTransactionReceipt = { | |
| jsonrpc: "2.0", | |
| id: 0, | |
| method: "eth_getTransactionByHash", | |
| params: ["0x0e2335166d46a1b7ad82ca83856c78fddbe1343983ca29bf0022d53311d2f2af"] | |
| }; | |
| async function request() { | |
| this.replay = ""; | |
| for (let i = 0; i <= 100000; i++) { | |
| try { | |
| eth_getTransactionReceipt.id = i; | |
| let replay = await http.post("", eth_getTransactionReceipt); | |
| if (replay.status === 200 && (i % 1000 === 0)) { | |
| console.log("i =", i); | |
| } | |
| } catch (error) { | |
| console.log("error = ", error); | |
| break; | |
| } | |
| } | |
| } | |
| request(); |
This file contains hidden or 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
| [2018-08-21 10:20:29:676][p:101588/t:101608]jueth_log:INFO >>[MHD-single] [Eth.cpp:489:eth_getTransactionByHash] curSpend 3 us, perSpend 2 us | |
| [2018-08-21 10:20:29:676][p:101588/t:101608]jueth_log:DEBUG>>[MHD-single] [JuHttpServer.cpp:304:callback] JuHttpServer response DATA: {"id":100000,"jsonrpc":"2.0","result":{"blockHash":"0x49ef6fc0340a210255420870f8661ee02f4ec3af743d10309cebaec3de96d95c","blockNumber":"0x16","from":"0x2a950a66df1071bd3c4d9e7c7e4e6f3993742184","gas":"0xe8d4a50fff","gasPrice":"0x174876e800","hash":"0x0e2335166d46a1b7ad82ca83856c78fddbe1343983ca29bf0022d53311d2f2af","input":"0x60fe47b10000000000000000000000000000000000000000000000000000000000ffffff","nonce":"0x165573914575b8a7dcb6196a5a832cffa71a4a59bd21300b0cda3717450","to":"0xd840de56a0138692263b476ba141a8fe68592400","transactionIndex":"0x0","value":"0x0"}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment