You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Steffen Pingel (JIRA)" <ji...@apache.org> on 2007/06/05 20:57:26 UTC

[jira] Created: (HTTPCORE-78) ExpandleBuffer uses direct byte buffers

ExpandleBuffer uses direct byte buffers
---------------------------------------

                 Key: HTTPCORE-78
                 URL: https://issues.apache.org/jira/browse/HTTPCORE-78
             Project: HttpComponents Core
          Issue Type: Improvement
    Affects Versions: 4.0-alpha4
            Reporter: Steffen Pingel
            Priority: Minor


HttpCore allocates subtypes of ExpandleBuffer per connection for buffering requests and responses. ExpandleBuffer creates a buffer using ByteBuffer.allocateDirect() which is initialized to a certain size but may be resized as needed requiring the garbage collector to discard the old buffer. 

According to the documentation for ByteBuffer, direct buffers are recommended for "large, long-lived buffers that are subject to the underlying system's native I/O operations". It seems that these buffers are rather short-lived and ByteBuffer.allocate() might be a better choice for allocation. 

Another option would be to pass a factory for allocating and releasing buffers which could reduce the number of allocations by reusing buffers.

-- 
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: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Updated: (HTTPCORE-78) ExpandableBuffer uses direct byte buffers

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

Steffen Pingel updated HTTPCORE-78:
-----------------------------------

    Attachment: httpcore-bytebuffer-allocator.patch

Sorry. Here is the updated patch.

> ExpandableBuffer uses direct byte buffers
> -----------------------------------------
>
>                 Key: HTTPCORE-78
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-78
>             Project: HttpComponents Core
>          Issue Type: Improvement
>    Affects Versions: 4.0-alpha4
>            Reporter: Steffen Pingel
>             Fix For: 4.0-alpha5
>
>         Attachments: httpcore-bytebuffer-allocator.patch, httpcore-bytebuffer-allocator.patch
>
>
> HttpCore allocates subtypes of ExpandleBuffer per connection for buffering requests and responses. ExpandleBuffer creates a buffer using ByteBuffer.allocateDirect() which is initialized to a certain size but may be resized as needed requiring the garbage collector to discard the old buffer. 
> According to the documentation for ByteBuffer, direct buffers are recommended for "large, long-lived buffers that are subject to the underlying system's native I/O operations". It seems that these buffers are rather short-lived and ByteBuffer.allocate() might be a better choice for allocation. 
> Another option would be to pass a factory for allocating and releasing buffers which could reduce the number of allocations by reusing buffers.

-- 
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: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Commented: (HTTPCORE-78) ExpandleBuffer uses direct byte buffers

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

Oleg Kalnichevski commented on HTTPCORE-78:
-------------------------------------------

Hi Steffen,

> if that is added to the constructor of ExpandableBuffer this will affect a lot of (test) classes it need to be propagated 
> all the way from IOEventDispatch, right?

I believe so. It will not be pretty but we can mitigate the impact on the existing code base by adding an extra constructor that provides some impl of the ByteBufferAllocator per default.

> Are you thinking about something along these lines?

Yes. I do not see a lot of value in providing pooling buffer allocators, hence there is not need to have #release method. This should do

ByteBufferAllocator {
  ByteBuffer allocate(int size);
}

What do you think?

Oleg


> ExpandleBuffer uses direct byte buffers
> ---------------------------------------
>
>                 Key: HTTPCORE-78
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-78
>             Project: HttpComponents Core
>          Issue Type: Improvement
>    Affects Versions: 4.0-alpha4
>            Reporter: Steffen Pingel
>             Fix For: 4.0-alpha5
>
>
> HttpCore allocates subtypes of ExpandleBuffer per connection for buffering requests and responses. ExpandleBuffer creates a buffer using ByteBuffer.allocateDirect() which is initialized to a certain size but may be resized as needed requiring the garbage collector to discard the old buffer. 
> According to the documentation for ByteBuffer, direct buffers are recommended for "large, long-lived buffers that are subject to the underlying system's native I/O operations". It seems that these buffers are rather short-lived and ByteBuffer.allocate() might be a better choice for allocation. 
> Another option would be to pass a factory for allocating and releasing buffers which could reduce the number of allocations by reusing buffers.

