You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2020/09/07 02:39:28 UTC

[GitHub] [dubbo-go] skyao opened a new pull request #739: Imp: Improve map access concurrency

skyao opened a new pull request #739:
URL: https://github.com/apache/dubbo-go/pull/739


   <!--  Thanks for sending a pull request! 
   -->
   
   **What this PR does**:
   
   This PR is to improve the accessing of map in concurrency environment.
   
   1. improve the performace of GetURLStatus() method
   2. fix the problem of concurrency risk in  GetMethodStatus() method
   
   
   **Which issue(s) this PR fixes**:
   <!--
   *Automatically closes linked issue when PR is merged.
   Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
   _If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
   -->
   Fixes #
   
   **Special notes for your reviewer**:
   
   **Does this PR introduce a user-facing change?**:
   <!--
   If no, just write "NONE" in the release-note block below.
   If yes, a release note is required:
   Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
   -->
   ```release-note
   NONE
   ```


----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-go] zouyx commented on pull request #739: Imp: Improve map access concurrency

Posted by GitBox <gi...@apache.org>.
zouyx commented on pull request #739:
URL: https://github.com/apache/dubbo-go/pull/739#issuecomment-688016724


   Should change target branch to `deveop`


----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-go] zouyx commented on a change in pull request #739: Imp: Improve map access concurrency

Posted by GitBox <gi...@apache.org>.
zouyx commented on a change in pull request #739:
URL: https://github.com/apache/dubbo-go/pull/739#discussion_r484620675



##########
File path: protocol/rpc_status.go
##########
@@ -98,7 +98,10 @@ func (rpc *RPCStatus) GetSuccessiveRequestFailureCount() int32 {
 
 // GetURLStatus get URL RPC status.
 func GetURLStatus(url common.URL) *RPCStatus {
-	rpcStatus, _ := serviceStatistic.LoadOrStore(url.Key(), &RPCStatus{})
+	rpcStatus, found := serviceStatistic.Load(url.Key())

Review comment:
       Why don't you use `LoadOrStore` directly? 




----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-go] watermelo commented on a change in pull request #739: Imp: Improve map access concurrency

Posted by GitBox <gi...@apache.org>.
watermelo commented on a change in pull request #739:
URL: https://github.com/apache/dubbo-go/pull/739#discussion_r484628838



##########
File path: protocol/rpc_status.go
##########
@@ -98,7 +98,10 @@ func (rpc *RPCStatus) GetSuccessiveRequestFailureCount() int32 {
 
 // GetURLStatus get URL RPC status.
 func GetURLStatus(url common.URL) *RPCStatus {
-	rpcStatus, _ := serviceStatistic.LoadOrStore(url.Key(), &RPCStatus{})
+	rpcStatus, found := serviceStatistic.Load(url.Key())

Review comment:
       It seems to have higher performance, go version is 1.13.
   ```go
   func BenchmarkStore(b *testing.B) {
       for i := 0; i < b.N; i++ {
           _, found := methodStatistics.Load("test")
           if !found {
               _, _ = methodStatistics.LoadOrStore("test", &RPCStatus{})
           }
       }
   }
   
   func BenchmarkLoadOrStore(b *testing.B) {
       for i := 0; i < b.N; i++ {
           _, _ = methodStatistics.LoadOrStore("test", &RPCStatus{})
       }
   }
   
   BenchmarkStore-4                23008020                48.4 ns/op             0 B/op          0 allocs/op
   BenchmarkLoadOrStore-4          10381435               102 ns/op              80 B/op          1 allocs/op
   PASS
   ```
   




----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-go] zouyx merged pull request #739: Imp: Improve map access concurrency

Posted by GitBox <gi...@apache.org>.
zouyx merged pull request #739:
URL: https://github.com/apache/dubbo-go/pull/739


   


----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-go] zouyx commented on a change in pull request #739: Imp: Improve map access concurrency

Posted by GitBox <gi...@apache.org>.
zouyx commented on a change in pull request #739:
URL: https://github.com/apache/dubbo-go/pull/739#discussion_r484620675



##########
File path: protocol/rpc_status.go
##########
@@ -98,7 +98,10 @@ func (rpc *RPCStatus) GetSuccessiveRequestFailureCount() int32 {
 
 // GetURLStatus get URL RPC status.
 func GetURLStatus(url common.URL) *RPCStatus {
-	rpcStatus, _ := serviceStatistic.LoadOrStore(url.Key(), &RPCStatus{})
+	rpcStatus, found := serviceStatistic.Load(url.Key())

Review comment:
       Why don't you use `LoadOrStore` directly? For avoid lock competition?




----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-go] skyao commented on a change in pull request #739: Imp: Improve map access concurrency

Posted by GitBox <gi...@apache.org>.
skyao commented on a change in pull request #739:
URL: https://github.com/apache/dubbo-go/pull/739#discussion_r484680853



##########
File path: protocol/rpc_status.go
##########
@@ -98,7 +98,10 @@ func (rpc *RPCStatus) GetSuccessiveRequestFailureCount() int32 {
 
 // GetURLStatus get URL RPC status.
 func GetURLStatus(url common.URL) *RPCStatus {
-	rpcStatus, _ := serviceStatistic.LoadOrStore(url.Key(), &RPCStatus{})
+	rpcStatus, found := serviceStatistic.Load(url.Key())

Review comment:
       yes, the new code will save the cost of "&RPCStatus{}", which only be used when the key is not set and do "store", and late access  to this key, it always "load". But each invoke will still cost for the "&RPCStatus{}".  




----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org