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 mutation_data write_to/read_from #499

Merged
merged 1 commit into from
Jul 29, 2016
Merged

improve mutation_data write_to/read_from #499

merged 1 commit into from
Jul 29, 2016

Conversation

qinzuoyan
Copy link
Collaborator

improvement:

  • write task_code as string to make it cross-process compatible
  • directly append blob to message_ex to avoid unnecessary memory copy

writer.write(update.data.data(), update.data.length());
writer.flush();

message_ex* msg = (message_ex*)to;
Copy link
Owner

@imzhenyu imzhenyu Jul 29, 2016

Choose a reason for hiding this comment

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

message_ex is not exposed to upper apps and frameworks, which only invokes the core features through C api (and upper wrappers).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It there any solution about it? I think the optimization is meaningful.

On Fri, Jul 29, 2016 at 2:17 PM, Zhenyu Guo [email protected]
wrote:

In src/dist/replication/lib/mutation.cpp
#499 (comment):

 {
  •    writer.write(update.data.data(), update.data.length());
    
  •    writer.flush();
    
  •    message_ex\* msg = (message_ex*)to;
    

message_ex is not exposed to upper apps and frameworks, which invokes the
core features through C api eventually.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/imzhenyu/rDSN/pull/499/files/4ed36f13e7f75d282315ba8284d1003944ed1b93#r72745993,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAgQPZD6Maf_qEDZxotGoJcPMwibGYVWks5qaZsPgaJpZM4JX4Dq
.

Copy link
Owner

@imzhenyu imzhenyu Jul 29, 2016

Choose a reason for hiding this comment

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

you may add a new dsn_msg_write_append C api which requires the callers to manage the buffer life-time correctly.

@qinzuoyan qinzuoyan changed the title improve mutation_data write_to/read_from, write task_code as string improve mutation_data write_to/read_from Jul 29, 2016
@qinzuoyan
Copy link
Collaborator Author

@imzhenyu , I have added a c-api of "dsn_msg_write_append", please review it.

@@ -785,6 +785,9 @@ extern DSN_API void dsn_msg_write_next(
/*! commit the write buffer after the message content is written with the real written size */
extern DSN_API void dsn_msg_write_commit(dsn_message_t msg, size_t size);

/*! append a buffer to the message, the "data" can be reinterpreted cast to (blob*) */
extern DSN_API void dsn_msg_write_append(dsn_message_t msg, dsn_blob_t data);
Copy link
Owner

Choose a reason for hiding this comment

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

dsn_blob_t is not a POD or C structure, therefore we cannot put it in this C API. May use (dsn_message_t, void*, size_t) instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

but then we lost the holder of blob, or just copy data?

On Fri, Jul 29, 2016 at 4:08 PM, Zhenyu Guo [email protected]
wrote:

In include/dsn/c/api_layer1.h
#499 (comment):

@@ -785,6 +785,9 @@ extern DSN_API void dsn_msg_write_next(
/*! commit the write buffer after the message content is written with the real written size */
extern DSN_API void dsn_msg_write_commit(dsn_message_t msg, size_t size);

+/! append a buffer to the message, the "data" can be reinterpreted cast to (blob) */
+extern DSN_API void dsn_msg_write_append(dsn_message_t msg, dsn_blob_t data);

dsn_blob_t is not a POD or C structure, therefore we cannot put it in this
C API. May use (dsn_message_t, void*, size_t) instead.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/imzhenyu/rDSN/pull/499/files/ea230134983ab865c8bb7b6e2110776c7d14b9ac#r72755516,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAgQPejEDsHaGiYDGDrmUtjSEcIL9P7Dks5qabUTgaJpZM4JX4Dq
.

Copy link
Owner

@imzhenyu imzhenyu Jul 29, 2016

Choose a reason for hiding this comment

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

The caller needs to guarantee the life-time; or we have to copy data.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The holder is a shared_ptr, so the life-time seems unable to handle.... can
you think out some resolution to avoid memory copy?

On Fri, Jul 29, 2016 at 4:44 PM, Zhenyu Guo [email protected]
wrote:

In include/dsn/c/api_layer1.h
#499 (comment):

@@ -785,6 +785,9 @@ extern DSN_API void dsn_msg_write_next(
/*! commit the write buffer after the message content is written with the real written size */
extern DSN_API void dsn_msg_write_commit(dsn_message_t msg, size_t size);

+/! append a buffer to the message, the "data" can be reinterpreted cast to (blob) */
+extern DSN_API void dsn_msg_write_append(dsn_message_t msg, dsn_blob_t data);

The caller needs to handle the life-time explicitly; or we have to copy
data.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/imzhenyu/rDSN/pull/499/files/ea230134983ab865c8bb7b6e2110776c7d14b9ac#r72759513,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAgQPXyekSSBRkBBDcDa5ne71m3UAcGTks5qab1wgaJpZM4JX4Dq
.

Copy link
Owner

Choose a reason for hiding this comment

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

This is what is ugly about C interface, unfortunately. That is why in certain cases I would prefere ref_counter or instrusive ptr instead of shared-ptr:-( I'll think about this though to see how we can enable this more elegantly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

well, now I will discard the optimization and leave it to future.

On Fri, Jul 29, 2016 at 5:31 PM, Zhenyu Guo [email protected]
wrote:

In include/dsn/c/api_layer1.h
#499 (comment):

@@ -785,6 +785,9 @@ extern DSN_API void dsn_msg_write_next(
/*! commit the write buffer after the message content is written with the real written size */
extern DSN_API void dsn_msg_write_commit(dsn_message_t msg, size_t size);

+/! append a buffer to the message, the "data" can be reinterpreted cast to (blob) */
+extern DSN_API void dsn_msg_write_append(dsn_message_t msg, dsn_blob_t data);

This is what is ugly about C interface, unfortunately. That is why in
certain cases I would prefere ref_counter or instrusive ptr instead of
shared-ptr:-( I'll think about this though to see how we can enable this
more elegantly.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/imzhenyu/rDSN/pull/499/files/ea230134983ab865c8bb7b6e2110776c7d14b9ac#r72765645,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAgQPbwWAMkLxrIkYmRDBcyBPWZX73lbks5qach4gaJpZM4JX4Dq
.

Copy link
Owner

Choose a reason for hiding this comment

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

ok.

@qinzuoyan
Copy link
Collaborator Author

we leave optimization of "directly append blob to message_ex to avoid unnecessary memory copy" to future, refer to #501

@qinzuoyan
Copy link
Collaborator Author

@imzhenyu , is it ok now?

@qinzuoyan qinzuoyan merged commit 9850d9b into master Jul 29, 2016
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.

2 participants