Skip to content
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

[Fix] Part-1 - LevelDbStore #3414

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

cschuchardt88
Copy link
Member

@cschuchardt88 cschuchardt88 commented Jul 8, 2024

Description

This fixes the store's dotnet memory management for GC, a long with adding new feature options, easier Exception catching.

Also exposes the store.
image

Change Log

  • Added more option features to ReadOptions, WriteOptions and Options.
  • Added LevelDBHandle.cs for GC and easy management.
  • Added IEnumerable<KeyValuePair<byte[], byte[]>> to Store.cs to Iterate over the whole store.
  • Changed namespace from Neo.IO.Data.LevelDB to Neo.IO.Storage.LevelDB
  • Added MaxOpenFiles=4096, SnappyCompression and FilterPolicy=10 option to Store.
  • Added code comments
  • Added thread-safety to batching since leveldb doesn't support multi-thread in batching.

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Unit tests

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@cschuchardt88 cschuchardt88 added the blocker Issues that are blocking other issues. Check issues details to see what it is blocking. label Jul 9, 2024
Copy link
Member

@vncoelho vncoelho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this PR be tested without PART 2?

@cschuchardt88
Copy link
Member Author

can this PR be tested without PART 2?

Yes

@Jim8y
Copy link
Contributor

Jim8y commented Jul 15, 2024

Hey Chris, can you please add a few UTs to demonstrate how your pr improves the leveldb? I am reviewing your code, but dont really clear how and where the improve works.

@cschuchardt88
Copy link
Member Author

cschuchardt88 commented Jul 16, 2024

Hey Chris, can you please add a few UTs to demonstrate how your pr improves the leveldb? I am reviewing your code, but dont really clear how and where the improve works.

Part-2 are the tests

@Jim8y
Copy link
Contributor

Jim8y commented Jul 16, 2024

Will check part 2 as well then, but please avoid doing this, cause it makes a single pr not reviewable.

@cschuchardt88
Copy link
Member Author

Will check part 2 as well then, but please avoid doing this, cause it makes a single pr not reviewable.

Just trying to make it small.

@cschuchardt88
Copy link
Member Author

Added thread-safety to batching since leveldb doesn't support multi-thread in batching.

@Jim8y
Copy link
Contributor

Jim8y commented Jul 30, 2024

@superboyiii can you please rake a look at this pr and do some tests on it?

@superboyiii
Copy link
Member

@superboyiii can you please rake a look at this pr and do some tests on it?

Sure

@superboyiii
Copy link
Member

@cschuchardt88 Seems not an issue from this PR because it occurs on master in block 2724677, I will open an issue.
1722997794683

@cschuchardt88
Copy link
Member Author

@superboyiii Is your testing finished for this PR? are we good to move forward?

@superboyiii
Copy link
Member

superboyiii commented Aug 28, 2024

@superboyiii Is your testing finished for this PR? are we good to move forward?

I've tried functional tests and compatiblity tests before, all seems works well. But not sure how to test GC performance. Do you have any good way or suggestion?

@cschuchardt88
Copy link
Member Author

cschuchardt88 commented Sep 1, 2024

@superboyiii Is your testing finished for this PR? are we good to move forward?

I've tried functional tests and compatiblity tests before, all seems works well. But not sure how to test GC performance. Do you have any good way or suggestion?

GC is an automated thing built into dotnet, that picks up stuff that is unallocated. At least now it handled better. So the GC doesn't removes anything that we are using in unmanaged state. If we were using huge chunks of data, we could measure it. But the data we handle is so small, nothing to measure. It's only Pointers we are talking about.

@superboyiii
Copy link
Member

superboyiii commented Sep 2, 2024

GC is an automated thing built into dotnet, that picks up stuff that is unallocated. At least now it handled better. So the GC doesn't removes anything that we are using in unmanaged state. If we were using huge chunks of data, we could measure it. But the data we handle is so small, nothing to measure. It's only Pointers we are talking about.

Will this improvement make memory increase less when node is running?

@cschuchardt88
Copy link
Member Author

cschuchardt88 commented Sep 2, 2024

GC is an automated thing built into dotnet, that picks up stuff that is unallocated. At least now it handled better. So the GC doesn't removes anything that we are using in unmanaged state. If we were using huge chunks of data, we could measure it. But the data we handle is so small, nothing to measure. It's only Pointers we are talking about.

Will this improvement make memory increase less when node is running?

No memory will be the same. Just won't get un-allocated randomly by GC. In other words the GC knows what it is.

Can pick in Performance Profiler In Visual Studio 2022
image

Copy link
Member

@superboyiii superboyiii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with #3415, seems works well and data is compatible. Memory usage is stable.

// at lease up to block index 10_000_000
MaxOpenFiles = 4096,
FilterPolicy = 10,
CompressionLevel = CompressionType.SnappyCompression,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was the previous value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateIfMissing = true,
FilterPolicy = Native.leveldb_filterpolicy_create_bloom(15)

CompressionLevel is enabled by default in leveldb

}

public void Put(byte[] key, byte[] value)
{
batch.Put(key, value);
lock (_lock)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jim8y already introduced something to ensure that is not used in non-thread safe cases

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still best to do this. All of leveldb is thread safe, except writebatch, isn't thread safe. Better to do it at the source. You can use leveldb in multi-threads. Just not writebatch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker Issues that are blocking other issues. Check issues details to see what it is blocking. Plugins waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants