-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor OperationIndex to reducee nubmer of database transactions * Some docs * Do the same for BigMapIndex * Docs * Changelog * Fix index state not being updated * Refactor index module * Fix fire_handler calls * Fix changelog * Lint * `LazyOperationFetcher` helper 🤔 * Test utils index matcher benchmark
- Loading branch information
1 parent
5b2ba98
commit 17f8699
Showing
7 changed files
with
199 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
cp tests/benchmarks/config.latest.json tests/benchmarks/config.json | ||
cp tests/benchmarks/config.latest.json tests/benchmarks/config.json | ||
cp tests/benchmarks/index.latest.json tests/benchmarks/index.json |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
rm tests/benchmarks/config.latest.json | ||
python tests/benchmarks/config.py -o tests/benchmarks/config.latest.json | ||
python -m pyperf compare_to --table tests/benchmarks/config.json tests/benchmarks/config.latest.json | ||
for i in config index; do | ||
rm tests/benchmarks/$i.latest.json; | ||
python tests/benchmarks/$i.py -o tests/benchmarks/$i.latest.json; | ||
python -m pyperf compare_to --table tests/benchmarks/$i.json tests/benchmarks/$i.latest.json; | ||
done; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import logging | ||
from collections import deque | ||
from contextlib import contextmanager | ||
from typing import AsyncGenerator, Deque, Iterator, Tuple | ||
from unittest.mock import patch | ||
|
||
from dipdup.datasources.tzkt.datasource import OperationFetcher | ||
from dipdup.index import OperationIndex | ||
from dipdup.models import OperationData | ||
|
||
logging.basicConfig(level=logging.ERROR) | ||
|
||
|
||
# NOTE: Not an actual fuzzer :) | ||
class OperationFetcherFuzzer(OperationFetcher): | ||
"""This thing is lazy, so instead of fetching all operations it returns the same data over and over again.""" | ||
|
||
levels: int | ||
repeats: int | ||
|
||
def __new__(cls, *a, **kw): | ||
super().__new__(cls, *a, **kw) | ||
cls.levels = 100 | ||
cls.repeats = 100 | ||
|
||
async def fetch_operations_by_level(self) -> AsyncGenerator[Tuple[int, Tuple[OperationData, ...]], None]: | ||
self._datasource._http._config.batch_size = 1000 | ||
level_operations: Deque[Tuple[int, Tuple[OperationData, ...]]] = deque() | ||
async for level, operations in super().fetch_operations_by_level(): | ||
level_operations.append((level, operations)) | ||
if len(level_operations) >= self.levels: | ||
break | ||
|
||
for _ in range(self.repeats): | ||
for level, operations in level_operations: | ||
yield level, operations | ||
|
||
|
||
class OperationIndexFuzzer(OperationIndex): | ||
async def _process_level_operations(self, operations: Tuple[OperationData, ...]) -> None: | ||
await self._match_operations(operations) | ||
|
||
|
||
@contextmanager | ||
def with_operation_fetcher_fuzzer(levels=100, repeats=100) -> Iterator[None]: | ||
OperationFetcherFuzzer.levels = levels | ||
OperationFetcherFuzzer.repeats = repeats | ||
with patch('dipdup.datasources.tzkt.datasource.OperationFetcher', OperationFetcherFuzzer): | ||
yield | ||
|
||
|
||
@contextmanager | ||
def with_operation_index_fuzzer(levels=100, repeats=100) -> Iterator[None]: | ||
with with_operation_fetcher_fuzzer(levels=levels, repeats=repeats): | ||
with patch('dipdup.index.OperationIndex', OperationIndexFuzzer): | ||
yield |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import asyncio | ||
from contextlib import suppress | ||
from os.path import dirname, join | ||
|
||
import pyperf # type: ignore | ||
|
||
from dipdup.config import DipDupConfig | ||
from dipdup.dipdup import DipDup | ||
from dipdup.exceptions import ReindexingRequiredError | ||
from dipdup.test import with_operation_index_fuzzer | ||
|
||
|
||
def add_cmdline_args(cmd, args): | ||
cmd += ['--quiet'] | ||
|
||
|
||
runner = pyperf.Runner(add_cmdline_args=add_cmdline_args) | ||
|
||
|
||
paths = [ | ||
join(dirname(__file__), '..', 'integration_tests', name) | ||
for name in [ | ||
'hic_et_nunc.yml', | ||
] | ||
] | ||
|
||
|
||
async def _match(): | ||
for path in paths: | ||
config = DipDupConfig.load([path]) | ||
config.database.path = ':memory:' | ||
config.initialize() | ||
|
||
with with_operation_index_fuzzer(10, 3): | ||
dipdup = DipDup(config) | ||
with suppress(ReindexingRequiredError): | ||
await dipdup.run(True, True) | ||
|
||
|
||
runner.bench_func('index_match_operations', lambda: asyncio.run(_match())) |