You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by John Caron <ca...@unidata.ucar.edu> on 2008/02/05 16:22:21 UTC
Obtain a SocketChannel instead of OutputStream ?
My application is a scientific data server that transfers large amounts of binary data. I am looking to make it as fast as possible and have been experimenting with the NIO FileChannel.transferTo() method. This appears to be much faster (3-10X) than using an OutputStream, under some circumstances. So I am trying to see if I can use this from within Tomcat.
So the question is whether there is a way to obtain a SocketChannel for the connection? The standard interface only allows to get an OutputStream. While Channels.newChannel(OutputStream out) gives a WriteableByteChannel, the transferTo() method does not work on it, apparently one needs to get the SocketChannel at a deeper level.
Has anyone else tried this? Any ideas would be much appreciated.
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Obtain a SocketChannel instead of OutputStream ?
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
John,
John Caron wrote:
| I may need to make many such transfers to satisfy the request, so
| sendfile doesnt seem like it will work.
In this case, are you sure that HTTP is really the protocol for you?
It's not too difficult to write a NIO-based request/response server that
does something specific.... that is, you don't have to re-implement
everything Tomcat provides just to build your own server.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkewr+EACgkQ9CaO5/Lv0PD5zACfT5wQDvo7LOKujLdfeorG5LPc
u2kAn1qpIHT2RdTv7bPsSBwf4gzBwGI7
=lCv2
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Obtain a SocketChannel instead of OutputStream ?
Posted by John Caron <ca...@unidata.ucar.edu>.
Filip Hanik - Dev Lists wrote:
> John Caron wrote:
>> My application is a scientific data server that transfers large
>> amounts of binary data. I am looking to make it as fast as possible
>> and have been experimenting with the NIO FileChannel.transferTo()
>> method. This appears to be much faster (3-10X) than using an
>> OutputStream, under some circumstances. So I am trying to see if I can
>> use this from within Tomcat.
>>
>> So the question is whether there is a way to obtain a SocketChannel
>> for the connection? The standard interface only allows to get an
>> OutputStream. While Channels.newChannel(OutputStream out) gives a
>> WriteableByteChannel, the transferTo() method does not work on it,
>> apparently one needs to get the SocketChannel at a deeper level.
>>
>> Has anyone else tried this? Any ideas would be much appreciated.
> we haven't exposed the API at this level, since the data you write to
> the network, must go through several filters.
> you can still take advantage of the direct transfers by using Tomcat's
> built in send file technique.
>
> A user previously wrote:
>
> Any servlet can instruct Tomcat to perform a sendfile call by setting
> the appropriate response attributes. When using sendfile...
> * org.apache.tomcat.sendfile.filename: Canonical filename of the file
> which will be sent as a String
> * org.apache.tomcat.sendfile.start: Start offset as a Long
> * org.apache.tomcat.sendfile.end: End offset as a Long
>
> So add these attributes into the request, (see DefaultServlet.java for
> an example), and if you are using the APR or the NIO connector in
> Tomcat, tomcat will transfer them directly
Hi Filip:
I may need to make many such transfers to satisfy the request, so sendfile doesnt seem like it will
work. I realize this would bypass the Filters. Perhaps its not worth it, but I would like to test
the possible performance gain.
Thanks for the help....
John
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Obtain a SocketChannel instead of OutputStream ?
Posted by Filip Hanik - Dev Lists <de...@hanik.com>.
John Caron wrote:
> My application is a scientific data server that transfers large
> amounts of binary data. I am looking to make it as fast as possible
> and have been experimenting with the NIO FileChannel.transferTo()
> method. This appears to be much faster (3-10X) than using an
> OutputStream, under some circumstances. So I am trying to see if I can
> use this from within Tomcat.
>
> So the question is whether there is a way to obtain a SocketChannel
> for the connection? The standard interface only allows to get an
> OutputStream. While Channels.newChannel(OutputStream out) gives a
> WriteableByteChannel, the transferTo() method does not work on it,
> apparently one needs to get the SocketChannel at a deeper level.
>
> Has anyone else tried this? Any ideas would be much appreciated.
we haven't exposed the API at this level, since the data you write to
the network, must go through several filters.
you can still take advantage of the direct transfers by using Tomcat's
built in send file technique.
A user previously wrote:
Any servlet can instruct Tomcat to perform a sendfile call by setting
the appropriate response attributes. When using sendfile...
* org.apache.tomcat.sendfile.filename: Canonical filename of the
file which will be sent as a String
* org.apache.tomcat.sendfile.start: Start offset as a Long
* org.apache.tomcat.sendfile.end: End offset as a Long
So add these attributes into the request, (see DefaultServlet.java for
an example), and if you are using the APR or the NIO connector in
Tomcat, tomcat will transfer them directly
Filip
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org