Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Programmer > Re: Data Storag...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 24 Topic 52608 of 55513
Post > Topic >>

Re: Data Storage Issue (Basic Issue)

by Tom Anderson <twic@[EMAIL PROTECTED] > May 9, 2008 at 06:19 PM

On Fri, 9 May 2008, Srini wrote:

> Which is more efficient? Why?? Storing or Reading a file in database or 
> on to disk in a web server environment? considering all things like 
> network, connections, memory are ideal.
>
> My knowledge says that using database is more efficient but few my 
> pierce argue that storing in disk is more efficient when concurrent 
> people accessing it...

Databases typically store their data in a file [1]. That means that a 
file-based solution can always be at least as fast as using a database, 
because it can just do what the database does.

The problem is that to make a file-based solution that's as fast as a good

database and also provides things like transactionality, you may have to 
write code that's as complex as a database. Which is not good.

If you're mostly reading your data, so you don't have to worry about 
concurrency and transactionality, and you have a straightforward 
organisation (like having fixed-size records which you can refer to by 
index in a sequence), then you can write a simple file-based 
implementation that should be faster than a database, because it avoids 
the overhead and complexity.

There's nothing in the java libraries, that i'm aware of, for doing this 
kind of non-database structured file access. There are things for some 
texual formats, like XML and properties files (remember those?!), but 
nothing like DBM or COBOL's record-oriented files. There are third-party 
libraries, though - see Berkeley DB, Java Edition:

http://www.oracle.com/technology/products/berkeley-db/je/index.html

and JDBM:

http://jdbm.sourceforge.net/

It's also not that hard to write your own fixed-size record manager, and 
not that hard to layer variable-sized records on top of such a thing.

There's also an excellent trick for using the unix filesystem as a 
database by storing data in symbolic links: the path of a symlink is 
actually an arbitrary text string, so you can store information, rather 
than an actual path, in it. Gives you hierarchically organised, 
string-keyed records of up to a kilobyte (YMMV) without any actual file 
IO!

A performance question for the wise: i hacked up a little fixed-size 
record manager, and wrote two backends, one using RandomAccessFile, and 
one using a NIO MappedByteBuffer. For both, i provided a way to flush to 
disk after each write - with RandomAccessFile, via getFD().sync(), and 
with MappedByteBuffer with force(). Timings to do a batch of reads and 
writes (100 000 operations, 75% reads, on 10 000 records of 256 bytes 
each; a different random pattern each time, on a machine doing nothing but

this and playing MP3s):

Implementation  	Flush?	Time (ms)

RandomAccessFile	no	733
RandomAccessFile	yes	20659
MappedByteBuffer	no	63
MappedByteBuffer	yes	33087

The mapped file is an order of magnitude faster without flu****ng, but 50% 
slower with. Any idea why?

tom

[1] Okay, so seriously heavyweight ones use disk extents/partitions and 
bypass the filesystem; how much of a difference does that make?

-- 
.... but when you spin it it looks like a dancing foetus!
 




 24 Posts in Topic:
Data Storage Issue (Basic Issue)
Srini <Srinihello@[EMA  2008-05-09 07:37:29 
Re: Data Storage Issue (Basic Issue)
Tom Anderson <twic@[EM  2008-05-09 18:19:34 
Re: Data Storage Issue (Basic Issue)
Lew <lew@[EMAIL PROTEC  2008-05-09 23:01:21 
Re: Data Storage Issue (Basic Issue)
Wayne <nospam@[EMAIL P  2008-05-11 14:56:24 
Re: Data Storage Issue (Basic Issue)
Lew <lew@[EMAIL PROTEC  2008-05-11 15:38:41 
Re: Data Storage Issue (Basic Issue)
=?UTF-8?B?QXJuZSBWYWpow7h  2008-05-11 22:59:14 
Re: Data Storage Issue (Basic Issue)
Lew <lew@[EMAIL PROTEC  2008-05-11 23:07:41 
Re: Data Storage Issue (Basic Issue)
=?UTF-8?B?QXJuZSBWYWpow7h  2008-05-11 23:03:03 
Re: Data Storage Issue (Basic Issue)
Rex Mottram <rexm@[EMA  2008-05-09 23:14:01 
Re: Data Storage Issue (Basic Issue)
Tom Anderson <twic@[EM  2008-05-10 14:17:04 
Re: Data Storage Issue (Basic Issue)
Eric Sosman <esosman@[  2008-05-10 09:45:18 
Re: Data Storage Issue (Basic Issue)
Lew <lew@[EMAIL PROTEC  2008-05-10 10:02:02 
Re: Data Storage Issue (Basic Issue)
Eric Sosman <esosman@[  2008-05-10 13:33:34 
Re: Data Storage Issue (Basic Issue)
Lew <lew@[EMAIL PROTEC  2008-05-10 18:04:49 
Re: Data Storage Issue (Basic Issue)
Patricia Shanahan <pat  2008-05-10 15:30:32 
Re: Data Storage Issue (Basic Issue)
Eric Sosman <esosman@[  2008-05-11 09:20:52 
Re: Data Storage Issue (Basic Issue)
Mark Space <markspace@  2008-05-14 19:30:01 
Re: Data Storage Issue (Basic Issue)
=?UTF-8?B?QXJuZSBWYWpow7h  2008-05-31 21:17:31 
Re: Data Storage Issue (Basic Issue)
Roedy Green <see_websi  2008-05-11 03:51:09 
Re: Data Storage Issue (Basic Issue)
Tom Anderson <twic@[EM  2008-05-11 15:37:34 
Re: Data Storage Issue (Basic Issue)
Lew <lew@[EMAIL PROTEC  2008-05-11 11:20:21 
Re: Data Storage Issue (Basic Issue)
John W Kennedy <jwkenn  2008-05-14 11:45:49 
Re: Data Storage Issue (Basic Issue)
Lew <lew@[EMAIL PROTEC  2008-05-14 23:46:05 
Re: Data Storage Issue (Basic Issue)
=?ISO-8859-1?Q?Arne_Vajh=  2008-05-11 23:08:03 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 18:32:40 CST 2008.