You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Tony Poppleton (JIRA)" <ji...@apache.org> on 2010/01/15 02:22:54 UTC

[jira] Created: (HTTPCLIENT-906) Minor performance improvement to IdleConnectionHandler

Minor performance improvement to IdleConnectionHandler
------------------------------------------------------

                 Key: HTTPCLIENT-906
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-906
             Project: HttpComponents HttpClient
          Issue Type: Improvement
            Reporter: Tony Poppleton
            Priority: Minor


The attached patch does the following changes to IdleConnectionHandler
 - as it iterator over a map of connections, using a LinkedHashMap is a faster
 - rather than using an iterator over the keyset and subsequently getting the values, an iterator over the entry set is used instead for efficiency (at least according to FindBugs)

Note that the patch contains other changes to make variables final where possible. This was done automatically by Eclipse, and can be removed if desired. However I see no harm in them, other than they affect more of the code than intended by the patch.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Updated: (HTTPCLIENT-906) Minor performance improvement to IdleConnectionHandler

Posted by "Tony Poppleton (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-906?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tony Poppleton updated HTTPCLIENT-906:
--------------------------------------

    Attachment: IdleConnectionHandler.java.patch

> Minor performance improvement to IdleConnectionHandler
> ------------------------------------------------------
>
>                 Key: HTTPCLIENT-906
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-906
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>            Reporter: Tony Poppleton
>            Priority: Minor
>         Attachments: IdleConnectionHandler.java.patch
>
>
> The attached patch does the following changes to IdleConnectionHandler
>  - as it iterator over a map of connections, using a LinkedHashMap is a faster
>  - rather than using an iterator over the keyset and subsequently getting the values, an iterator over the entry set is used instead for efficiency (at least according to FindBugs)
> Note that the patch contains other changes to make variables final where possible. This was done automatically by Eclipse, and can be removed if desired. However I see no harm in them, other than they affect more of the code than intended by the patch.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Updated: (HTTPCLIENT-906) Minor performance improvement to IdleConnectionHandler

Posted by "Tony Poppleton (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-906?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tony Poppleton updated HTTPCLIENT-906:
--------------------------------------

    Attachment: IdleConnectionHandler.java.patch3

Attached .patch3 which uses spaces rather than tabs (as per conventions) and removed use of "final" keyword to be consistent with rest of file.

> Minor performance improvement to IdleConnectionHandler
> ------------------------------------------------------
>
>                 Key: HTTPCLIENT-906
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-906
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>            Reporter: Tony Poppleton
>            Priority: Minor
>             Fix For: 4.1 Alpha2
>
>         Attachments: IdleConnectionHandler.java.patch, IdleConnectionHandler.java.patch2, IdleConnectionHandler.java.patch3
>
>
> The attached patch does the following changes to IdleConnectionHandler
>  - as it iterator over a map of connections, using a LinkedHashMap is a faster
>  - rather than using an iterator over the keyset and subsequently getting the values, an iterator over the entry set is used instead for efficiency (at least according to FindBugs)
> Note that the patch contains other changes to make variables final where possible. This was done automatically by Eclipse, and can be removed if desired. However I see no harm in them, other than they affect more of the code than intended by the patch.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Updated: (HTTPCLIENT-906) Minor performance improvement to IdleConnectionHandler

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-906?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oleg Kalnichevski updated HTTPCLIENT-906:
-----------------------------------------

    Fix Version/s: 4.1 Alpha2

> Minor performance improvement to IdleConnectionHandler
> ------------------------------------------------------
>
>                 Key: HTTPCLIENT-906
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-906
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>            Reporter: Tony Poppleton
>            Priority: Minor
>             Fix For: 4.1 Alpha2
>
>         Attachments: IdleConnectionHandler.java.patch, IdleConnectionHandler.java.patch2
>
>
> The attached patch does the following changes to IdleConnectionHandler
>  - as it iterator over a map of connections, using a LinkedHashMap is a faster
>  - rather than using an iterator over the keyset and subsequently getting the values, an iterator over the entry set is used instead for efficiency (at least according to FindBugs)
> Note that the patch contains other changes to make variables final where possible. This was done automatically by Eclipse, and can be removed if desired. However I see no harm in them, other than they affect more of the code than intended by the patch.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Commented: (HTTPCLIENT-906) Minor performance improvement to IdleConnectionHandler

Posted by "Tony Poppleton (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-906?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12800493#action_12800493 ] 

Tony Poppleton commented on HTTPCLIENT-906:
-------------------------------------------

This patch's usage of LinkedHashMap means it requires Java 1.4+.  Is this the case for HttpClient?

> Minor performance improvement to IdleConnectionHandler
> ------------------------------------------------------
>
>                 Key: HTTPCLIENT-906
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-906
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>            Reporter: Tony Poppleton
>            Priority: Minor
>         Attachments: IdleConnectionHandler.java.patch
>
>
> The attached patch does the following changes to IdleConnectionHandler
>  - as it iterator over a map of connections, using a LinkedHashMap is a faster
>  - rather than using an iterator over the keyset and subsequently getting the values, an iterator over the entry set is used instead for efficiency (at least according to FindBugs)
> Note that the patch contains other changes to make variables final where possible. This was done automatically by Eclipse, and can be removed if desired. However I see no harm in them, other than they affect more of the code than intended by the patch.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Resolved: (HTTPCLIENT-906) Minor performance improvement to IdleConnectionHandler

Posted by "Sebb (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-906?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb resolved HTTPCLIENT-906.
-----------------------------

    Resolution: Fixed

