Balancing the use of CPU / memory resource flows on a Java J2EE server

I am developing a website / online document collaboration service that runs on JBoss. During testing on a Linux machine with a 2.5 GHz processor and 2 GB RAM, the page response is very fast, and we plan to start this machine.

The problem occurs when processing documents. After the user downloads the document, a new stream starts, which, among other things, converts the document, extracts text and images from the document and downloads the document via https on another server. The user can upload several documents at once, and the streams for their processing work simultaneously. Until this processing is complete, the website becomes almost unresponsive.

Can you give me some tips on how I could somehow distribute the percentage of CPU / memory (e.g. 40%) to document processing threads? If this is not possible, please tell me a methodology / template that will somehow distribute the load on the machine between JBoss responding to page requests and document processing threads.

Hi

+3
source share
2 answers

It is not possible to allocate a certain percentage of CPU / memory time for a given thread. You can lower the priority of a stream so that it does not saturate all resources:

int oldPriority = Thread.currentThread().getPriority();
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
// process your documents here
Thread.currentThread().setPriority(oldPriority);

, , , , ExecutorService . , 50% . , singleton :

int threads = Runtime.getRuntime().availableProcessors() / 2;
ExecutorService service = Executors.newFixedThreadPool(threads);

- Callable, , :

Callable<Result> callable = new DocumentProcessorCallable<Object>(doc);
Result result = service.submit(callable).get();

, Runnable, service.execute(runnable). . ExecutorService .

+3

, , JMS, MDB. , , , ( CPU).

, MDB . , .

+2

All Articles