hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "silver9886 (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (HTTPCORE-480) improve the code in check timeout
Date Wed, 02 Aug 2017 13:15:00 GMT

    [ https://issues.apache.org/jira/browse/HTTPCORE-480?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16110833#comment-16110833
] 

silver9886 edited comment on HTTPCORE-480 at 8/2/17 1:14 PM:
-------------------------------------------------------------


the new idea is this(i update the attach .java file) :
add a protected class MinHoldTime default value is 0.
        if( (currentTime - this.lastTimeoutCheck) >= this.timeoutCheckInterval + minholdTime.get())
{
            if (keys != null) {
                for (final SelectionKey key : keys) {
                    timeoutCheck(key, currentTime,minholdTime);
                }
            }
        }
in the timeoutCheck,we can get the min sockettimeout is all sessions and change the minholdTime.get()
return value.
    protected void timeoutCheck(final SelectionKey key, final long now, final MinHoldTime
minHoldTime) {
        final IOSessionImpl session = (IOSessionImpl) key.attachment();
        if (session != null) {
            final int timeout = session.getSocketTimeout();
            if (minHoldTime.get() == 0 || minHoldTime.get() > timeout ) {
                minHoldTime.set(timeout);
            }
            if (timeout > 0) {
                if (session.getLastAccessTime() + timeout < now) {
                    sessionTimedOut(session);
                }
            }
        }
    }
 


was (Author: silver9886):
when return from readyCount = this.selector.select(this.selectTimeout); the time has elapsed
(this.selectTimeout default is 1s). 
when the code execute the code if( (currentTime - this.lastTimeoutCheck) >= this.timeoutCheckInterval)
the time is elapsed larger than (this.selectTimeout default is 1s).
beacuse the pc need the time to execute the code between readyCount = this.selector.select(this.selectTimeout);
and if( (currentTime - this.lastTimeoutCheck) >= this.timeoutCheckInterval)
so currentTime - this.lastTimeoutCheck >= this.timeoutCheckInterval will always return
true(because timeoutCheckInterval=selectTimeout ).
I think if there is no post/get request , the currentTime - this.lastTimeoutCheck should no
be true.
suppose the time executed elapsed between 
readyCount = this.selector.select(this.selectTimeout); and if( (currentTime - this.lastTimeoutCheck)
>= this.timeoutCheckInterval) 
at last need 1 millisecond.

the new idea is this(i update the attach .java file) :
add a protected class MinHoldTime default value is 1 (means at last 1 millisecond).
        if( (currentTime - this.lastTimeoutCheck) >= this.timeoutCheckInterval + minholdTime.get())
{
            if (keys != null) {
                for (final SelectionKey key : keys) {
                    timeoutCheck(key, currentTime,minholdTime);
                }
            }
        }
in the timeoutCheck,we can get the min sockettimeout is all sessions and change the minholdTime.get()
return value.
    protected void timeoutCheck(final SelectionKey key, final long now, final MinHoldTime
minHoldTime) {
        final IOSessionImpl session = (IOSessionImpl) key.attachment();
        if (session != null) {
            final int timeout = session.getSocketTimeout();
            if (minHoldTime.get() == 1 || minHoldTime.get() > timeout ) {
                minHoldTime.set(timeout);
            }
            if (timeout > 0) {
                if (session.getLastAccessTime() + timeout < now) {
                    sessionTimedOut(session);
                }
            }
        }
    }
 

> improve the code in check timeout
> ---------------------------------
>
>                 Key: HTTPCORE-480
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-480
>             Project: HttpComponents HttpCore
>          Issue Type: Improvement
>          Components: HttpCore NIO
>    Affects Versions: 4.4.6
>            Reporter: silver9886
>            Priority: Minor
>             Fix For: 4.4.7
>
>         Attachments: AbstractIOReactor.java, BaseIOReactor.java
>
>
> change the code in org.apache.http.impl.nio.reactor.BaseIOReactor:
>         if( (currentTime - this.lastTimeoutCheck) >= this.timeoutCheckInterval) ->
>    if( (currentTime - this.lastTimeoutCheck) >= this.timeoutCheckInterval + 2)
> because :the code will run for a time and network tranport expend the time too.  So currentTime
- this.lastTimeoutCheck should be 
> larger than selectTimeout in order to check timeout. In this case , This will make the
code more efficiency.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

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


Mime
View raw message