• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which one would be Optimal? ( Map Vs Data Base)

 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

Back, into this forum, after quite a long time.

Now, I have a scenario, where some information is stored in Database.

I fetch the information, and store the data in a Map. Later at some point of time, I need information, which would be a sub-set of what is in the Map.

Now, would it be wise, to use the Map to hit the Database and get them?

What would be the several constraints that would be considered here?

Thanks a lot, in Advance for your help.

Cheers,
Swamy
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, using the Map would be an in-memory operation (CPU-bound as they say), while the Database operation would be an IO operation (ergo, IO-bound). As you probably know, any IO stuff a computer does is slow[er]. So, it would definitely be more efficient (memory-wise) to use the in-memory Map at that point.

There are probably other issues though, if you're asking this question at all.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We cache things from the database into maps in memory all the time. Every time it's a gamble that the peformance improvement is worth the memory cost. If we run out of memory, we may have bet too much on caching.

If the data is not totally static - unchanging between system restarts - we need a way to clear or reload the cached data. We went to some effort with a web UI and an API to make this work across a cluster of servers.
 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pals,

Many a thanks to you.

Got the idea.

Cheers,
Swamy
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some references on caching:
http://jcache.sourceforge.net/ <- generalized caching ref JSR 107
https://whirlycache.dev.java.net/ <- recent release, claims great speed
Enjoy!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic