Skip to content

Commit d05b6db

Browse files
committed
Add profiling for sync.
1 parent fb79fc5 commit d05b6db

File tree

7 files changed

+1329
-15
lines changed

7 files changed

+1329
-15
lines changed

gel/_internal/_save.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,7 @@ def make_save_executor_constructor(
10741074
refetch: bool,
10751075
warn_on_large_sync_set: bool = False,
10761076
save_postcheck: bool = False,
1077+
executor_type: type,
10771078
) -> Callable[[], SaveExecutor]:
10781079
(
10791080
create_batches,
@@ -1085,7 +1086,7 @@ def make_save_executor_constructor(
10851086
refetch=refetch,
10861087
warn_on_large_sync_set=warn_on_large_sync_set,
10871088
)
1088-
return lambda: SaveExecutor(
1089+
return lambda: executor_type(
10891090
objs=objs,
10901091
create_batches=create_batches,
10911092
updates=updates,

gel/_testbase.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,17 +479,21 @@ def make_test_client(
479479
if cls.is_client_async
480480
else blocking_client.BlockingIOConnection
481481
)
482-
client_class = (
483-
TestAsyncIOClient
484-
if issubclass(connection_class, asyncio_client.AsyncIOConnection)
485-
else TestClient
486-
)
482+
client_class = cls._get_client_class(connection_class)
487483
return client_class(
488484
connection_class=connection_class,
489485
max_concurrency=1,
490486
**conargs,
491487
)
492488

489+
@classmethod
490+
def _get_client_class(cls, connection_class):
491+
return (
492+
TestAsyncIOClient
493+
if issubclass(connection_class, asyncio_client.AsyncIOConnection)
494+
else TestClient
495+
)
496+
493497
@classmethod
494498
def get_connect_args(
495499
cls, *, cluster=None, database="edgedb", user="edgedb", password="test"

gel/asyncio_client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from .protocol import asyncio_proto # type: ignore [attr-defined, unused-ignore]
3838
from .protocol.protocol import InputLanguage, OutputFormat
3939

40-
from ._internal._save import make_save_executor_constructor
40+
from ._internal._save import make_save_executor_constructor, SaveExecutor
4141

4242
if typing.TYPE_CHECKING:
4343
from ._internal._qbmodel._pydantic import GelModel
@@ -600,6 +600,7 @@ class AsyncIOClient(
600600

601601
__slots__ = ()
602602
_impl_class = _AsyncIOPoolImpl
603+
_save_executor_type = SaveExecutor
603604

604605
async def check_connection(self) -> base_client.ConnectionInfo:
605606
return await self._impl.ensure_connected()
@@ -647,6 +648,7 @@ async def _save_impl(
647648
refetch=refetch,
648649
save_postcheck=opts.save_postcheck,
649650
warn_on_large_sync_set=warn_on_large_sync_set,
651+
executor_type=self._save_executor_type,
650652
)
651653

652654
async for tx in self._batch():

gel/blocking_client.py

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@
3939
from .protocol import blocking_proto # type: ignore [attr-defined, unused-ignore]
4040
from .protocol.protocol import InputLanguage, OutputFormat
4141

42-
from ._internal._save import make_save_executor_constructor
42+
from ._internal._save import (
43+
QueryBatch,
44+
QueryRefetch,
45+
SaveExecutor,
46+
make_save_executor_constructor,
47+
)
4348

4449
if typing.TYPE_CHECKING:
4550
from ._internal._qbmodel._pydantic import GelModel
@@ -651,6 +656,7 @@ class Client(
651656

652657
__slots__ = ()
653658
_impl_class = _PoolImpl
659+
_save_executor_type = SaveExecutor
654660

655661
def _save_impl(
656662
self,
@@ -659,12 +665,9 @@ def _save_impl(
659665
objs: tuple[GelModel, ...],
660666
warn_on_large_sync_set: bool = False,
661667
) -> None:
662-
opts = self._get_debug_options()
663-
664-
make_executor = make_save_executor_constructor(
665-
objs,
668+
make_executor = self._get_make_save_executor(
666669
refetch=refetch,
667-
save_postcheck=opts.save_postcheck,
670+
objs=objs,
668671
warn_on_large_sync_set=warn_on_large_sync_set,
669672
)
670673

@@ -675,22 +678,53 @@ def _save_impl(
675678
with executor:
676679
for batches in executor:
677680
for batch in batches:
678-
tx.send_query(batch.query, batch.args)
681+
self._send_batch_query(tx, batch)
679682
batch_ids = tx.wait()
680683
for ids, batch in zip(batch_ids, batches, strict=True):
681684
batch.feed_db_data(ids)
682685

683686
if refetch:
684687
ref_queries = executor.get_refetch_queries()
685688
for ref in ref_queries:
686-
tx.send_query(ref.query, **ref.args)
689+
self._send_refetch_query(tx, ref)
687690

688691
refetch_data = tx.wait()
689692
for ref_data, ref in zip(
690693
refetch_data, ref_queries, strict=True
691694
):
692695
ref.feed_db_data(ref_data)
693696

697+
def _get_make_save_executor(
698+
self,
699+
*,
700+
refetch: bool,
701+
objs: tuple[GelModel, ...],
702+
warn_on_large_sync_set: bool = False,
703+
) -> typing.Callable[[], SaveExecutor]:
704+
opts = self._get_debug_options()
705+
706+
return make_save_executor_constructor(
707+
objs,
708+
refetch=refetch,
709+
save_postcheck=opts.save_postcheck,
710+
warn_on_large_sync_set=warn_on_large_sync_set,
711+
executor_type=self._save_executor_type,
712+
)
713+
714+
def _send_batch_query(
715+
self,
716+
tx: BatchIteration,
717+
batch: QueryBatch,
718+
) -> None:
719+
tx.send_query(batch.query, batch.args)
720+
721+
def _send_refetch_query(
722+
self,
723+
tx: BatchIteration,
724+
ref: QueryRefetch,
725+
) -> None:
726+
tx.send_query(ref.query, **ref.args)
727+
694728
def save(
695729
self,
696730
*objs: GelModel,
@@ -718,6 +752,7 @@ def __debug_save__(self, *objs: GelModel) -> SaveDebug:
718752
make_executor = make_save_executor_constructor(
719753
objs,
720754
refetch=False, # TODO
755+
executor_type=self._save_executor_type,
721756
)
722757
plan_time = time.monotonic_ns() - ns
723758

tests/dbsetup/chemistry.esdl

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
INSERT Element {
2+
name := 'Hydrogen',
3+
symbol := 'H',
4+
number := 1,
5+
valence := 1,
6+
weight := 1.0080,
7+
};
8+
INSERT Element {
9+
name := 'Helium',
10+
symbol := 'He',
11+
number := 2,
12+
valence := 0,
13+
weight := 4.0026,
14+
};
15+
INSERT Element {
16+
name := 'Lithium',
17+
symbol := 'Li',
18+
number := 3,
19+
valence := 1,
20+
weight := 6.94,
21+
};
22+
INSERT Element {
23+
name := 'Beryllium',
24+
symbol := 'Be',
25+
number := 4,
26+
valence := 2,
27+
weight := 9.0122,
28+
};
29+
INSERT Element {
30+
name := 'Boron',
31+
symbol := 'B',
32+
number := 5,
33+
valence := 3,
34+
weight := 10.81,
35+
};
36+
INSERT Element {
37+
name := 'Carbon',
38+
symbol := 'C',
39+
number := 6,
40+
valence := 4,
41+
weight := 12.011,
42+
};
43+
INSERT Element {
44+
name := 'Nitrogen',
45+
symbol := 'N',
46+
number := 7,
47+
valence := 5,
48+
weight := 14.007,
49+
};
50+
INSERT Element {
51+
name := 'Oxygen',
52+
symbol := 'O',
53+
number := 8,
54+
valence := 6,
55+
weight := 15.999,
56+
};
57+
INSERT Element {
58+
name := 'Fluorine',
59+
symbol := 'F',
60+
number := 9,
61+
valence := 7,
62+
weight := 18.998,
63+
};
64+
INSERT Element {
65+
name := 'Neon',
66+
symbol := 'Ne',
67+
number := 10,
68+
valence := 0,
69+
weight := 20.180,
70+
};

tests/dbsetup/chemistry.gel

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
module default {
2+
type Named {
3+
required name: std::str;
4+
};
5+
6+
type Element extending Named {
7+
required symbol: str;
8+
required number: int64;
9+
required valence: int64;
10+
required weight: float64;
11+
};
12+
13+
# We do this for now, since self multi links aren't well supported
14+
type BaseAtom {
15+
# Single link no props
16+
required element: Element;
17+
18+
# Computed single prop
19+
weight := sum(.element.weight);
20+
};
21+
22+
type RefAtom extending BaseAtom {
23+
# Multi link with props
24+
multi bonds: BaseAtom {
25+
count: int64;
26+
}
27+
28+
# Computed single link
29+
compound := .<atoms[is Compound];
30+
};
31+
32+
type Compound extending Named {
33+
# Multi link no props
34+
required multi atoms: RefAtom;
35+
36+
# Multi prop
37+
multi alternate_names: str;
38+
};
39+
40+
type Reactor {
41+
# Computed multi link
42+
multi atoms := .<reactor[is Atom];
43+
44+
# Computed single prop
45+
total_weight := sum(.atoms.element.weight);
46+
# Computed multi prop
47+
atom_weights := .atoms.element.weight;
48+
};
49+
50+
type Atom extending BaseAtom {
51+
# Multi link with props
52+
multi bonds: BaseAtom {
53+
count: int64;
54+
}
55+
56+
# Single link with props
57+
required reactor: Reactor;
58+
59+
# Computed single prop using link props
60+
total_bond_count := sum(.bonds@count);
61+
total_bond_weight := sum(.bonds.weight);
62+
};
63+
}

0 commit comments

Comments
 (0)