Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 16F4C200CD8 for ; Wed, 2 Aug 2017 15:15:10 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 154D91695B6; Wed, 2 Aug 2017 13:15:10 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 346B51695B3 for ; Wed, 2 Aug 2017 15:15:09 +0200 (CEST) Received: (qmail 32838 invoked by uid 500); 2 Aug 2017 13:15:07 -0000 Mailing-List: contact dev-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list dev@hc.apache.org Received: (qmail 32827 invoked by uid 99); 2 Aug 2017 13:15:07 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Aug 2017 13:15:07 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 175F018041D for ; Wed, 2 Aug 2017 13:15:07 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id WVgEg1O_S4EG for ; Wed, 2 Aug 2017 13:15:02 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id A58865F5C4 for ; Wed, 2 Aug 2017 13:15:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id D0D54E0AF9 for ; Wed, 2 Aug 2017 13:15:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 81EB924651 for ; Wed, 2 Aug 2017 13:15:00 +0000 (UTC) Date: Wed, 2 Aug 2017 13:15:00 +0000 (UTC) From: "silver9886 (JIRA)" To: dev@hc.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (HTTPCORE-480) improve the code in check timeout MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Wed, 02 Aug 2017 13:15:10 -0000 [ 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