-- 
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: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Commented: (HTTPCORE-78) ExpandableBuffer uses direct byte buffers

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

Oleg Kalnichevski commented on HTTPCORE-78:
-------------------------------------------

Patch checked in with some very minor modifications. 

Steffen,
Would you be interested in submitting a follow-up patch that optimizes ByteBuffer allocation strategies in HttpCore NIO? Probably only Shared*Buffer classes should be using DirectByteBufferAllocator per default as they are meant to be rather largish and constant in length. 

Besides, do consider sending in your CLA [1], so we could mention your name in the @author tags of the classes you have made significant contribution to.

Oleg

[1] http://www.apache.org/licenses/index.html#clas

> ExpandableBuffer uses direct byte buffers
> -----------------------------------------
>
>                 Key: HTTPCORE-78
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-78
>             Project: HttpComponents Core
>          Issue Type: Improvement
>    Affects Versions: 4.0-alpha4
>            Reporter: Steffen Pingel
>             Fix For: 4.0-alpha5
>
>         Attachments: httpcore-bytebuffer-allocator.patch, httpcore-bytebuffer-allocator.patch
>
>
> HttpCore allocates subtypes of ExpandleBuffer per connection for buffering requests and responses. ExpandleBuffer creates a buffer using ByteBuffer.allocateDirect() which is initialized to a certain size but may be resized as needed requiring the garbage collector to discard the old buffer. 
> According to the documentation for ByteBuffer, direct buffers are recommended for "large, long-lived buffers that are subject to the underlying system's native I/O operations". It seems that these buffers are rather short-lived and ByteBuffer.allocate() might be a better choice for allocation. 
> Another option would be to pass a factory for allocating and releasing buffers which could reduce the number of allocations by reusing buffers.

-- 
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: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Updated: (HTTPCORE-78) ExpandableBuffer uses direct byte buffers

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

Steffen Pingel updated HTTPCORE-78:
-----------------------------------

    Attachment: httpcore-bytebuffer-allocator.patch

Sounds good. Please see the patch for an implementation. I have added additional setters to some of the methods to maintain the current API as much as possible.

> ExpandableBuffer uses direct byte buffers
> -----------------------------------------
>
>                 Key: HTTPCORE-78
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-78
>             Project: HttpComponents Core
>          Issue Type: Improvement
>    Affects Versions: 4.0-alpha4
>            Reporter: Steffen Pingel
>             Fix For: 4.0-alpha5
>
>         Attachments: httpcore-bytebuffer-allocator.patch
>
>
> HttpCore allocates subtypes of ExpandleBuffer per connection for buffering requests and responses. ExpandleBuffer creates a buffer using ByteBuffer.allocateDirect() which is initialized to a certain size but may be resized as needed requiring the garbage collector to discard the old buffer. 
> According to the documentation for ByteBuffer, direct buffers are recommended for "large, long-lived buffers that are subject to the underlying system's native I/O operations". It seems that these buffers are rather short-lived and ByteBuffer.allocate() might be a better choice for allocation. 
> Another option would be to pass a factory for allocating and releasing buffers which could reduce the number of allocations by reusing buffers.

-- 
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: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Updated: (HTTPCORE-78) ExpandleBuffer uses direct byte buffers

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

Steffen Pingel updated HTTPCORE-78:
-----------------------------------


Oleg, if that is added to the constructor of ExpandableBuffer this will affect a lot of (test) classes it need to be propagated all the way from IOEventDispatch, right?

Are you thinking about something along these lines?

 ByteBufferAllocator {
  ByteBuffer allocate(int size);
  void release(ByteBuffer buffer);
 }

