• Post Reply Bookmark Topic Watch Topic
  • New Topic

Web Application w/ Massive Users, need Threads?

 
Unnsse Khan
Ranch Hand
Posts: 511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marty,
My colleague and I are itching to write a chat room (which would be in the form of an Applet) embedded in a JSP page. My question to you is, how do we prevent the page from crashing - due to many users (100,000+) accessing the same page at once?
Do I use the single thread model? Or do I use multiple threads to manage the concurrency? In addition, do you think Java Web Start would be a more viable solution?
Thanks again,
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course you have to use mulitple threads to manage the concurrency... but one important point can be seen in the article below...
Many internet browsers allocate a thread for each applet on a page, using that thread for all calls to the applet's major methods. Some browsers allocate multiple threads or a thread group for each applet. Multiple threads share more of their enrivonment with each other than singletasking. Threads may be distinguished by the value of their program counters and stack address while sharing a multiple address space and set of variables. The threads that the major methods are called from depends on the application that is running the applet, so that it is easy to kill or get the control part or all the threads that belong to a particular applet.
It is difficult to directly discover the flaws in the design and implementation of internet browsers. The current research is to design a risk analysis method to exploit weaknesses in the type checking of threads and Java applets and system-level flaws, in order to prevent the vulnerabilities caused by Java/applet applications, that possibly leak sensitive information, corrupt an application environment and cause great inconvenience.
 
Unnsse Khan
Ranch Hand
Posts: 511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like I said before, this question was directy asked for Mr. Hall to answer.
Thanks for giving your two cents, nonetheless...
 
Marty Hall
Author
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My colleague and I are itching to write a chat room (which would be in the form of an Applet) embedded in a JSP page. My question to you is, how do we prevent the page from crashing - due to many users (100,000+) accessing the same page at once?

Well, a couple of thoughts:
  • The server already uses multiple threads to handle requests. Concurrent access is a good thing since most of the server's time is spent doing I/O, so the server is basically sitting around most of the time waiting for the I/O to finish.
  • The server itself should also already be able to set a limit on the number of simultaneous threads: too many users should slow your server down, but not crash it.
  • Just because you have 100,000 people using your chat app simultaneously does not mean that you have 100,000 simultaneous HTTP requests. Presumably they access the initial page only infrequently.
  • The actual chat data (from the applet) need not be sent via HTTP. You can write your own server to handle that as long as that server is on the same host as the system that served up the applet. For example, the applet could use RMI or JDBC to talk directly to another Java app or a database. For high-traffic situations, this approach for the chat applet is preferable to HTTP tunneling, since HTTP requests are connectionless and thus with HTTP you have more overhead of establishing connections and telling the server who you are. On the other hand, you don't have to establish your own server if you use HTTP tunneling.


  • Do I use the single thread model?

    No! Never use SingleThreadModel. As discussed at length in the book, it has grave deficiencies (and is in fact deprecated in servlets 2.4/JSP 2.0). First, it will hurt your performance tremendously: you want concurrent access in this situation so the dead time while I/O is happening is not wasted. Second, the race conditions that SingleThreadModel and the related isThreadSafe="false" business supposedly prevent are not really prevented because servers can either serialize requests of use pools of instances (boooooo!). Forget SingleThreadModel. Forget isThreadSafe="false".
    Or do I use multiple threads to manage the concurrency?

    Yes, definitely. Fortunately, the system will do this automatically for the HTTP requests. You'll have to do it yourself if you opt for a separate server to handle the chat data.
    In addition, do you think Java Web Start would be a more viable solution?

    Since hyou are already using applets (and presumably requiring the JDK 1.4 plugin), I don't see what Java WebStart buys you.
    Cheers-
    - Marty
     
    Unnsse Khan
    Ranch Hand
    Posts: 511
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Marty,
    Thank you very much for such a detailed response... My colleague and I are
    very appreciative. I e-mailed your response to my colleague...
    Thank you!
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!