You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2021/05/27 22:31:48 UTC

[GitHub] [geode] dschneider-pivotal opened a new pull request #6535: GEODE-9331: remove the threadConnMaps ArrayList

dschneider-pivotal opened a new pull request #6535:
URL: https://github.com/apache/geode/pull/6535


   The threadConnMaps ArrayList has been removed which will improve performance of new threads
   creating their first thread owned connection.
   This removal also means that the HashMap is now
   only referenced by a ThreadLocal so it no longer
   is synchronized which simplifies the code.
   
   Thank you for submitting a contribution to Apache Geode.
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically `develop`)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   - [ ] Does `gradlew build` run cleanly?
   
   - [ ] Have you written or updated unit tests to verify your changes?
   
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
   
   ### Note:
   Please ensure that once the PR is submitted, check Concourse for build issues and
   submit an update to your PR as soon as possible. If you need help, please send an
   email to dev@geode.apache.org.
   


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



[GitHub] [geode] dschneider-pivotal merged pull request #6535: GEODE-9331: remove the threadConnMaps ArrayList

Posted by GitBox <gi...@apache.org>.
dschneider-pivotal merged pull request #6535:
URL: https://github.com/apache/geode/pull/6535


   


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



[GitHub] [geode] dschneider-pivotal commented on a change in pull request #6535: GEODE-9331: remove the threadConnMaps ArrayList

Posted by GitBox <gi...@apache.org>.
dschneider-pivotal commented on a change in pull request #6535:
URL: https://github.com/apache/geode/pull/6535#discussion_r643329972



##########
File path: geode-core/src/main/java/org/apache/geode/internal/tcp/ConnectionTable.java
##########
@@ -443,32 +434,18 @@ Connection getThreadOwnedConnection(InternalDistributedMember id, long startTime
     if (m == null) {
       // First time for this thread. Create thread local
       m = new HashMap();
-      synchronized (threadConnMaps) {
-        if (closed) {
-          owner.getCancelCriterion().checkCancelInProgress(null);
-          throw new DistributedSystemDisconnectedException("Connection table is closed");
-        }
-        // check for stale references and remove them.
-        for (Iterator it = threadConnMaps.iterator(); it.hasNext();) {
-          Reference r = (Reference) it.next();
-          if (r.get() == null) {
-            it.remove();
-          }
-        }
-        threadConnMaps.add(new WeakReference(m));
+      if (closed) {

Review comment:
       nice catch; done




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



[GitHub] [geode] pivotal-jbarrett commented on a change in pull request #6535: GEODE-9331: remove the threadConnMaps ArrayList

Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on a change in pull request #6535:
URL: https://github.com/apache/geode/pull/6535#discussion_r643277673



##########
File path: geode-core/src/main/java/org/apache/geode/internal/tcp/ConnectionTable.java
##########
@@ -443,32 +434,18 @@ Connection getThreadOwnedConnection(InternalDistributedMember id, long startTime
     if (m == null) {
       // First time for this thread. Create thread local
       m = new HashMap();
-      synchronized (threadConnMaps) {
-        if (closed) {
-          owner.getCancelCriterion().checkCancelInProgress(null);
-          throw new DistributedSystemDisconnectedException("Connection table is closed");
-        }
-        // check for stale references and remove them.
-        for (Iterator it = threadConnMaps.iterator(); it.hasNext();) {
-          Reference r = (Reference) it.next();
-          if (r.get() == null) {
-            it.remove();
-          }
-        }
-        threadConnMaps.add(new WeakReference(m));
+      if (closed) {

Review comment:
       I think this check for closing and canceling was here because of the potential blocking at the now removed synchronized block. The calling method checks this before making the call. I don't think checking a few lines later makes any difference, especially since it can change to closed immediately after this check. 




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



[GitHub] [geode] dschneider-pivotal commented on pull request #6535: GEODE-9331: remove the threadConnMaps ArrayList

Posted by GitBox <gi...@apache.org>.
dschneider-pivotal commented on pull request #6535:
URL: https://github.com/apache/geode/pull/6535#issuecomment-852443871


   the dunit failure is the known issue: https://issues.apache.org/jira/browse/GEODE-9242


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



[GitHub] [geode] pivotal-jbarrett commented on a change in pull request #6535: GEODE-9331: remove the threadConnMaps ArrayList

Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on a change in pull request #6535:
URL: https://github.com/apache/geode/pull/6535#discussion_r643338085



##########
File path: geode-core/src/main/java/org/apache/geode/internal/tcp/ConnectionTable.java
##########
@@ -443,32 +434,14 @@ Connection getThreadOwnedConnection(InternalDistributedMember id, long startTime
     if (m == null) {
       // First time for this thread. Create thread local
       m = new HashMap();
-      synchronized (threadConnMaps) {
-        if (closed) {
-          owner.getCancelCriterion().checkCancelInProgress(null);
-          throw new DistributedSystemDisconnectedException("Connection table is closed");
-        }
-        // check for stale references and remove them.
-        for (Iterator it = threadConnMaps.iterator(); it.hasNext();) {
-          Reference r = (Reference) it.next();
-          if (r.get() == null) {
-            it.remove();
-          }
-        }
-        threadConnMaps.add(new WeakReference(m));
-      }
       threadOrderedConnMap.set(m);

Review comment:
       Now with all the other stuff gone we could replace this with:
   ```
   static final ThreadLocal<Map<DistributedMember, InternalConnection>> threadOrderedConnMap =
         ThreadLocal.withInitial(HashMap::new);
   ```




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



[GitHub] [geode] dschneider-pivotal commented on a change in pull request #6535: GEODE-9331: remove the threadConnMaps ArrayList

Posted by GitBox <gi...@apache.org>.
dschneider-pivotal commented on a change in pull request #6535:
URL: https://github.com/apache/geode/pull/6535#discussion_r643355362



##########
File path: geode-core/src/main/java/org/apache/geode/internal/tcp/ConnectionTable.java
##########
@@ -443,32 +434,14 @@ Connection getThreadOwnedConnection(InternalDistributedMember id, long startTime
     if (m == null) {
       // First time for this thread. Create thread local
       m = new HashMap();
-      synchronized (threadConnMaps) {
-        if (closed) {
-          owner.getCancelCriterion().checkCancelInProgress(null);
-          throw new DistributedSystemDisconnectedException("Connection table is closed");
-        }
-        // check for stale references and remove them.
-        for (Iterator it = threadConnMaps.iterator(); it.hasNext();) {
-          Reference r = (Reference) it.next();
-          if (r.get() == null) {
-            it.remove();
-          }
-        }
-        threadConnMaps.add(new WeakReference(m));
-      }
       threadOrderedConnMap.set(m);

Review comment:
       I liked this idea initially but then I found a couple of existing places in the code that we call get on this thread local to see if the current thread has a map and if it does to do something. If we make this change then these calls (they are cleanup methods) can end up creating a new HashMap for threads that didn't have one. So for this PR and like to hold off on making this change.




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