> ExpandleBuffer uses direct byte buffers
> ---------------------------------------
>
>                 Key: HTTPCORE-78
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-78
>             Project: HttpComponents Core
>          Issue Type: Improvement
>    Affects Versions: 4.0-alpha4
>            Reporter: Steffen Pingel
>             Fix For: 4.0-alpha5
>
>
> HttpCore allocates subtypes of ExpandleBuffer per connection for buffering requests and responses. ExpandleBuffer creates a buffer using ByteBuffer.allocateDirect() which is initialized to a certain size but may be resized as needed requiring the garbage collector to discard the old buffer. 
> According to the documentation for ByteBuffer, direct buffers are recommended for "large, long-lived buffers that are subject to the underlying system's native I/O operations". It seems that these buffers are rather short-lived and ByteBuffer.allocate() might be a better choice for allocation. 
> Another option would be to pass a factory for allocating and releasing buffers which could reduce the number of allocations by reusing buffers.

-- 
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: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Commented: (HTTPCORE-78) ExpandableBuffer uses direct byte buffers

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

Oleg Kalnichevski commented on HTTPCORE-78:
-------------------------------------------

Steffen,
ByteBufferAllocator and DirectByteBufferAllocator classes are not included in the patch. Could you please 'svn add' those files and re-create the patch?

Oleg

> ExpandableBuffer uses direct byte buffers
> -----------------------------------------
>
>                 Key: HTTPCORE-78
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-78
>             Project: HttpComponents Core
>          Issue Type: Improvement
>    Affects Versions: 4.0-alpha4
>            Reporter: Steffen Pingel
>             Fix For: 4.0-alpha5
>
>         Attachments: httpcore-bytebuffer-allocator.patch
>
>
> HttpCore allocates subtypes of ExpandleBuffer per connection for buffering requests and responses. ExpandleBuffer creates a buffer using ByteBuffer.allocateDirect() which is initialized to a certain size but may be resized as needed requiring the garbage collector to discard the old buffer. 
> According to the documentation for ByteBuffer, direct buffers are recommended for "large, long-lived buffers that are subject to the underlying system's native I/O operations". It seems that these buffers are rather short-lived and ByteBuffer.allocate() might be a better choice for allocation. 
> Another option would be to pass a factory for allocating and releasing buffers which could reduce the number of allocations by reusing buffers.

-- 
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: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Resolved: (HTTPCORE-78) ExpandableBuffer uses direct byte buffers

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

Oleg Kalnichevski resolved HTTPCORE-78.
---------------------------------------

    Resolution: Fixed

Patch checked in. Many thanks, Steffen

> BTW, is it possible to limit the maximum request URI length and header/request length? I am concerned that overly 
> large requests would cause the buffers to resized until no more memory is available or the maximum buffer size of 
> Interger.MAX_VALUE is reached. 

'http.connection.max-line-length' and 'http.connection.max-header-count' parameters are already being enforced in HttpCore base (blocking) module. These checks still need to be implemented in HttpCore NIO.

Oleg

> ExpandableBuffer uses direct byte buffers
> -----------------------------------------
>
>                 Key: HTTPCORE-78
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-78
>             Project: HttpComponents Core
>          Issue Type: Improvement
>    Affects Versions: 4.0-alpha4
>            Reporter: Steffen Pingel
>             Fix For: 4.0-alpha5
>
>         Attachments: httpcore-bytebuffer-allocator.patch, httpcore-bytebuffer-allocator.patch, httpcore-heap-allocator.patch
>
>
> HttpCore allocates subtypes of ExpandleBuffer per connection for buffering requests and responses. ExpandleBuffer creates a buffer using ByteBuffer.allocateDirect() which is initialized to a certain size but may be resized as needed requiring the garbage collector to discard the old buffer. 
> According to the documentation for ByteBuffer, direct buffers are recommended for "large, long-lived buffers that are subject to the underlying system's native I/O operations". It seems that these buffers are rather short-lived and ByteBuffer.allocate() might be a better choice for allocation. 
> Another option would be to pass a factory for allocating and releasing buffers which could reduce the number of allocations by reusing buffers.

-- 
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: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Updated: (HTTPCORE-78) ExpandableBuffer uses direct byte buffers

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

Steffen Pingel updated HTTPCORE-78:
-----------------------------------

    Attachment: httpcore-heap-allocator.patch

