0

I'm creating an Java application using a REST front-end, hence must be responsive, and once in a while (X minutes) another service is polling the internet. For this some hundreds of threads are spawned.

Needless to say when hundreds of threads are running the server is slowing down (ie irresponsive). I found an option to supply a setPriority argument to Thread. But also found some flaws, meaning the front-end is pretty much irresponsive, although appears to be better without Java nicing.

So I'm checking my options: 1) nicing threads; 2) nicing a War (found no such option) 3) spawn another tomcat and nice that one, is possible but I would be losing precious resourced. Maybe assign thread pools to a subselection of cores?

My question mainly is some pointers in a helpful directions, preferably for option 1, then 2 etc. Or, of course, something I haven't mentioned, resulting in some dedicated cpu time for other threads.

Danielson
  • 2,605
  • 2
  • 28
  • 51
  • 2
    Why would your server be unresponsive when hundreds of threads are polling the Internet? They will mostly be blocked in reads or connects. If you have a problem to which thread priority is the solution, you usually have quite a different problem. – user207421 Jan 02 '15 at 21:00
  • Aside from polling the internet, the results get parsed and checked against the database (whether they already exist), to translate and stuff. I know that polling itself is not cpu expensive, but that's not all that happens... – Danielson Jan 03 '15 at 07:24
  • Why hundreds of threads rather than a few worker threads scanning through the list of queries, especially since the set only has to run once every X minutes? (I'd also check whether your "parsing and checking against the database" is oversynchronized, but reducing the number of threads would seem to be the first step.) – keshlam Jan 03 '15 at 07:33
  • When I am polling stuff out of Australia or Japan (since I'm from the Netherlands) takes about 200 ms (ping), so I need more threads. Furthermore, I don't see how this is relevant for the question. Regardless of what I am doing, I want to dedicate some part of my machine so that new requests are being processed as if the server was not busy. I could use 1 thread for polling, but then the idle time would be too great, and polling thousands of feeds would take too long. – Danielson Jan 03 '15 at 08:14

1 Answers1

0

I was able to nice the processes by editing the

/etc/systemd/system/tomcat.service

Just add a Nice=10 or whatever niceness level you want. All the processes should inherit the priority of the parent.

Suraj Kumar
  • 5,547
  • 8
  • 20
  • 42
user3788120
  • 447
  • 4
  • 4