You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2020/09/17 10:10:45 UTC

[GitHub] [rocketmq] huangyiminghappy opened a new issue #2306: get Selector don't need to judge by programming

huangyiminghappy opened a new issue #2306:
URL: https://github.com/apache/rocketmq/issues/2306


   n the org.apache.rocketmq.remoting.common.RemotingUtil.openSelector
   `public static Selector openSelector() throws IOException {
       Selector result = null;
   
       if (isLinuxPlatform()) {
           try {
               final Class<?> providerClazz = Class.forName("sun.nio.ch.EPollSelectorProvider");
               if (providerClazz != null) {
                   try {
                       final Method method = providerClazz.getMethod("provider");
                       if (method != null) {
                           final SelectorProvider selectorProvider = (SelectorProvider) method.invoke(null);
                           if (selectorProvider != null) {
                               result = selectorProvider.openSelector();
                           }
                       }
                   } catch (final Exception e) {
                       log.warn("Open ePoll Selector for linux platform exception", e);
                   }
               }
           } catch (final Exception e) {
               // ignore
           }
       }
   
       if (result == null) {
           result = Selector.open();
       }
   
       return result;
   }`
   
   get the Selector don't need to judge by programming,because the code `Selector.open()`
   has the ability to choose Selector according to the platform.
   
   Example in my macos's jdk 8,the Selector.open ,the code is `
   public static Selector open() throws IOException { 
      return SelectorProvider.provider().openSelector();
    }
    
   public static SelectorProvider provider() {
       synchronized (lock) {
           if (provider != null)
               return provider;
           return AccessController.doPrivileged(
               new PrivilegedAction<SelectorProvider>() {
                   public SelectorProvider run() {
                           if (loadProviderFromProperty())
                               return provider;
                           if (loadProviderAsService())
                               return provider;
                           provider = sun.nio.ch.DefaultSelectorProvider.create();
                           return provider;
                       }
                   });
       }
   }
   `
   
    
   the code `provider = sun.nio.ch.DefaultSelectorProvider.create();`
   
   
   it's implementation is different depending on the platform,and if it is openjdk,get Selector is the same,link:https://github.com/ibmruntimes/openj9-openjdk-jdk8/blob/c85b84056711e44d349a1d967eca1e7ace723566/jdk/src/solaris/classes/sun/nio/ch/DefaultSelectorProvider.java
   
    


----------------------------------------------------------------
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] [rocketmq] huangyiminghappy commented on issue #2306: get Selector don't need to judge by programming

Posted by GitBox <gi...@apache.org>.
huangyiminghappy commented on issue #2306:
URL: https://github.com/apache/rocketmq/issues/2306#issuecomment-699800047


   > Yes, the default `SelectorProvider` will choose the right `Selector` based on the system, as for Linux, it will use `EPollSelectorProvider` if the kernel is 2.6 or newer otherwise it will choose `PollSelectorProvider`.
   > But as the the JDK api says, users can specify their own SelectorProvider:
   > 
   > ```
   > The first invocation of this method locates the default provider object as follows:
   > 
   > If the system property java.nio.channels.spi.SelectorProvider is defined then it is taken to be the fully-qualified name of a concrete provider class. The class is loaded and instantiated; if this process fails then an unspecified error is thrown.
   > 
   > If a provider class has been installed in a jar file that is visible to the system class loader, and that jar file contains a provider-configuration file named java.nio.channels.spi.SelectorProvider in the resource directory META-INF/services, then the first class name specified in that file is taken. The class is loaded and instantiated; if this process fails then an unspecified error is thrown.
   > 
   > Finally, if no provider has been specified by any of the above means then the system-default provider class is instantiated and the result is returned.
   > 
   > Subsequent invocations of this method return the provider that was returned by the first invocation.
   > ```
   > 
   > So, IMHO, if it is the purpose of RocketMQ to disable user-specified Selector and use `EPollSelectorProvider` regardless of user configuration, use only `Selector.open()` would not work.
   
   I agree with some of your views,but i think that,if the code Clearly indicate the use like `if (isLinuxPlatform()) {
       try {
           final Class<?> providerClazz = Class.forName("sun.nio.ch.EPollSelectorProvider");`
   
   i think the use like this,The user has no choice,The effect is that the user uses EPollSelectorProvider  on the linux platform,so much code can use Selector.open() instead, and why user must use EPollSelectorProvider in linux as the only choose ? may be they can use custom selector,so i think we need clear some unnecessory code


----------------------------------------------------------------
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] [rocketmq] huangyiminghappy edited a comment on issue #2306: get Selector don't need to judge by programming

Posted by GitBox <gi...@apache.org>.
huangyiminghappy edited a comment on issue #2306:
URL: https://github.com/apache/rocketmq/issues/2306#issuecomment-700378874


   if you read kafka,you can found it just use selector.open,and not Separately what's platform,so I still insist that modification is the best choice


----------------------------------------------------------------
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] [rocketmq] huangyiminghappy edited a comment on issue #2306: get Selector don't need to judge by programming

Posted by GitBox <gi...@apache.org>.
huangyiminghappy edited a comment on issue #2306:
URL: https://github.com/apache/rocketmq/issues/2306#issuecomment-700378874


   if you read kafka,you can find it just use selector.open,and not Separately what's platform,so I still insist that modification is the best choice


----------------------------------------------------------------
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] [rocketmq] vongosling commented on issue #2306: get Selector don't need to judge by programming

Posted by GitBox <gi...@apache.org>.
vongosling commented on issue #2306:
URL: https://github.com/apache/rocketmq/issues/2306#issuecomment-699862652


   It doesn't seem particularly obvious benefits, especially for the older platform and some minor versions in jdk8. IMO, we could remove it when updating the default compiler like the same doing in openjdk( https://bugs.openjdk.java.net/browse/JDK-8142872). Thanks for all participating discussion :-)


----------------------------------------------------------------
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] [rocketmq] huangyiminghappy commented on issue #2306: get Selector don't need to judge by programming

Posted by GitBox <gi...@apache.org>.
huangyiminghappy commented on issue #2306:
URL: https://github.com/apache/rocketmq/issues/2306#issuecomment-698088219


   @RongtongJin can you help review it ?thanks


----------------------------------------------------------------
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] [rocketmq] imaffe commented on issue #2306: get Selector don't need to judge by programming

Posted by GitBox <gi...@apache.org>.
imaffe commented on issue #2306:
URL: https://github.com/apache/rocketmq/issues/2306#issuecomment-695492828


   Yeah looks like we probably need a platform-compatibility specialist to verify 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



[GitHub] [rocketmq] huangyiminghappy commented on issue #2306: get Selector don't need to judge by programming

Posted by GitBox <gi...@apache.org>.
huangyiminghappy commented on issue #2306:
URL: https://github.com/apache/rocketmq/issues/2306#issuecomment-700378874


   if you read kafka,you can found it just use selector.open,and not Separately what's platform


----------------------------------------------------------------
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] [rocketmq] vongosling closed issue #2306: get Selector don't need to judge by programming

Posted by GitBox <gi...@apache.org>.
vongosling closed issue #2306:
URL: https://github.com/apache/rocketmq/issues/2306


   


----------------------------------------------------------------
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] [rocketmq] medusar commented on issue #2306: get Selector don't need to judge by programming

Posted by GitBox <gi...@apache.org>.
medusar commented on issue #2306:
URL: https://github.com/apache/rocketmq/issues/2306#issuecomment-699747793


   Yes, the default `SelectorProvider` will choose the right `Selector` based on the system,  as for Linux, it will use `EPollSelectorProvider` if the kernel is 2.6 or newer otherwise it will choose `PollSelectorProvider`.
   But as the the JDK api says, users can specify their own SelectorProvider: 
   ```
   The first invocation of this method locates the default provider object as follows:
   
   If the system property java.nio.channels.spi.SelectorProvider is defined then it is taken to be the fully-qualified name of a concrete provider class. The class is loaded and instantiated; if this process fails then an unspecified error is thrown.
   
   If a provider class has been installed in a jar file that is visible to the system class loader, and that jar file contains a provider-configuration file named java.nio.channels.spi.SelectorProvider in the resource directory META-INF/services, then the first class name specified in that file is taken. The class is loaded and instantiated; if this process fails then an unspecified error is thrown.
   
   Finally, if no provider has been specified by any of the above means then the system-default provider class is instantiated and the result is returned.
   
   Subsequent invocations of this method return the provider that was returned by the first invocation.
   ```
   So, IMHO, if it is the purpose of RocketMQ to disable user-specified Selector and use `EPollSelectorProvider` regardless of user configuration, use only `Selector.open()` would not work.


----------------------------------------------------------------
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] [rocketmq] huangyiminghappy edited a comment on issue #2306: get Selector don't need to judge by programming

Posted by GitBox <gi...@apache.org>.
huangyiminghappy edited a comment on issue #2306:
URL: https://github.com/apache/rocketmq/issues/2306#issuecomment-699800047


   > Yes, the default `SelectorProvider` will choose the right `Selector` based on the system, as for Linux, it will use `EPollSelectorProvider` if the kernel is 2.6 or newer otherwise it will choose `PollSelectorProvider`.
   > But as the the JDK api says, users can specify their own SelectorProvider:
   > 
   > ```
   > The first invocation of this method locates the default provider object as follows:
   > 
   > If the system property java.nio.channels.spi.SelectorProvider is defined then it is taken to be the fully-qualified name of a concrete provider class. The class is loaded and instantiated; if this process fails then an unspecified error is thrown.
   > 
   > If a provider class has been installed in a jar file that is visible to the system class loader, and that jar file contains a provider-configuration file named java.nio.channels.spi.SelectorProvider in the resource directory META-INF/services, then the first class name specified in that file is taken. The class is loaded and instantiated; if this process fails then an unspecified error is thrown.
   > 
   > Finally, if no provider has been specified by any of the above means then the system-default provider class is instantiated and the result is returned.
   > 
   > Subsequent invocations of this method return the provider that was returned by the first invocation.
   > ```
   > 
   > So, IMHO, if it is the purpose of RocketMQ to disable user-specified Selector and use `EPollSelectorProvider` regardless of user configuration, use only `Selector.open()` would not work.
   
   I agree with some of your views,but i think that,if the code Clearly indicate the use like `if (isLinuxPlatform()) {
       try {
           final Class<?> providerClazz = Class.forName("sun.nio.ch.EPollSelectorProvider");`
   
   i think the use like this,The user has no choice,The effect is that the user uses EPollSelectorProvider  on the linux platform, if the linux version is less than 2.6,we can not require user use 'EPollSelectorProvider', so i think some code can use Selector.open() instead, and why user must use EPollSelectorProvider in linux as the only choose ? may be they can use custom selector,so i think we need clear some unnecessory code


----------------------------------------------------------------
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] [rocketmq] medusar commented on issue #2306: get Selector don't need to judge by programming

Posted by GitBox <gi...@apache.org>.
medusar commented on issue #2306:
URL: https://github.com/apache/rocketmq/issues/2306#issuecomment-699804034


   > > Yes, the default `SelectorProvider` will choose the right `Selector` based on the system, as for Linux, it will use `EPollSelectorProvider` if the kernel is 2.6 or newer otherwise it will choose `PollSelectorProvider`.
   > > But as the the JDK api says, users can specify their own SelectorProvider:
   > > ```
   > > The first invocation of this method locates the default provider object as follows:
   > > 
   > > If the system property java.nio.channels.spi.SelectorProvider is defined then it is taken to be the fully-qualified name of a concrete provider class. The class is loaded and instantiated; if this process fails then an unspecified error is thrown.
   > > 
   > > If a provider class has been installed in a jar file that is visible to the system class loader, and that jar file contains a provider-configuration file named java.nio.channels.spi.SelectorProvider in the resource directory META-INF/services, then the first class name specified in that file is taken. The class is loaded and instantiated; if this process fails then an unspecified error is thrown.
   > > 
   > > Finally, if no provider has been specified by any of the above means then the system-default provider class is instantiated and the result is returned.
   > > 
   > > Subsequent invocations of this method return the provider that was returned by the first invocation.
   > > ```
   > > 
   > > 
   > > So, IMHO, if it is the purpose of RocketMQ to disable user-specified Selector and use `EPollSelectorProvider` regardless of user configuration, use only `Selector.open()` would not work.
   > 
   > I agree with some of your views,but i think that,if the code Clearly indicate the use like `if (isLinuxPlatform()) { try { final Class<?> providerClazz = Class.forName("sun.nio.ch.EPollSelectorProvider");`
   > 
   > i think the use like this,The user has no choice,The effect is that the user uses EPollSelectorProvider on the linux platform,so much code can use Selector.open() instead, and why user must use EPollSelectorProvider in linux as the only choose ? may be they can use custom selector,so i think we need clear some unnecessory code
   
   I agree with you, `Selector.open()` is much simpler and clean.


----------------------------------------------------------------
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] [rocketmq] huangyiminghappy commented on issue #2306: get Selector don't need to judge by programming

Posted by GitBox <gi...@apache.org>.
huangyiminghappy commented on issue #2306:
URL: https://github.com/apache/rocketmq/issues/2306#issuecomment-698088219


   @RongtongJin can you help review it ?thanks


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