You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2015/01/21 21:50:55 UTC

[Bug 57478] New: Using non-blocking "Future" instead of blocking "Future.get" to improve performance?

https://issues.apache.org/bugzilla/show_bug.cgi?id=57478

            Bug ID: 57478
           Summary: Using non-blocking "Future" instead of blocking
                    "Future.get" to improve performance?
           Product: Tomcat 8
           Version: trunk
          Hardware: PC
                OS: Mac OS X 10.1
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: yu.lin.86@gmail.com

Hi, I'm doing research on asynchronous programming. I found in many places, the
code in Tomcat 8 invokes "Future.get()" immediately after starting a future
task. Because "Future.get()" is a blocking call, the code will block
immediately. 

For example, in "startInternal" method of "ContainerBase" class (line 917), you
invoke "result.get()", where "result" is a Future, immediately after starting
it, so the code blocks immediately. Such code has the same effect as sequential
code (or even worse since you need to use other threads). 

Why not use Guava ListenableFuture or Java8 CompletableFuture and avoid
"Future.get()"? These two new constructs provide callbacks to listen to the
Future's result:
http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/util/concurrent/ListenableFuture.html

https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html

For example, in "ContainerBase" class, you may put the code after
"result.get()" (such as lines 924-937) into CompletableFuture.thenRunAsync.
Then make "startInternal" method return this CompletableFuture, and in the
callers (such as "LifecycleBase.start()" method) you can put more continuations
into CompletableFuture.thenRunAsync. And you can also invoke "Future.get"
somewhere in the callers, instead of immediately. 

Do you think such kind of change is correct and can improve the code?

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57478] Using non-blocking "Future" instead of blocking "Future.get" to improve performance?

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=57478

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Mark Thomas <ma...@apache.org> ---
Bugzilla is not a discussion for design descisions. This belongs on the dev
list.

For the record, I think the kind of change you are suggesting is wrong and is
based on a superficial understanding of the code.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57478] Using non-blocking "Future" instead of blocking "Future.get" to improve performance?

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=57478

--- Comment #3 from Chuck Caldarale <ch...@unisys.com> ---
What part of "belongs on the dev list" was not clear?

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57478] Using non-blocking "Future" instead of blocking "Future.get" to improve performance?

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=57478

--- Comment #2 from Yu Lin <yu...@gmail.com> ---
Thanks for the reply.
> Bugzilla is not a discussion for design descisions. This belongs on the dev
> list.
> 
I think this is a performance issue, so I posted it here. Or should I send it
to dev@tomcat.apache.org

> For the record, I think the kind of change you are suggesting is wrong and
> is based on a superficial understanding of the code.
Could you elaborate a bit? Don't you think invoking "Future.get()" immediately
after starting the task has the same effect as sequential execution? Is there
any better suggestions?

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org