-
Notifications
You must be signed in to change notification settings - Fork 345
draft: File ID Manager base implementation #921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9da7b46
add FileIdManager class and assoc. tests
dlqqq 86fcaf3
integrate FileIdManager into ContentsManager implementations
dlqqq 39998d7
support out-of-band operations for FID.index/get_id
dlqqq 6a5b24d
handle disjoint moves in move() method
dlqqq c98e5b6
fix recursive move()
dlqqq 57a19a7
handle edge case of creating new file at an empty but prev indexed path
dlqqq 4e60209
detect oob moves in get_path()
dlqqq 695de46
minimize transactions by restricting usage to public methods in FIM
dlqqq bea8dd4
optimize _index_all() to not commit transactions
dlqqq 56b7668
fix get path following oob recursive move
dlqqq 12e12b5
only index new directories in _scan_dir()
dlqqq 7ff6cb9
prefer _stat() over DirEntry.stat() for windows support
dlqqq 7b97de8
verify file existence in get_path()
dlqqq 8da5648
do not accept *args in __init__()
dlqqq fb8cc40
greatly simplify syncing of indexed-but-moved dirs
dlqqq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import os | ||
import timeit | ||
|
||
from jupyter_core.paths import jupyter_data_dir | ||
|
||
from jupyter_server.services.contents.fileidmanager import FileIdManager | ||
|
||
db_path = os.path.join(jupyter_data_dir(), "file_id_manager_perftest.db") | ||
|
||
|
||
def build_setup(n, insert=True): | ||
def setup(): | ||
try: | ||
os.remove(db_path) | ||
except: | ||
pass | ||
fid_manager = FileIdManager(db_path=db_path) | ||
|
||
if not insert: | ||
return | ||
|
||
for i in range(n): | ||
fid_manager.con.execute( | ||
"INSERT INTO Files (path) VALUES (?)", (f"abracadabra/{i}.txt",) | ||
) | ||
fid_manager.con.commit() | ||
|
||
return setup | ||
|
||
|
||
BATCH_SIZE = 100_000 | ||
|
||
|
||
def build_test_index(n, single_transaction, batched=False): | ||
def test_index(): | ||
fid_manager = FileIdManager(db_path=db_path) | ||
|
||
if single_transaction: | ||
if batched: | ||
for batch_start in range(0, n, BATCH_SIZE): | ||
batch_end = batch_start + BATCH_SIZE | ||
fid_manager.con.execute( | ||
"INSERT INTO FILES (path) VALUES " | ||
+ ",".join( | ||
[f'("abracadabra/{i}.txt")' for i in range(batch_start, batch_end)] | ||
) | ||
) | ||
else: | ||
for i in range(n): | ||
fid_manager.con.execute( | ||
"INSERT INTO Files (path) VALUES (?)", (f"abracadabra/{i}.txt",) | ||
) | ||
|
||
fid_manager.con.commit() | ||
else: | ||
for i in range(n): | ||
fid_manager.index(f"abracadabra/{i}.txt") | ||
|
||
return test_index | ||
|
||
|
||
def test_copy(): | ||
fid_manager = FileIdManager(db_path=db_path) | ||
fid_manager.copy("abracadabra", "shazam", recursive=True) | ||
|
||
|
||
def test_move(): | ||
fid_manager = FileIdManager(db_path=db_path) | ||
fid_manager.move("abracadabra", "shazam", recursive=True) | ||
|
||
|
||
def test_delete(): | ||
fid_manager = FileIdManager(db_path=db_path) | ||
fid_manager.delete("abracadabra", recursive=True) | ||
|
||
|
||
row_template = "{:<9,d} files | {:<8.4f} s" | ||
|
||
|
||
# too slow for 1k+ | ||
print("Index benchmark (separate transactions)") | ||
for i in [100, 1_000]: | ||
print( | ||
row_template.format( | ||
i, | ||
timeit.timeit( | ||
build_test_index(i, single_transaction=False), | ||
build_setup(i, insert=False), | ||
number=1, | ||
), | ||
) | ||
) | ||
|
||
print("Index benchmark (single transaction, atomic INSERTs)") | ||
for i in [100, 1_000, 10_000, 100_000, 1_000_000]: | ||
print( | ||
row_template.format( | ||
i, | ||
timeit.timeit( | ||
build_test_index(i, single_transaction=True, batched=False), | ||
build_setup(i, insert=False), | ||
number=1, | ||
), | ||
) | ||
) | ||
|
||
# suggested by https://stackoverflow.com/a/72527058/12548458 | ||
# asymptotically faster because it reduces work being done by the SQLite VDBE https://www.sqlite.org/opcode.html | ||
# weird constant time factor that makes it sub-optimal for <1M records. | ||
print("Index benchmark (single transaction, batched INSERTs)") | ||
for i in [100, 1_000, 10_000, 100_000, 1_000_000]: | ||
print( | ||
row_template.format( | ||
i, | ||
timeit.timeit( | ||
build_test_index(i, single_transaction=True, batched=True), | ||
build_setup(i, insert=False), | ||
number=1, | ||
), | ||
) | ||
) | ||
|
||
print("Recursive move benchmark") | ||
for i in [100, 1_000, 10_000, 100_000, 1_000_000]: | ||
print(row_template.format(i, timeit.timeit(test_move, build_setup(i), number=1))) | ||
|
||
print("Recursive copy benchmark") | ||
for i in [100, 1_000, 10_000, 100_000, 1_000_000]: | ||
print(row_template.format(i, timeit.timeit(test_copy, build_setup(i), number=1))) | ||
|
||
print("Recursive delete benchmark") | ||
for i in [100, 1_000, 10_000, 100_000, 1_000_000]: | ||
print(row_template.format(i, timeit.timeit(test_delete, build_setup(i), number=1))) |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.