Thanks for merging. The attached patch modifies the code to use HeapByteBufferAllocator by default except for Shared*Buffers.

BTW, is it possible to limit the maximum request URI length and header/request length? I am concerned that overly large requests would cause the buffers to resized until no more memory is available or the maximum buffer size of Interger.MAX_VALUE is reached.


> ExpandableBuffer uses direct byte buffers
> -----------------------------------------
>
>                 Key: HTTPCORE-78
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-78
>             Project: HttpComponents Core
>          Issue Type: Improvement
>    Affects Versions: 4.0-alpha4
>            Reporter: Steffen Pingel
>             Fix For: 4.0-alpha5
>
>         Attachments: httpcore-bytebuffer-allocator.patch, httpcore-bytebuffer-allocator.patch, httpcore-heap-allocator.patch
>
>
> HttpCore allocates subtypes of ExpandleBuffer per connection for buffering requests and responses. ExpandleBuffer creates a buffer using ByteBuffer.allocateDirect() which is initialized to a certain size but may be resized as needed requiring the garbage collector to discard the old buffer. 
> According to the documentation for ByteBuffer, direct buffers are recommended for "large, long-lived buffers that are subject to the underlying system's native I/O operations". It seems that these buffers are rather short-lived and ByteBuffer.allocate() might be a better choice for allocation. 
> Another option would be to pass a factory for allocating and releasing buffers which could reduce the number of allocations by reusing buffers.

-- 
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: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Updated: (HTTPCORE-78) ExpandableBuffer uses direct byte buffers

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

Sebb updated HTTPCORE-78:
-------------------------

    Summary: ExpandableBuffer uses direct byte buffers  (was: ExpandleBuffer uses direct byte buffers)

> ExpandableBuffer uses direct byte buffers
> -----------------------------------------
>
>                 Key: HTTPCORE-78
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-78
>             Project: HttpComponents Core
>          Issue Type: Improvement
>    Affects Versions: 4.0-alpha4
>            Reporter: Steffen Pingel
>             Fix For: 4.0-alpha5
>
>
> HttpCore allocates subtypes of ExpandleBuffer per connection for buffering requests and responses. ExpandleBuffer creates a buffer using ByteBuffer.allocateDirect() which is initialized to a certain size but may be resized as needed requiring the garbage collector to discard the old buffer. 
> According to the documentation for ByteBuffer, direct buffers are recommended for "large, long-lived buffers that are subject to the underlying system's native I/O operations". It seems that these buffers are rather short-lived and ByteBuffer.allocate() might be a better choice for allocation. 
> Another option would be to pass a factory for allocating and releasing buffers which could reduce the number of allocations by reusing buffers.

-- 
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: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Updated: (HTTPCORE-78) ExpandleBuffer uses direct byte buffers

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

Oleg Kalnichevski updated HTTPCORE-78:
--------------------------------------

         Priority: Major  (was: Minor)
    Fix Version/s: 4.0-alpha5

Hi Steffen
A ByteBufferAllocator interface sounds like a good idea to me

Oleg

> ExpandleBuffer uses direct byte buffers
> ---------------------------------------
>
>                 Key: HTTPCORE-78
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-78
>             Project: HttpComponents Core
>          Issue Type: Improvement
>    Affects Versions: 4.0-alpha4
>            Reporter: Steffen Pingel
>             Fix For: 4.0-alpha5
>
>
> HttpCore allocates subtypes of ExpandleBuffer per connection for buffering requests and responses. ExpandleBuffer creates a buffer using ByteBuffer.allocateDirect() which is initialized to a certain size but may be resized as needed requiring the garbage collector to discard the old buffer. 
> According to the documentation for ByteBuffer, direct buffers are recommended for "large, long-lived buffers that are subject to the underlying system's native I/O operations". It seems that these buffers are rather short-lived and ByteBuffer.allocate() might be a better choice for allocation. 
> Another option would be to pass a factory for allocating and releasing buffers which could reduce the number of allocations by reusing buffers.

-- 
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: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org