[ 
https://issues.apache.org/jira/browse/ZOOKEEPER-4952?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Li Wang updated ZOOKEEPER-4952:
-------------------------------
    Description: 
As part of ZOOKEEPER-4289,  Prometheus summary reporting is handled as an async 
operation using ThreadPoolExecutor.

The default RejectedExecutionHandler used by ThreadPoolExecutor is AbortPolicy, 
which performs toString() on both the Runnable object and exception object. 
This can significantly impact performance when too many exceptions occur after 
the max queue size exceeds.

{code:java}
public static class AbortPolicy implements RejectedExecutionHandler {
        /**
         * Creates an {@code AbortPolicy}.
         */
        public AbortPolicy() { }

        /**
         * Always throws RejectedExecutionException.
         *
         * @param r the runnable task requested to be executed
         * @param e the executor attempting to execute this task
         * @throws RejectedExecutionException always
         */
        public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
            throw new RejectedExecutionException("Task " + r.toString() +
                                                 " rejected from " +
                                                 e.toString());
        }
    }

{code}


  was:
The default RejectedExecutionHandler using by ThreadPoolExecutor is 
AbortPolicy.  It performs toString() on both the Runnable object and exception 
object. The GC overhead can be significant when too many exception occurs after 
the max queue size is exceeded.

This is to reduce the GC overhead and improve performance by implementing a 
PrometheusRejectExceptionHandler and overriding the rejectedExecution() API.

{code:java}
public static class AbortPolicy implements RejectedExecutionHandler {
        /**
         * Creates an {@code AbortPolicy}.
         */
        public AbortPolicy() { }

        /**
         * Always throws RejectedExecutionException.
         *
         * @param r the runnable task requested to be executed
         * @param e the executor attempting to execute this task
         * @throws RejectedExecutionException always
         */
        public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
            throw new RejectedExecutionException("Task " + r.toString() +
                                                 " rejected from " +
                                                 e.toString());
        }
    }

{code}



> Reduce the GC overhead of Prometheus reject exception handling
> --------------------------------------------------------------
>
>                 Key: ZOOKEEPER-4952
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-4952
>             Project: ZooKeeper
>          Issue Type: Improvement
>          Components: metric system
>    Affects Versions: 3.8.0, 3.9.0, 3.8.2, 3.8.3, 3.9.1, 3.8.4, 3.9.2, 3.9.3
>            Reporter: Li Wang
>            Priority: Critical
>
> As part of ZOOKEEPER-4289,  Prometheus summary reporting is handled as an 
> async operation using ThreadPoolExecutor.
> The default RejectedExecutionHandler used by ThreadPoolExecutor is 
> AbortPolicy, which performs toString() on both the Runnable object and 
> exception object. This can significantly impact performance when too many 
> exceptions occur after the max queue size exceeds.
> {code:java}
> public static class AbortPolicy implements RejectedExecutionHandler {
>         /**
>          * Creates an {@code AbortPolicy}.
>          */
>         public AbortPolicy() { }
>         /**
>          * Always throws RejectedExecutionException.
>          *
>          * @param r the runnable task requested to be executed
>          * @param e the executor attempting to execute this task
>          * @throws RejectedExecutionException always
>          */
>         public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
>             throw new RejectedExecutionException("Task " + r.toString() +
>                                                  " rejected from " +
>                                                  e.toString());
>         }
>     }
> {code}



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

Reply via email to