massakam commented on issue #3630: Broker can not respond to client requests
URL: https://github.com/apache/pulsar/issues/3630#issuecomment-468116803
 
 
   @rdhabalia I modified the test code `CaffeineTest.java` of comment 
https://github.com/apache/pulsar/issues/3630#issuecomment-467926959 as follows, 
but the same phenomenon occurred. Just using an external executor may not solve 
this problem.
   
   Change:
   ```diff
   --- CaffeineTest.java.BAK       2019-02-28 10:56:31.401268202 +0900
   +++ CaffeineTest.java   2019-02-28 11:45:04.092022888 +0900
   @@ -7,19 +7,23 @@
    import com.github.benmanes.caffeine.cache.AsyncLoadingCache;
    import com.github.benmanes.caffeine.cache.Caffeine;
   
   +import org.apache.bookkeeper.common.util.OrderedExecutor;
   +
    public class CaffeineTest {
        private final AsyncLoadingCache<String, String> dataCache;
   +    private final OrderedExecutor executor;
   
        public CaffeineTest() {
            dataCache = Caffeine.newBuilder().expireAfterWrite(1, 
TimeUnit.MINUTES).buildAsync((k, executor) -> null);
   +        executor = 
OrderedExecutor.newBuilder().name("external-executor").numThreads(6).build();
        }
   
        public CompletableFuture<String> getDataAsync(final String key) {
            CompletableFuture<String> future = new CompletableFuture<>();
   
   -        dataCache.get(key, (k, executor) -> {
   +        dataCache.get(key, (k, cacheExecutor) -> {
                CompletableFuture<String> cacheFuture = new 
CompletableFuture<>();
   -            executor.execute(() -> {
   +            this.executor.execute(() -> {
                    cacheFuture.complete("val" + k);
                });
                return cacheFuture;
   @@ -33,6 +37,10 @@
            return future;
        }
   
   +    public void shutdown() {
   +        executor.shutdown();
   +    }
   +
        public static void main(String[] args) throws Exception {
            System.out.println("---- START ----");
            CaffeineTest cTest = new CaffeineTest();
   @@ -49,6 +57,7 @@
                threads[i].join();
            }
            System.out.println("---- FINISH ----");
   +        cTest.shutdown();
        }
    }
   
   @@ -74,7 +83,7 @@
                    final String key = String.valueOf(i);
                    cTest.getDataAsync(key).thenAccept(v -> {
                        printInfo(String.format("key: %s, value: %s", key, v));
   -                    if (tid == 0 && 
Thread.currentThread().getName().startsWith("ForkJoinPool.commonPool-worker")
   +                    if (tid == 0 && 
Thread.currentThread().getName().startsWith("external-executor-OrderedExecutor")
                                && !alreadySlept) {
                            alreadySlept = true;
                            printInfo("Sleeping 10 sec...");
   ```
   
   Execution result:
   ```sh
   ---- START ----
   11:16:18.454 [9] [Thread-10] [INFO] key: 0, value: val0
   11:16:18.456 [6] [Thread-7] [INFO] key: 0, value: val0
   
   ...
   
   11:16:18.472 [1] [Thread-2] [INFO] key: 3, value: val3
   11:16:18.481 [7] [external-executor-OrderedExecutor-2-0] [INFO] key: 6, 
value: val6
   11:16:18.482 [4] [external-executor-OrderedExecutor-2-0] [INFO] key: 8, 
value: val8
   11:16:18.482 [0] [external-executor-OrderedExecutor-2-0] [INFO] key: 8, 
value: val8
   
   # "external-executor-OrderedExecutor-2-0" starts sleeping for 10 seconds here
   11:16:18.483 [0] [external-executor-OrderedExecutor-2-0] [INFO] Sleeping 10 
sec...
   
   11:16:18.483 [1] [Thread-2] [INFO] key: 4, value: val4
   11:16:18.483 [1] [Thread-2] [INFO] key: 5, value: val5
   11:16:18.483 [1] [Thread-2] [INFO] key: 6, value: val6
   11:16:18.484 [1] [Thread-2] [INFO] key: 7, value: val7
   11:16:18.484 [1] [Thread-2] [INFO] key: 8, value: val8
   11:16:18.484 [1] [Thread-2] [INFO] key: 9, value: val9
   
   # Processing of all threads is stopped for about 10 seconds from here
   
   11:16:28.483 [8] [external-executor-OrderedExecutor-2-0] [INFO] key: 8, 
value: val8
   11:16:28.484 [2] [external-executor-OrderedExecutor-2-0] [INFO] key: 8, 
value: val8
   11:16:28.484 [3] [external-executor-OrderedExecutor-2-0] [INFO] key: 8, 
value: val8
   11:16:28.484 [9] [external-executor-OrderedExecutor-2-0] [INFO] key: 8, 
value: val8
   11:16:28.485 [6] [external-executor-OrderedExecutor-2-0] [INFO] key: 8, 
value: val8
   11:16:28.485 [5] [external-executor-OrderedExecutor-2-0] [INFO] key: 8, 
value: val8
   11:16:28.485 [7] [external-executor-OrderedExecutor-2-0] [INFO] key: 8, 
value: val8
   ---- FINISH ----
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to