Reputation: 314
I am using the jsp-servlet in my application. and deployed the war on jboss 7.0.2 server. i have servlet have code related to database and that is being called many time in sec (say 500 times). but it is falling over for such many threads, jboss 7.0.2 will not able to handle this threads.
I am using the 64 bit jvm.
I have reduce the size of the thread stack with -Xss256k, this not work for me.
i did the configuration in jboss.conf
wrapper.java.additional.10=-XX:ThreadStackSize=256k
I need to handle the 2000 threads on jboss7.
server (jboss7.0.2) throws an exception.
java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Unknown Source)
Here is my servlet java.lang.OutOfMemoryError: unable to create new native thread
public class Test extends HttpServlet {
private static final long serialVersionUID = 1L;
public Test() {
super();
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}
public void processRequest(HttpServletRequest request,
HttpServletResponse response) {
Logger log=LoggerFactory.getLogger(feedback.class);
/* here is my code to insert the data in database. */
TestClass testobj = new TestClass();
testobj.setparam("");
smsmanager1.add(sms);
smsmanager1 = null;
sms = null;
}
}
code fot add method
public void add(T obj) {
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session=sessionFactory.openSession();
Transaction transaction = null;
try {
transaction = session.beginTransaction();
session.save(obj);
transaction.commit();
session.flush();
} catch (HibernateException e) {
if(transaction!=null){
transaction.rollback();}
e.printStackTrace();
} finally {
if(session!=null){
session.close();}
session = null;
transaction = null;
}
i have tested for the blank servlet that has the only one console printing statement. it works fine but it not work for above servlet.
am i on the right track here ?
how the server will handle the such servlet for above 500-800 threads ?
Upvotes: 0
Views: 1289
Reputation: 16066
Varsha;
2000 threads sounds like too many threads. You did not mention how many processors your target machine has, but I believe that for Tomcat, the empirical maximum per processor is around 200-250, so conservatively, you would need 10 [reserved (+)] processors to support 2000 concurrent threads.
(+) I say reserved because obviously you would need processor capacity for other stuff as well.
More importantly, keep in mind that each thread needs to acquire, use and release a database connection, so it is unlikely that either your application server or your database can achieve or sustain this sort of throughput. If you simply attempt to allocate these resources, you will swamp your system and start getting errors like the one you outlined.
I would reconsider your approach with the following premises in mind:
Cheers.
PS. This is a good presentation on how to calculate the number of required nodes to satisfy a specific quantity and content of traffic.
Upvotes: 1