According to Java Generics and Collections (O'Reilly) Chapter 16, LinkedHashMap has slightly worse performance overall than HashMap, and should only be used if insertion or access order is important. That makes sense, because the LHM has to maintain its links.

BTW, when providing updated patches, it may be clearer to replace the original file with a new one.
IIf the old file is to be kept, please use a fixed type (e.g. .patch) and change the file stem (e.g. try3.patch), otherwise the attachment may be treated as binary.

I've applied the patch without the change to use LHM.

URL: http://svn.apache.org/viewvc?rev=899957&view=rev
Log:
HTTPCLIENT-906 Minor performance improvement to IdleConnectionHandler
Replace keySet() + get() with entrySet()

Modified:
   httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java

> Minor performance improvement to IdleConnectionHandler
> ------------------------------------------------------
>
>                 Key: HTTPCLIENT-906
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-906
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>            Reporter: Tony Poppleton
>            Priority: Minor
>             Fix For: 4.1 Alpha2
>
>         Attachments: IdleConnectionHandler.java.patch, IdleConnectionHandler.java.patch2, IdleConnectionHandler.java.patch3
>
>
> The attached patch does the following changes to IdleConnectionHandler
>  - as it iterator over a map of connections, using a LinkedHashMap is a faster
>  - rather than using an iterator over the keyset and subsequently getting the values, an iterator over the entry set is used instead for efficiency (at least according to FindBugs)
> Note that the patch contains other changes to make variables final where possible. This was done automatically by Eclipse, and can be removed if desired. However I see no harm in them, other than they affect more of the code than intended by the patch.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Updated: (HTTPCLIENT-906) Minor performance improvement to IdleConnectionHandler

Posted by "Tony Poppleton (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-906?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tony Poppleton updated HTTPCLIENT-906:
--------------------------------------

    Attachment: IdleConnectionHandler.java.patch2

Attached a second version of the patch (with suffix .patch2) without the whitespace and final changes.

> Minor performance improvement to IdleConnectionHandler
> ------------------------------------------------------
>
>                 Key: HTTPCLIENT-906
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-906
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>            Reporter: Tony Poppleton
>            Priority: Minor
>         Attachments: IdleConnectionHandler.java.patch, IdleConnectionHandler.java.patch2
>
>
> The attached patch does the following changes to IdleConnectionHandler
>  - as it iterator over a map of connections, using a LinkedHashMap is a faster
>  - rather than using an iterator over the keyset and subsequently getting the values, an iterator over the entry set is used instead for efficiency (at least according to FindBugs)
> Note that the patch contains other changes to make variables final where possible. This was done automatically by Eclipse, and can be removed if desired. However I see no harm in them, other than they affect more of the code than intended by the patch.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Commented: (HTTPCLIENT-906) Minor performance improvement to IdleConnectionHandler

Posted by "Tony Poppleton (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-906?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12801178#action_12801178 ] 

Tony Poppleton commented on HTTPCLIENT-906:
-------------------------------------------

Thanks.

Agreed, LHM is slower for some operation, however it does have faster iteration performance (http://www.artima.com/weblogs/viewpost.jsp?thread=122295).  I guess I was optimizing for my particular use-case where I don't add new connections frequently, but do try and close idle ones every 5 seconds.

Anyway, am happy either way.

> Minor performance improvement to IdleConnectionHandler
> ------------------------------------------------------
>
>                 Key: HTTPCLIENT-906
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-906
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>            Reporter: Tony Poppleton
>            Priority: Minor
>             Fix For: 4.1 Alpha2
>
>         Attachments: IdleConnectionHandler.java.patch, IdleConnectionHandler.java.patch2, IdleConnectionHandler.java.patch3
>
>
> The attached patch does the following changes to IdleConnectionHandler
>  - as it iterator over a map of connections, using a LinkedHashMap is a faster
>  - rather than using an iterator over the keyset and subsequently getting the values, an iterator over the entry set is used instead for efficiency (at least according to FindBugs)
> Note that the patch contains other changes to make variables final where possible. This was done automatically by Eclipse, and can be removed if desired. However I see no harm in them, other than they affect more of the code than intended by the patch.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Commented: (HTTPCLIENT-906) Minor performance improvement to IdleConnectionHandler

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-906?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12800498#action_12800498 ] 

Sebb commented on HTTPCLIENT-906:
---------------------------------

Agree that using entry set is better if one wants both key and values.
Whether LHM is faster overall is less immediately obvious, and will depend on how the map is used, not just how it is iterated.

The patch has spurious white-space changes as well as the final changes which make it very much harder to review.
Also, when patches are committed it is generally prefereable to fix one problem per commit.
Please provide patches that fix only the problem at hand.

The original code for which you have provided a patch includes generics, which require Java 1.5+, so LinkedHashMap must be OK

> Minor performance improvement to IdleConnectionHandler
> ------------------------------------------------------
>
>                 Key: HTTPCLIENT-906
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-906
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>            Reporter: Tony Poppleton
>            Priority: Minor
>         Attachments: IdleConnectionHandler.java.patch, IdleConnectionHandler.java.patch2
>
>
> The attached patch does the following changes to IdleConnectionHandler
>  - as it iterator over a map of connections, using a LinkedHashMap is a faster
>  - rather than using an iterator over the keyset and subsequently getting the values, an iterator over the entry set is used instead for efficiency (at least according to FindBugs)
> Note that the patch contains other changes to make variables final where possible. This was done automatically by Eclipse, and can be removed if desired. However I see no harm in them, other than they affect more of the code than intended by the patch.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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