You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "gunli (via GitHub)" <gi...@apache.org> on 2023/11/04 07:23:45 UTC

[PR] [Improve] pool sendRequest to improve producer perf [pulsar-client-go]

gunli opened a new pull request, #1126:
URL: https://github.com/apache/pulsar-client-go/pull/1126

   <!--
   ### Contribution Checklist
     
     - Name the pull request in the form "[Issue XYZ][component] Title of the pull request", where *XYZ* should be replaced by the actual issue number.
       Skip *Issue XYZ* if there is no associated github issue for this pull request.
       Skip *component* if you are unsure about which is the best component. E.g. `[docs] Fix typo in produce method`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   *(If this PR fixes a github issue, please add `Fixes #<xyz>`.)*
   
   Fixes #<xyz>
   
   *(or if this PR is one task of a github issue, please add `Master Issue: #<xyz>` to link to the master issue.)*
   
   Master Issue: #<xyz>
   
   ### Motivation
   
   `sendRequest ` in producer is a frequently allocated struct, pool it can decrease the memory allocation.
   
   
   
   ### Modifications
   
   1. Init a sync.Pool;
   2. Get sendRequest  from the pool when we need; 
   3. Reset sendRequest and put it back into the pool when it is done.
   
   ### Verifying this change
   
   - [x] Make sure that the change passes the CI checks.
   
   *(Please pick either of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If `yes` was chosen, please highlight the changes*
   
     - Dependencies (does it add or upgrade a dependency): (no)
     - The public API: (yes / no)
     - The schema: (yes / no / don't know)
     - The default values of configurations: (yes / no)
     - The wire protocol: (yes / no)
   
   ### Documentation
   
     - Does this pull request introduce a new feature? (no)
     - If yes, how is the feature documented? (not applicable / docs / GoDocs / not documented)
     - If a feature is not applicable for documentation, explain why?
     - If a feature is not documented yet in this PR, please create a followup issue for adding the documentation
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve] pool sendRequest to improve producer perf [pulsar-client-go]

Posted by "rfyiamcool (via GitHub)" <gi...@apache.org>.
rfyiamcool commented on code in PR #1126:
URL: https://github.com/apache/pulsar-client-go/pull/1126#discussion_r1385986865


##########
pulsar/producer_partition.go:
##########
@@ -1477,6 +1491,13 @@ func (sr *sendRequest) done(msgID MessageID, err error) {
 			sr.transaction.endSendOrAckOp(err)
 		}
 	}
+
+	pool := sr.pool
+	if pool != nil {
+		// reset all the fields
+		*sr = sendRequest{}

Review Comment:
   👍



##########
pulsar/producer_partition.go:
##########
@@ -1477,6 +1491,13 @@ func (sr *sendRequest) done(msgID MessageID, err error) {
 			sr.transaction.endSendOrAckOp(err)
 		}
 	}
+
+	pool := sr.pool
+	if pool != nil {
+		// reset all the fields
+		*sr = sendRequest{}

Review Comment:
   👍



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve] pool sendRequest to improve producer perf [pulsar-client-go]

Posted by "Gleiphir2769 (via GitHub)" <gi...@apache.org>.
Gleiphir2769 commented on PR #1126:
URL: https://github.com/apache/pulsar-client-go/pull/1126#issuecomment-1793962565

   Hi @gunli, the implement looks good to me. But most member of `SendRequest` are pointer. I think It's not essential to pool it. Could you give a more significant benchmark result?
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve] pool sendRequest to improve producer perf [pulsar-client-go]

Posted by "RobertIndie (via GitHub)" <gi...@apache.org>.
RobertIndie merged PR #1126:
URL: https://github.com/apache/pulsar-client-go/pull/1126


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve] pool sendRequest to improve producer perf [pulsar-client-go]

Posted by "gunli (via GitHub)" <gi...@apache.org>.
gunli commented on PR #1126:
URL: https://github.com/apache/pulsar-client-go/pull/1126#issuecomment-1794266161

   > Hi @gunli, the implement looks good to me. But most member of `SendRequest` are pointer. I think It's not essential to pool it. Could you give a more significant benchmark result?
   
   ![heap-pr](https://github.com/apache/pulsar-client-go/assets/10734543/5244d3b6-61a7-4c25-a1f9-1a38e5c2c977)
   ![heap-nopr](https://github.com/apache/pulsar-client-go/assets/10734543/14a406de-9c82-485e-9593-21064a054454)
   
   Yes, here are the heap pprof results when benchmarked with and without this PR, we can see when benchmarked  without this PR, `internalSend` and `internalSendAsync`, in where `sendRequest`s are allocated, allocated much more memory than that when it benchmarked with this PR. 
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve] pool sendRequest to improve producer perf [pulsar-client-go]

Posted by "gunli (via GitHub)" <gi...@apache.org>.
gunli commented on PR #1126:
URL: https://github.com/apache/pulsar-client-go/pull/1126#issuecomment-1800866415

   For the sake of fairness, I updated the benchmark, set b.N = 500000, the pprof reports are:
   
   ![pr](https://github.com/apache/pulsar-client-go/assets/10734543/7fcb58fd-3627-41f7-b296-c3b1c70c14fe)
   ![no-pr](https://github.com/apache/pulsar-client-go/assets/10734543/a08bc650-091c-4267-aae3-80aed04870f8)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve] pool sendRequest to improve producer perf [pulsar-client-go]

Posted by "Gleiphir2769 (via GitHub)" <gi...@apache.org>.
Gleiphir2769 commented on PR #1126:
URL: https://github.com/apache/pulsar-client-go/pull/1126#issuecomment-1794556083

   >  we can see when benchmarked without this PR, internalSend and internalSendAsync, in where sendRequests are allocated, allocated much more memory than that when it benchmarked with this PR.
   Good work @gunli ! I have no doubt now.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve] pool sendRequest to improve producer perf [pulsar-client-go]

Posted by "gunli (via GitHub)" <gi...@apache.org>.
gunli commented on PR #1126:
URL: https://github.com/apache/pulsar-client-go/pull/1126#issuecomment-1793379639

   @RobertIndie @tisonkun @Gleiphir2769 @shibd 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org