ApeWorX / ApeWorX/web3.py

causes of sudden changes in consumption time

Open
#2,388 4 comments 0 reactions 0 assignees View on GitHub
performance priority: p2 normal
Dominant language
Python
Stars
5.5k
Forks
1.7k
Avg merge
3d 10h
Merged PRs (30d)
2

Description

* Version: 5.17.0
* Python: 3.7
* OS: linux

## output
```
100%|██████████| 500/500 [04:41<00:00, 1.77it/s]
total time cost 281.79
```
![image](https://user-images.githubusercontent.com/19996579/157832765-d8d38368-cd52-406c-bdc0-0adff7876835.png)

### What was wrong?

* The code which produced the problem
```python
from web3 import Web3
from tqdm import tqdm

WSADDRESS = 'ws://xxx.xx.xxx.xx:8545'
w3 = Web3(Web3.WebsocketProvider(WSADDRESS, websocket_timeout=60))

address = "0xa8f9c7ff9f605f401bde6659fd18d9a0d0a802c5"
sample_txs = sampling_transactions(address, use_sampling=True, sample_count=500) # sample first 500 transactions

# caller_tracer.js is from https://github.com/ethereum/go-ethereum/blob/master/eth/tracers/js/internal/tracers/call_tracer_legacy.js
with open('./caller_tracer.js', 'r') as f:
callTracer = f.read()

def trace_transaction(tx):
return w3.provider.make_request('debug_traceTransaction', [
tx,
{
'tracer': callTracer,
'timeout': '60000s'
}
])

time_used = []
ts = time.time()
for tx in tqdm(sample_txs):
s = time.time()
trace_transaction(tx['transaction_hash'])
e = time.time()
time_used.append(e-s)
te = time.time()
print("total time cost %.2f"%(te-ts))

# draw transaction index vs time_used
# draw transaction index vs accumulated time
```

* What type of node you were connecting to.
A node on a different computer (full sync), so I have to use Websockets.

**I want to know the reason and how to fix it, thanks a lot**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.