You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2022/12/22 23:17:00 UTC

[jira] [Work logged] (POOL-393) BaseGenericObjectPool.jmxRegister may cost too much time

     [ https://issues.apache.org/jira/browse/POOL-393?focusedWorklogId=835413&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-835413 ]

ASF GitHub Bot logged work on POOL-393:
---------------------------------------

                Author: ASF GitHub Bot
            Created on: 22/Dec/22 23:16
            Start Date: 22/Dec/22 23:16
    Worklog Time Spent: 10m 
      Work Description: niallkp opened a new pull request, #199:
URL: https://github.com/apache/commons-pool/pull/199

   The algorithm for generating the JMX name for newly created pools can be very slow if the number of pools is large. This PR makes a 10x improvement without changing the naming sequence.
   
   I tried a couple of approaches - first retrieving all the registered pool names using  the MBeanServer's  **_queryNames(ObjectName, QueryExp)_** method and and then using MBeanServer's **_isRegistered(ObjectName)_** method. The later involved many more JMX calls but was slightly faster and simpler code - so this PR uses that approach.
   
   This PR seems to provide the performance improvement without changing behavior - which Phil didn't like in https://github.com/apache/commons-pool/pull/115




Issue Time Tracking
-------------------

    Worklog Id:     (was: 835413)
    Time Spent: 1h 10m  (was: 1h)

> BaseGenericObjectPool.jmxRegister may cost too much time
> --------------------------------------------------------
>
>                 Key: POOL-393
>                 URL: https://issues.apache.org/jira/browse/POOL-393
>             Project: Commons Pool
>          Issue Type: Improvement
>    Affects Versions: 2.4.2
>            Reporter: Shichao Yuan
>            Priority: Major
>          Time Spent: 1h 10m
>  Remaining Estimate: 0h
>
>  
> When creating many pools, I find that it tasks too much time to register jmx.
> In the code,  the ObjectName's postfix always starts with 1, so many InstanceAlreadyExistsExceptions may be thrown before registered successfully.
> Maybe a random number is a better choice, or a atomic long.
> {quote}private ObjectName jmxRegister(BaseObjectPoolConfig config,
>  String jmxNameBase, String jmxNamePrefix) {
>  ObjectName objectName = null;
>  MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
>  int i = 1;
>  boolean registered = false;
>  String base = config.getJmxNameBase();
>  if (base == null)
> Unknown macro: \{ base = jmxNameBase; }
> while (!registered) {
>  try {
>  ObjectName objName;
>  // Skip the numeric suffix for the first pool in case there is
>  // only one so the names are cleaner.
>  if (i == 1)
> Unknown macro: \{ objName = new ObjectName(base + jmxNamePrefix); }
> else
> Unknown macro: \{ objName = new ObjectName(base + jmxNamePrefix + i); }
> mbs.registerMBean(this, objName);
>  objectName = objName;
>  registered = true;
>  } catch (MalformedObjectNameException e) {
>  if (BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX.equals(
>  jmxNamePrefix) && jmxNameBase.equals(base))
> Unknown macro: \{ // Shouldn't happen. Skip registration if it does. registered = true; }
> else
> Unknown macro: \{ // Must be an invalid name. Use the defaults instead. jmxNamePrefix = BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX; base = jmxNameBase; }
> } catch (InstanceAlreadyExistsException e)
> Unknown macro: \{ // Increment the index and try again i++; }
> catch (MBeanRegistrationException e)
> Unknown macro: \{ // Shouldn't happen. Skip registration if it does. registered = true; }
> catch (NotCompliantMBeanException e)
> }
>  return objectName;
>  }
> {quote}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)