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

Improve buffer usage across bolt & packstream classes #224

Merged
merged 2 commits into from
Aug 22, 2017

Conversation

ali-ince
Copy link
Contributor

  1. Introduced Buffer related settings into the configuration,
  2. Dropped MemoryStream from ChunkReader and started to use a fix sized buffer,
  3. Dropped MemoryStream from BoltWriter,
  4. Reset MemoryStream capacity to default buffer size after consuming or sending messages in BoltReader and ChunkWriter classes.

@zhenlineo
Copy link
Contributor

Looks okay, but would like to hear more input from @lutovich

if (_currentChunkSize == -1 && HasBytesAvailable(_chunkSizeBuffer.Length))
{
ReadFromChunkStream(_chunkSizeBuffer, 0, _chunkSizeBuffer.Length);
ReadFromBuffer(_chunkSizeBuffer, 0, _chunkSizeBuffer.Length);
Copy link
Contributor

Choose a reason for hiding this comment

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

This method is only used for reading chunk size, maybe we could just move all logic of reading size header into the same method and rename it as ReadChunkSize()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

CopyToFromChunkStream(targetStream, _currentChunkSize);
var count = Math.Min(_currentChunkSize, _lastWritePosition - _lastReadPosition);

CopyFromBuffer(targetStream, count);
Copy link
Contributor

Choose a reason for hiding this comment

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

Will it be a good idea if we rename targetStream to messageStream/dechunkedStream and downStream to networkStream?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed targetStream to messageStream but did not touch downStream as it may not be networkStream which we're dealing with.

_lastWritePosition += read;

// Can we read a whole message from what we have?
if (TryReadFromBuffer(targetStream))
Copy link
Contributor

Choose a reason for hiding this comment

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

TryReadOneCompleteMessage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed to TryReadOneCompleteMessageFromBuffer.

@zhenlineo
Copy link
Contributor

Reviewed with @lutovich, I got a few naming suggestions. He got the question if it is needed to expose the defaultReadBufferSize, MaxReadBufferSize and the same for writer exposed in Config? Shall we first hides it from users as it might be really hard to config them correctly by an end-user.

  1. Introduced Buffer related settings into the configuration,
  2. Dropped MemoryStream from ChunkReader and started to use a fix sized buffer,
  3. Dropped MemoryStream from BoltWriter,
  4. Reset MemoryStream capacity to default buffer size after consuming or sending messages in BoltReader and ChunkWriter classes.
@ali-ince
Copy link
Contributor Author

ali-ince commented Aug 21, 2017

Regarding config options, there are defaults set and unless the user does not have any specific needs (very large reads or very large writes) we do not expect them to set those config options. For me it is better to have config options with suitable defaults and let the user change them upon any requirement. We may discuss further if needed.

@zhenlineo zhenlineo merged commit ee06346 into neo4j:1.5 Aug 22, 2017
@ali-ince ali-ince deleted the 1.5-improve-buffer-usage branch September 1, 2017 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants