Hi Geert Van Damme,

Thanks for the reply.  So, if I use DB connection
pooling, writing to DB for each session is not
something to worry about?  Hmmm, still worries me, but
I guess I can only try it out.

I've been working on DB connection pooling actually,
will post another message again if I encounter any
problem.

Thanks,
June


>
> One way I can think of is to map a servlet to the
root(where the
> index page is) and for each new session(not for each
request for
> index page, because I don't want to include those
accesses made
> by people who are already at the site) that gets
created I
> increment the visit count in the database.  Same
thing goes for
> the shopping cart.  However, I think this approach
to write to
> database each time is costly in terms of db access.
>

That's the way to do it.
One important thing however is: Use DB Connection
pooling !!!!!

Without the overhead of creating a connection, how
many inserts do you think
you can do?
Did you test it? Depending on hardware, OS, DBMS,
server load .... it might
range between 300 and 50.000 per  second. (very rough
figures, just my
personal experience, YMMV)
If you have a website that handles over 300 new
visitors per second, or 300
shopping cards per second, you're a rich man ;-). In
that case you can
easily afford a whole server parjk and several
developers.

I see you're talking about 150 or 200 per day. IMO, I
wouldn't care about
your problem up till 500.000 hits per day.

The first steps then are:
- Buy bigger HW
- Move the DB to a dedicated server
- Load balance the app server.
- Load balance (HW) the web server)
- Sell your entire product and retire ;-)



> Another way which I think is more desirable is to
store those
> counts in the servlet until the servlet gets
destroyed.  I guess
> I can write to database in the destroy method and
get the latest
> count from database in the init method of the
servlet.  However,
> since what I want is the daily counts, not just the
sum of
> everythings, how do I differentiate them and write
yesterday's
> count to yesterday's column and write today's count
to today's
> column, especially when I don't have control over
when the
> servlet is destroyed?
>

You do have control over it (unless the server crashes
or something, so it's
not 100% safe)
But the most important thing is: don't try to optimize
speed unless you did
proper profiling!





> Hang on, how about this?  I declare a vector(since I
don't know
> how many Dates I will be storing until the servlet
gets
> destroyed) as an instance variable, in the doGet
method I
> instantiate a Date for each Session and compare it
with the last
> Date element in the vector.  If it's the same date,
I increment
> the count that belongs to that Date, and if not, I
add another
> Date element with new count.  In the destroy method,
I write what
> is in the vector to the database.  In the init
method, I get the
> last date from db with the count and store it in the
> vector......Would this work?  Or is there an easier
way?  Am I
> making something that is so easy compliated?

Yes, you're making it way too complicated ;-)
Make it work first, when you see you really need to
aggregate the inserts (I
doubt it) then rebuild your approach. There's a chance
< 1/100 that you'll
ever need to.

Geert Van Damme


http://messenger.yahoo.com.au - Yahoo! Messenger
- A great way to communicate long-distance for FREE!

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to