Thanks for reply!
I looked through the code of the StaticResourcesAdapter and found that
actual data transfer from FileInputStream to Response (and then to the
adapter container) is completly done on the thead that handles request - so
the thread is completly occupied by this.
> 159 FileInputStream fis = new FileInputStream(resource);
> 160 byte b[] = new byte[8192];
> 161 ByteChunk chunk = new ByteChunk();
> 162 int rd = 0;
> 163 while ((rd = fis.read(b)) > 0) {
> 164 chunk.setBytes(b, 0, rd);
> 165 res.doWrite(chunk);
> 166 }
>
I'm surely not a grizzly expert (yet :) ) but i'm 99% sure that this
implementation can handle only as many file requests (at the same time) as
many threads are in the threadpool (http server uses threads from grizzly's
threadpool right?). Surely one can increase the number of worker threads but
that's not a scalable solution you know.
p.s. seems that someone forgot to close fileinputstream :)
https://grizzly.dev.java.net/nonav/xref/com/sun/grizzly/tcp/StaticResourcesAdapter.html#159
Jeanfrancois Arcand-2 wrote:
>
> Salut,
>
> ash2k! wrote:
>> Hi, all!
>>
>> I need to implement a simple web server that will handle simple GET
>> requests. Based on request server should do some actions and then answer
>> the
>> client by giving him a file (some thing like file server). Files will be
>> big
>> (~300-500 MB max) and i want to use NIO to be able to scale to many
>> clients.
>>
>> Questions: :)
>> 1) can i use comet or some other grizzly based thing to implement this?
>
> Yes. What you want is to use the Grizzly's http web server. You can
> download the binary here[1] and try it by doing:
>
> java -jar grizzly-http-webserver-1.7.3.1.jar -p 8080 -a /var/www
>
> (or build it yourself by checking out the code:
>
> % svn checkout https://www.dev.java.net/svn/grizzly/trunk
>
> Now this WebServer is for static resources. For you application, you
> will need to write an Adapter[2] if you really want to work with bytes,
> or if you want to use a Servlet-like API, extends the GrizzlyAdapter[3].
> I recommend you extend GrizzlyAdapter as it has support for
> Input/OutputStream, Writer, etc. NIO API is not available at that layer
> but if you really needs access to the SocketChannel, I can probably
> add a new API for you to get access to it.
>
> Then once you have your Adapter implemented, you just need to do (the
> code is from [4]):
>
>> 83 /**
>> 84 * Create a single SelectorThread.
>> 85 * @param args The command line arguments.
>> 86 */
>> 87 public SelectorThread createSelectorThread(String args[]) throws
>> Exception {
>> 107 String selectorThreadClassname =
>> System.getProperty(SELECTOR_THREAD);
>> 108 if (selectorThreadClassname != null) {
>> 109 st = (SelectorThread) loadClass(selectorThreadClassname);
>> 110 } else {
>> 111 st = new SelectorThread() {
>> 112 @Override
>> 113 public void listen() throws InstantiationException,
>> IOException {
>> 114 super.listen();
>> 115 System.out.println("Server started in "
>> 116 + (System.currentTimeMillis() - t1) + "
>> milliseconds.");
>> 117 }
>> 118 };
>> 119 }
>> 120
>> st.setAlgorithmClassName(StaticStreamAlgorithm.class.getName());
>> 121 st.setPort(port);
>> 122 SelectorThread.setWebAppRootPath(appliPath);
>> 123
>> 124 st.setAdapter(configureAdapter(st));
>> 125 return st;
>> 126 }
>
> And example of Adapter can be found in [5], a GrizzlyAdapter in [6]
>
>> 2) may be there is some other (may be non grizzly based) http
>> server/framework i can use to implement this?
>
> Grizzly is exactly what you want :-)
>
> A+
>
> -- Jeanfrancois
>
> [1]
> http://download.java.net/maven/2/com/sun/grizzly/grizzly-http-webserver/1.7.3.1/grizzly-http-webserver-1.7.3.1.jar
> [2]
> https://grizzly.dev.java.net/nonav/xref/com/sun/grizzly/tcp/Adapter.html
> [3]
> https://grizzly.dev.java.net/nonav/xref/com/sun/grizzly/tcp/http11/GrizzlyAdapter.html
> [4]
> https://grizzly.dev.java.net/nonav/xref/com/sun/grizzly/standalone/StandaloneMainUtil.html
> [5]
> https://grizzly.dev.java.net/nonav/xref/com/sun/grizzly/tcp/StaticResourcesAdapter.html
> [6]
> https://grizzly.dev.java.net/nonav/xref/com/sun/grizzly/http/servlet/ServletAdapter.html
>
>
--
View this message in context: http://www.nabble.com/Question-about-http-on-grizzly-tp16846432p16890706.html
Sent from the Grizzly - Users mailing list archive at Nabble.com.