• Post Reply Bookmark Topic Watch Topic
  • New Topic

Web Counter  RSS feed

 
Felix Ng
Greenhorn
Posts: 9
Eclipse IDE Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did anyone tried to write a web counter (to display the hit count) and deploy to a server cluster?

How did you "synchronize" the counter? How about performance?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're going to have to make all the web apps use a common resource to save the count value - most "clustered" web applications "cluster" the web and any code parts - servlets, JSPs, HTML pages, EJBs, etc. - however, the "back end" usually talks to a single data store - i.e. a database. Databases *can* be clustered too - but this is usually provided through the database itself, so you should still be able to pretty much access it as if it were a single data source.

In a non-clustered environment, you may be able to save page counts in a JavaBean bound in Application scope - in a clustered envirnoment, there's an Application scope for every copy of the Web App in the cluster. So you have to save the count in some kind of resource outside of the web application itself. The easiest resource to use for this would be the database - through whatever persistence scheme you use - direct DB access, EJBs, Hibernate, etc. You could also technically use a remote service (through RMI, CORBA, Jini, etc.) to keep track of this, because if there is only one instance of the service, all copies of the web application will get a remote reference to the same service. If you're trying to coordinate access to a common resource, you'll also need to do some thread handling (through the use of synchronized methods/blocks to ensure only one of the web apps at a time is updating the count. The database approach is, by far, the more common approach to this - mainly becaue most web apps use a database already.
 
Felix Ng
Greenhorn
Posts: 9
Eclipse IDE Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your suggestion...

This simple question turns out become a very complicated one...

In order to miminize the database WRITE, i am going to do some fetch and update the underlying database every 60seconds. While every "hit count" will increment a static value in the Counter bean.

Really want to know more if there is any package (either opensource or not) to handle this problem
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!