Betamoo
Betamoo

Reputation: 15860

Processing large documents on server side

What is the best way to avoid loading a document upon each client http request?? Is it logical to keep all these loaded documents in memory? If yes, would it require a thread pool, where each thread is holding a document? If no, what are the other options?

(Working with Java - Tomcat - Ubuntu)

Upvotes: 0

Views: 123

Answers (2)

Konstantin Pribluda
Konstantin Pribluda

Reputation: 12367

In case you are processing document by external program, tere is not much that you can do except caching processing results somewhere. Another option would be eagerly preprocess documents and store all possible query results for later retrieval.

Forking external process on every request is clearly worst option.

As your data is processed insiede web applicaton and is immutable you can just mmap files into byte buffers and work agains them. this way you will save loading and allocation of data in your JVM.

And since your queries do not change data,there is no need to push them to separate threads - they can access data from different threads serving http requests directly

Upvotes: 0

Dario Pedol
Dario Pedol

Reputation: 2110

I would put another server in front of your tomcat to do some caching. If you implement this yourself, you're bound to run into problems. A setup might look like this:

ClientVarnish Caching ServerApache HTTP ServerTomcat

If you need HTTPS, you might consider putting another server before Varnish as it doesn't support SSL (as I recall). Then it might be like this:

ClientPoundVarnish Caching ServerApache HTTP ServerTomcat

You can configure Varnish extensively with some kind of rule-language. It will serve you very nicely.

Pound is just a small reverse-proxy that you can use for terminating SSL and/or load balancing.

Links:

Apache: http://httpd.apache.org/

Varnish: https://www.varnish-cache.org/

Pound: http://www.apsis.ch/pound

Upvotes: 1

Related Questions