I want to devlelop a chat website using JSP/Servlets and Tomcat. I have following questions:
Can the website handle load (1000 people at one time) without slowing down?
Will it cause the website to slow down? What is the ideal server configuration for this kind of website? Note that I don't have a huge budget to host.
How can I implement server push?
Will PHP or JSP be ideal for such website?
Depends entirely on hardware/software. It will obviously run faster on a Quadcore Xeon server from 2010 than an Octa Pentium Pro server from 2000. It will also obviously run and scale better if the code is written efficiently and the server is configured to an optimum.
See 1. I'd suggest to use the NIO connector in Tomcat.
You can use Comet for this. In Tomcat, it's available by AIO (Advanced IO).
Depends entirely on your own skillset. But technically, JSP/Servlet will likely scale better with this.
why re-invent the wheel? Just use an XMPP client. Here are some good clients and claros in particular is a good one.
Related
I have to develop a small web application which would be running on a embedded device.
There are many light weight servers like thttpd, lighttpd. The functionality I want is something similar to router/modem configuration page. I am using mpc5200B (http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPC5200B). It'll have a Linux kernel on it.
I am not able to decide on the server and programming language to use. Should I just run an embedded apache server and use JSP/servlets for programming as I believe the chip has enough resources.
Any hints/help/insights would be helpful. Thanks!
I've never seen routers with JVM inside.
From my own experience - every router I've configured had a PHP inside web-admin application.
For smaller embedded systems, based on single-chip microcontrollers, you might want to consider the lwIP TCP/IP stack. There is a YouTube video that shows an embedded web server running on a small embedded ARM Cortex-M3 board with SSI (server-side includes) and CGI (common gateway interface) capabilities. This means that you can generate HTML dynamically (SSI) and you can accept commands from standard HTML forms (CGI). All this without a need for running Java in your browser.
I would suggest Apache + PHP. Even you have enough resource, whether the technology is stable or not still one of the consideration.
Apache + PHP is a very stable combination.
I am not sure, seems the device come with it's own linux.
The micromonitor (uMon... http://www.umonfw.com) package has an LWIP application that includes the HTTP server that started from LWIP contributions; however I modified it quite a bit so that it would serve files out of TFS (basic FFS that comes with uMon). Plus I added some basic hooks to support SSI-like stuff and some form-to-target interaction. Works ok and doesn't need an RTOS; but for really small systems it still needs to be "tuned". So...
I am now working on a condensed version of that package (called uMon-M) for use on devices with very small footprints like the Cortex-M3/M4 stuff. As of this writing, I have it ported to the "Simple-cortex" (http://www.brc-electronics.nl) based on an NXP-LPC1769 (Cortex-M3). The boot monitor itself is a major subset of uMon, but still has all the same fundamental capabilities (FFS, scripting, UDP/IP, etc..). Most of my effort at this point is in the HTTP server as a user interface for an application. It currently works I'm just trying to make it smaller; but still have some reasonable ability to serve dynamic web pages. I've got it hooking to Web Sockets and a very basic SSI-like facility so that the html pages can be more dynamic. Try it, it works as is, and will hopefully just get smaller. It would be great to get some folks looking at this with me for collaboration.
In case of 8- and 16-bit microcontrollers you can use micro IP (uIP). It implements TCP/IP protocol and it is written in C and requires few kilobytes of RAM ( good striped version requires only 200 bytes of RAM). Moreover, uIP is open source TCP/IP stack.
Have you considered Snorkel or Appweb?
Or Raspberry PI. Cost is less than $50, and you can run Linux with a LAMP stack, iptables, etc.
Background of the web application:
I am using java/spring-mvc/tomcat to provide my web service as well as exposing my restful API to mobile clients. I am happy with everything on the web surface right now. The problem is that my application has a really heavy computing process at its core, which invokes a separate Java program to process the images and return computed data back to the web service.
It sometime eats up lots of my EC2 instance memory, or causes an exception that shuts down my Tomcat7 server.
Question:
Right now everything is running under same tomcat7 container, and I am seeking a solution to decouple those two so that I can install them in different server, perhaps find a high memory server for computing program alone.
What are the options out there that allow me to decouple them and improve scalability and stability?
Update:
I can invoke computing engine programmatically or from command line.
Update2:
I have done some researches based on the answer. When I read on another post about What exactly is Apache Camel?, I feel I should probably learn a little more about EIP patterns. Hopefully, it is not overkill.
Solution based on suggestion
After reading through the EIP concept, camel in action, activemq, I finally come up with a solution. It might not be elegant, but it's working. Suggestion and comments would be appreciated!
I wrote a queue router based on apache-camel , connecting to activemq broker and running as standalone program in one server. The computing engine running in standalone container and the router is responsible to process jms requestor from my spring container in web server. Later on I just need to config load balance for computing engine from camel if further intensive computing is needed.
The one which are pointing right now is adding more hardware. You need to think through if this solves your problem. Eg: If you are using a 32 bit JVM there are limitations on how much heap size you can specify. If you are lucky to have a 64 bit JVM them then you will have a bigger room for memory. But there is always the possibility of using too much CPU where your application becomes unresponsive.
I prefer breaking the compute intensive tasks into jobs and work them out in a seperate JVM. Persist your jobs in a datastore/JMS so that they do not get lost. Be careful if you are doing DB updates from those jobs to avoid any locking.
If I understand correctly, it seems you need a load balancer.
Have a load balancer to route to one of multiple instances of your webservice/compute engine. You can achieve this using an esb, routing engine, clustered, master-slave, distributed-cache etc most of them interrelated.
And you can also spin up additional nodes realtime on EC2 based on load.
Else, if the task can be broken, then delegate it to multiple nodes/services. You will need some orchestration mechanism.
There are open source solutions that can address 1 and 2 above.
Does the backend work synchronously? I mean, when the mobile clients requests something do they have to wait for the backend to do a lot of processing?
If yes, you can grow horizontally, putting more worker nodes (backend webapps) and a front Nginx or any balancer. It's the fastest way.
Do you have reutilizable data? if yes, you can use something like memcached.
Hope it helps, if you give us more information I'm pretty sure that we will provide better advice.
I would like to make a chat server in java, but I don't know if it's a good idea, because I can't understand what is the maximum of the users of which can handle...
I'm using NIO
I don't know your stance on third-party products, but Jabber is always an option and has been tried and tested by some of the industry's biggest sites. It's an XMPP-compliant server and can handle things like clustering, load-balancing, etc.
A typical IO or NIO server can handle between 1K and 10K concurrent connections with Java 6. NIO doesn't make as much difference to the maximum connections as it did with java 1.4. Assuming that the chat is light weight you should be able to reach 10K on a modest server.
If you just need 1K connections, I would use IO as this tends to be simpler to use and will do the job.
ICEpush is still in alpha version, so I am curious if it is appropriate to use in web application on tomcat or tc server with many clients. How many users can be serviced by this technology with small delay? I'm curious what is delay under 100, 1000 and 10000 clients.
What else Java library for reverse AJAX is worth to look at?
Purely for the fact that if it is software in 'Alpha' state, I would suggest against it and I would be surprised if anyone admitted using it in a production environment.
If you are just trying to find out what load it can handle, then you could easily find out by writing a test case to exercise the code and run it locally. This advice of course doesn't address network latency nor horizontal scalability.
We're come across a problem here at my company and I'm trying to find the best solution.
Software was recently purchased that utilizes a Java program to get the tax for a certain shipment. The site that needs this was written in PHP4. How can I communicate between the two?
It was suggested to use files to communicate but that was horribly slow since the Java program needed to be recompiled every time. So, what is the best solutions to this:
Create a mutli-threaded Java server and use PHP to send/receive the info.
Some other type of file-writing method
Something cool that I dont even know about.
Thanks in advance!
Edit:
I understand the importance of web services but why would this be more efficient that using a mutli-threaded socket-based java server? The only thing connecting to this web services will be my PHP program, no one else. It seems like it might be overkill for my simple task. Am I mistaken? If so, why? Thanks.
Wrap the Java program in a Web Service, and invoke it from PHP. You can even use caching in the Web Service, to optimize performance.
Why not dump the info into a database and have some sort of schedualed job read from it once and a while?
You can always use Quercus which allows you to run PHP in a Tomcat Servlet container.
Web Services is the elegant solution. But in many cases I found much practical to go for a quick-and-dirty solution: start a Java server that communicates using a lightweight communication protocol (none of the heavyweight stuff like XML from Web Services) - example: Apache Thrift. The write a very light client, that takes parameters from command line and writes the output to the console. The client can be in Java or even in other languages, like C++ (Apache Thrift supports that). Then you call the client with system() or with exec() from PHP.
This is not a solution I would ever recommend for production, but it's great for prototyping. Quick and dirty and flexible and extremely modest learning curve (if you already use light-weight communication between your Java processes).
Since you are using PHP4, you may want to just set up a tomcat server that is on a closed network, or just local on the machine of interest, and have it communicate with a servlet, that way you don't have to write a multi-threaded server and deal with creating a communication interface.
If you can upgrade, this page has two other options that may of interest:
http://us3.php.net/manual/en/intro.java.php
Give a look at Quercus
Quercus is Caucho Technology's fast, open-source, 100% Java implementation of the PHP language
I never used it though,
Web Services is the answer. Here's a nice intro link. Your problem is the very reason web services came to the forefront - communication between systems that couldn't ordinarily communicate.
What a web service is essentially going to do is send XML between the PHP and the Java systems. You're going to have to establish an interface for the two, which might be more difficult at the upstart, but you'll reap the benefits later on. In either case, it will be much faster than reading and writing files on the server. Disk I/O are the major bottlenecks on any server.
I may miss something, but if your java program output the needed values, can't you just start the java program from php using exec (http://dk.php.net/manual/en/function.exec.php)
Use the PHP/Java Bridge from sourceforge.net. It is mature, fast and easy to install.