{"action":"created","issue":{"url":"https://api.github.com/repos/netty/netty/issues/4441","labels_url":"https://api.github.com/repos/netty/netty/issues/4441/labels{/name}","comments_url":"https://api.github.com/repos/netty/netty/issues/4441/comments","events_url":"https://api.github.com/repos/netty/netty/issues/4441/events","html_url":"https://github.com/netty/netty/issues/4441","id":115280949,"number":4441,"title":"Recyclable FileRegion","user":{"login":"pjulien","id":673277,"avatar_url":"https://avatars.githubusercontent.com/u/673277?v=3","gravatar_id":"","url":"https://api.github.com/users/pjulien","html_url":"https://github.com/pjulien","followers_url":"https://api.github.com/users/pjulien/followers","following_url":"https://api.github.com/users/pjulien/following{/other_user}","gists_url":"https://api.github.com/users/pjulien/gists{/gist_id}","starred_url":"https://api.github.com/users/pjulien/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pjulien/subscriptions","organizations_url":"https://api.github.com/users/pjulien/orgs","repos_url":"https://api.github.com/users/pjulien/repos","events_url":"https://api.github.com/users/pjulien/events{/privacy}","received_events_url":"https://api.github.com/users/pjulien/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-05T13:11:03Z","updated_at":"2015-11-11T01:21:04Z","closed_at":null,"body":"I have the following use case\r\n\r\n- Single ring buffer per incoming request queue\r\n- Multiple ring buffers can be used to write to a fairly static set of ``Channel``s, i.e., one to many relationship between ring buffers and channels\r\n- A single ring buffer is backed by a memory mapped ``ByteBuffer`` file\r\n- I keep the ``FileChannel`` of the ring buffer open\r\n- To queue up data to the socket, I write to the ring buffer which in turns writes to the memory mapped buffer\r\n- For forwarding the data, I just read the position and length of entries in the ring buffer to initialize a ``DefaultFileRegion``\r\n- I have about 50,000 ring buffers, which implies 50,000 file descriptors.\r\n- I can also peek multiple entries from the ring buffer, which means I can have multiple writes of ``FileRegion`` in-flight at the same time.\r\n\r\nThe problems I'm facing with ``DefaultFileRegion`` are:\r\n- There is no constructor that allows leaving the ``FileChannel`` open when done.  Without this, I cannot keep the number of ``FileChannel``s static.\r\n- Additionally, it would be nice if I could recycle ``DefaultFileRegion`` when done.  I would reset the position and length and perform a new write using the same object.  This is just for GC churn.\r\n"},"comment":{"url":"https://api.github.com/repos/netty/netty/issues/comments/155623757","html_url":"https://github.com/netty/netty/issues/4441#issuecomment-155623757","issue_url":"https://api.github.com/repos/netty/netty/issues/4441","id":155623757,"user":{"login":"normanmaurer","id":439362,"avatar_url":"https://avatars.githubusercontent.com/u/439362?v=3","gravatar_id":"","url":"https://api.github.com/users/normanmaurer","html_url":"https://github.com/normanmaurer","followers_url":"https://api.github.com/users/normanmaurer/followers","following_url":"https://api.github.com/users/normanmaurer/following{/other_user}","gists_url":"https://api.github.com/users/normanmaurer/gists{/gist_id}","starred_url":"https://api.github.com/users/normanmaurer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/normanmaurer/subscriptions","organizations_url":"https://api.github.com/users/normanmaurer/orgs","repos_url":"https://api.github.com/users/normanmaurer/repos","events_url":"https://api.github.com/users/normanmaurer/events{/privacy}","received_events_url":"https://api.github.com/users/normanmaurer/received_events","type":"User","site_admin":false},"created_at":"2015-11-11T01:21:04Z","updated_at":"2015-11-11T01:21:04Z","body":"@pjulien why you can't just extend `DefaultFileRegion` and override the `deallocate()` method ? This way it will not close the `FileChannel`."}}