You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by Joseph Grace <oc...@serv.net> on 2004/09/01 08:09:00 UTC
java1.4.2 "rws" mode fix: LogToFile.java diff
Dear derby-dev:
Apologies for any faux-pas. I'm not sure what diff to use, so I used
diff -c2 to make the following patch.
I made this change to get derby running under java 1.4.2 on Mac OSX
10.3.5 (i.e., the latest and greatest version). I believe the patch
fixes a bug where the database gets created twice unnecessarily. This
bug was causing the simple instructions example ("connect
'jdbc:derby:test;create=true';") to choke with a file already exists
error. Apparently, this situation crops up whenever "rws" mode was
available, and would not occur prior to 1.4.1 (since apparently "rws"
was too buggy to use until 1.4.2 and, so, was avoided). Anyway, here's
what I believe is a fix for that issue and, at least, got the database
to initialize per instructions on my system.
BTW, I also fixed some typos in the comments and tried to make the
comments agree with the changes.
Cheers,
= Joe =
*** LogToFile.java.org Thu Aug 26 12:07:32 2004
--- LogToFile.java Tue Aug 31 22:19:16 2004
***************
*** 889,902 ****
lastFlush =
endPosition;
! //if write sync is true
, prellocate the log file
! //and reopen the file
in rws mode.
if(isWriteSynced)
{
! //extend the
file by wring zeros to it
preAllocateNewLogFile(theLog);
theLog.close();
theLog=
privRandomAccessFile(logFile, "rws");
! //postion the
log at the current end postion
!
theLog.seek(endPosition);
}
--- 889,902 ----
lastFlush =
endPosition;
! // if write sync is
true , preallocate the log file
! // and reopen the file
in rws mode.
if(isWriteSynced)
{
! // extend the
file by writing zeros to it
preAllocateNewLogFile(theLog);
theLog.close();
theLog=
privRandomAccessFile(logFile, "rws");
! // position
the log at the current end position
! theLog.seek(
endPosition);
}
***************
*** 3004,3008 ****
// don't need to try to delete
it, we know it isn't there
! StorageRandomAccessFile theLog =
privRandomAccessFile(logFile, "rw");
if (!initLogFile(theLog,
logFileNumber, LogCounter.INVALID_LOG_INSTANT))
--- 3004,3008 ----
// don't need to try to delete
it, we know it isn't there
! StorageRandomAccessFile theLog =
privRandomAccessFile( logFile, isWriteSynced? "rws": "rw");
if (!initLogFile(theLog,
logFileNumber, LogCounter.INVALID_LOG_INSTANT))
***************
*** 3015,3028 ****
lastFlush =
theLog.getFilePointer();
! //if write sync is true , prellocate the log file
! //and reopen the file in rws mode.
! if(isWriteSynced)
{
! //extend the file by wring zeros to it
! preAllocateNewLogFile(theLog);
! theLog.close();
! theLog= privRandomAccessFile(logFile, "rws");
! //postion the log at the current log end
postion
! theLog.seek(endPosition);
}
logOut = new
LogAccessFile(theLog, logBufferSize);
--- 3015,3026 ----
lastFlush =
theLog.getFilePointer();
! // if write sync is true , preallocate the log
file
! // and reposition cursor.
! if( isWriteSynced)
{
! // extend the file by writing zeros to it
! preAllocateNewLogFile( theLog);
! // position the log at the current log end
position
! theLog.seek( endPosition);
}
logOut = new
LogAccessFile(theLog, logBufferSize);
More on open("rws"/"rwd"), O_{D,}SYNC, metadata, and OSX JVM
Posted by Joseph Grace <oc...@serv.net>.
Dear derby-dev:
Given the derby issue on OSX of preallocate+"rws" file open()'s
failing, I did some more research (google) on the issue of "rws"
metadata. I don't think it's quite as mysterious as it may have at
first seemed (though there are still open questions of O_SYNC
interpretation on OSX and other advanced operating systems). In any
case, take the following with a grain of salt and chime in if you can
with additional corroboration or information.
I gather that metadata typically refers to the update of the directory
information associated with the contents of the file. So, if a
database gets updated, then the, e.g., "modified time", should also be
updated (in the directory entry for that file) as well. If that's
true, then:
"rwd" updates just the contents ensuring full data retrieval, but
glosses over all but essential metadata (i.e., new block allocation
metadata is handled, but directory timestamp updates are skipped).
"rws" updates not only the contents, but also non-essential
metadata (directory timestamps (e.g., "modified time", "access time")
et al.).
I'm not sure it's that simple (since the Java most likely relies on the
underlying OS support for O_SYNC, O_DSYNC or their analogues) but at
least it narrows the focus a bit. I get this impression from a variety
of sites, but this URL is perhaps the clearest I found:
http://publib16.boulder.ibm.com/doc_link/en_US/a_doc_lib/aixprggd/
genprogc/fileio.htm#wq222
under "Synchronous I/O" where it mentions:
-=-
• Specified by the O_DSYNC open flag. When a file is opened using the
O_DSYNC open mode, the write () system call will not return until the
file data and all file system meta-data required to retrieve the file
data are both written to their permanent storage locations.
• Specified by the O_SYNC open flag. In addition to items specified
by O_DSYNC, O_SYNC specifies that the write () system call will not
return until all file attributes relative to the I/O are written to
their permanent storage locations, even if the attributes are not
required to retrieve the file data.
-=-
IOW, I believe O_DSYNC should protect data integrity even if it
(purposely for performance reasons) avoids updating all associated
metadata. O_SYNC is good too, but (at least according to above) you
pay a performance penalty. So, I think O_DSYNC may be a worthwhile
substitute for O_SYNC as long as the incidental metadata is not all
important.
Bottom line: a production d/b with performance goals likely uses
O_DSYNC (since O_SYNC is overkill if you just need to protect the
data).
-=-
I also looked a bit into OSX for O_DSYNC in search of "rws"/"rwd"
insights. I downloaded the sources for Darwin (OSX's BSD
underpinnings). It appears that OSX only has an O_SYNC flag. The
Darwin code says that O_DSYNC is not supported yet. So, in theory,
O_DSYNC should degenerate to O_SYNC.
Unfortunately, even though I was able to look at the Darwin sources, I
do not have the Apple Java sources to see how the flags are treated in
OSX's JVM1.4.2. (There is no JVM1.5 (Java Tiger) (pre)release yet, so
I can't test against a newer version of Java (yet).)
Having said all that, the question still remains why does O_SYNC behave
differently than O_DSYNC in the OSX JVM (especially since only O_SYNC
exists in Darwin). I don't know. The two knee-jerk hypotheses I have
are:
1. jvm:O_SYNC is using darwin:O_SYNC, but jvm:O_DSYNC is
darwin:no_sync (that would be bad). So, if you need O_DSYNC, you
better use O_SYNC (which fails mysteriously when file is preallocated).
_or_
2. jvm:O_DSYNC uses darwin:O_SYNC (as it should), and jvm:O_SYNC uses
darwin:O_SYNC and also synchronizes OSX metadata files like .DS_Store
and resource forks (and ends up taking exception under ambiguous
conditions in "rws" mode).
I don't know enough about typical O_SYNC, .DS_Store, or resource forks
to know the answer to this mystery.
Bottom line: I know neither whether jvm:O_DSYNC protects data on
OSX/Java1.4.2 (as it should), nor why jvm:O_SYNC is any different than
jvm:O_DSYNC on OSX/Java1.4.2 (especially when jvm:O_DSYNC should
degenerate to darwin:O_SYNC since Darwin only has O_SYNC).
Anyway, that's probably an excess for one post. If anyone has insight
to any of these questions (e.g., anyone from the OSX java team! ;-),
please share.
Cheers,
= Joe =
Re: java1.4.2 "rws" mode fix: LogToFile.java diff
Posted by Daniel John Debrunner <dj...@debrunners.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Jan Hlavatý wrote:
| Daniel John Debrunner wrote:
|
|
|>Cloudscape has always been written against
|>the Java specs, not making any assumptions on how various Java
|>implementations implement the spec. I would hope Derby would follow this
|>idea.
|
|
| Even Sun has to work around bugs.
I wasn't referring to bugs, but the use of "rws" vs. "rwd". "rwd" by
definition does not sync meta data (without defining what metadata is)
and thus on some platforms may cause recoverability problems.
| I can see two ways to handle known bugs:
|
| 1. Automatic way:
|
| 2. Known bugs list:
I agree, and unfortunately it will always be a combination of the two,
because bugs will be found in JVM's that affect existing Derby releases.
And no, the committers do not have commit access yet. Ken Coar sent an
e-mail a few days ago explaing the ASF secetary is on vacation.
Dan.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFBOy7qIv0S4qsbfuQRAiqtAJ9u79GRQjd62r2JlpNVoWfCuOk4SACdEu8l
qFtLX05fM6YE7hPzdN4ELXw=
=ZF1K
-----END PGP SIGNATURE-----
Re: java1.4.2 "rws" mode fix: LogToFile.java diff
Posted by Jan Hlavatý <hl...@code.cz>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Daniel John Debrunner wrote:
> Cloudscape has always been written against
> the Java specs, not making any assumptions on how various Java
> implementations implement the spec. I would hope Derby would follow this
> idea.
Even Sun has to work around bugs. Telling users its not our fault will not help them.
For example, the fact that log forcing does not currently seem to work correctly on OSX
JDK 1.5rc1 and thus users may have higher probablility of data loss in crash
when running Derby on OSX is something they will really want to know in advance ;-)
Reliability is key in database systems.
I can see two ways to handle known bugs:
1. Automatic way: check for exact JVM version that is known to have the bug,
then apply workaround when that version of JVM is found. Assume unknown JVM does not have the bug.
This is the way Sun recommends for working around bugs in JDK.
This could be handled by same mechanisms that configure Derby for different JDK versions.
Or it could even be handled as part of installation process, so it wouldnt have impact
on runtime performance.
Of course, only some bugs can be worked around - if bugs are too serious
and impossible to workaround, Derby should not run and issue appropriate warning, instead of
failing because of the bug.
That way, users wont be bitten by known bugs, and will be happy.
This would also be good solution for environments where users are not free to pick
the JVM they use.
This is ideal solution for users, and bad solution for developers ;-)
2. Known bugs list: This would require a list of JVM versions with known bugs that
affect Derby, possibly on a web page, or a section in readme file.
Users would have to be directed to it to check their environment.
This requires no code in Derby, it's just and administrative measure, and thus an easy one ;-)
Of course, there may be other bugs than JVM bugs, which would be nice to be aware of too.
Jan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iQEVAwUBQTsot3FDePgyse5HAQJ7FQf/eMpm3dPCCqWE6o3RsOAn9rhBabw7rA10
W88HNjIfLMShaX9DX4YOUFLF+Hyit+VEyqaPH9NE+zOsXQe5EjNQ+DS79W8zQdB7
aG9TdlpedpwTshIddvEjr9NRYg8a0r5jhZUEccvqPO1km953PW5XWAeooi+lst6E
rmfi6FTyRKMZNib/JW4X+nzTjhVL5+PAJGVL3XRA0ApuS71sKn4lSH1RtGFoYfec
aBjOfOxAEY23HcLmJxfzOoxX8KcOEtXIAJatLYF5F0lWBI2POzAGfNoaN5b6SdBT
PglWFkfpeMSs+0z0NwQ23ybFWqxKeXS4LYEOdDlG9u9FS6xzMKim0w==
=Pkv5
-----END PGP SIGNATURE-----
Re: java1.4.2 "rws" mode fix: LogToFile.java diff
Posted by Daniel John Debrunner <dj...@debrunners.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
| On Sep 3, 2004, at 6:33 PM, Joseph Grace wrote:
|
|> However, I have experimented and discovered that "rwd" works (on OSX),
|> while "rws" does not work. The only difference appears to be that
|> "rws" writes metadata in addition to the content. Hmm...
Just wanted to add that performance is the secondary issue for the logs,
recoverability is the first. Thus "rws" may have been selected because
it does write the metadata whereas "rwd" does not. This is of course
complicated by lack of definition of metadata, thus the choice of "rws"
may be the safer of the two. Cloudscape has always been written against
the Java specs, not making any assumptions on how various Java
implementations implement the spec. I would hope Derby would follow this
idea.
Dan.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFBOeafIv0S4qsbfuQRAshpAJ9LvetUvk+fCQU5B9bpCN1REcFnSgCeNH6h
Iy6+G8LTaBBHdk3AM5rx5+U=
=q95f
-----END PGP SIGNATURE-----
Re: java1.4.2 "rws" mode fix: LogToFile.java diff
Posted by Joseph Grace <oc...@serv.net>.
Three clarifications (mea culpa) on my previous post.
On Sep 3, 2004, at 6:33 PM, Joseph Grace wrote:
> However, I have experimented and discovered that "rwd" works (on OSX),
> while "rws" does not work. The only difference appears to be that
> "rws" writes metadata in addition to the content. Hmm...
1. I need to be more specific. I'm talking specifically about testing
(a subset of) the Derby code using "rws" (access content and metadata).
"rws" results in "File not found" under OSX when trying to reopen an
existing file (even though it seems to work on other platforms) under
some not well defined circumstance. This is the bug/issue which
started this thread, but it's not clear where to place blame (OSX JVM,
Derby, or blameless ambiguity of
http://java.sun.com/j2se/1.4.2/docs/api/java/io/RandomAccessFile.html).
2. However it is interesting that, under the same not well defined
circumstance, "rwd" does work on OSX which may provide the desired
multiplatform workaround. That's what my patch does.
3. I should mention however that I'm not sure about relative
performance ramifications of the latest patches as I don't have a good
sense of the performance issues to begin with as the pertain to the
"rw", "rws", and "rwd" approaches. If someone could sanity check these
alternatives from a performance perspective, I'd appreciate it
(assuming the "rwd" patch even makes sense).
Cheers,
= Joe =
Re: java1.4.2 "rws" mode fix: LogToFile.java diff
Posted by Joseph Grace <oc...@serv.net>.
Dear derby-dev and mike matrigali:
> Do you have any time to write a test case of the I/O calls separate
> from
> derby? This has the feel of a JVM bug, but maybe the interfaces are
> not
> being used correctly. This is a relatively new feature in jvm's (and
> new code in derby) so could be a bug in either area.
Sure. Here's my guesswork/bugwork to get Derby running comfortably on
OSX given the latest discussion(s).
mike matrigali wrote (Thu, 02 Sep 2004 09:53:45):
> Joe I don't have access to an OSX 10.3.5. This error is strange, from
> my
> reading of the java interfaces and the code the first call is creating
> the file, and the second call should just be opening the existing file
> -
> and should not be getting a file exists error.
Yes. I read (presumably) the same docs at (FYI):
http://java.sun.com/j2se/1.4.2/docs/api/java/io/RandomAccessFile.html
To quote:
"r"
Open for reading only. Invoking any of the write methods of the
resulting object will cause an IOException to be thrown.
"rw"
Open for reading and writing. If the file does not already exist then
an attempt will be made to create it.
"rws"
Open for reading and writing, as with "rw", and also require that
every update to the file's content or metadata be written
synchronously to the underlying storage device.
"rwd"
Open for reading and writing, as with "rw", and also require that
every update to the file's content be written synchronously to the
underlying storage device.
Specifically, under "rw", it says "If the file does not already exist
then an attempt will be made to create it." Plus, "rws" (and "rwd")
say "as with "rw"", so autocreate should apply to them also.
However, I have experimented and discovered that "rwd" works (on OSX),
while "rws" does not work. The only difference appears to be that
"rws" writes metadata in addition to the content. Hmm...
I don't know what the metadata should be but...
Could this "rws" metadata explain the dual writes behavior someone
discovered on Windows using "rws" (i.e., one write for content file,
and one for metadata)?
Could this metadata write explain the "File not found" message (i.e.,
perhaps the metadata file is not found) when "rws" is used to open an
already existing (content) file (which has no matching metadata file)?
I don' t know if the OSX JVM "File not found" behavior is
correct/preferred/other (i.e., whether metadata file should be
autocreated, even if the content file already existed without a
metadata file), or whether it's just ambiguous (the docs at the URL do
not cover this odd case), or whether my hypotheses are misguided, but
it led me to the following.
> It would be nice if a work around can be found to get this up and
> running in the OSX environment but not have to pay the extra
> performance
> cost across all the other JVM's.
When I replace "rws" with "rwd", the code (seems to) works on OSX. I
presume it also works on:
> I have tested this on a sun jdk 1.4.2 and an ibm 1.42 on windows and I
> believe it has also been tested against a linux jdk 1.4.2.
but a double-check would be worthwhile if the patch seems appropriate.
To be consistent with this hypothesis, I (went out on a limb and)
replaced all (five) LogToFile.java occurrences of "rws" with "rwd".
I'm sure you'll sanity check that approach.
-=-
Also, along the way, I found what I believe is a subtle operator
precedence bug in DirFile4.java which prevented "rwd" from taking
effect (it became "rw" instead). So I offer a patch for DirFile4.java
as well. This time I used 'diff -c1' from the derby root directory
(hopefully more convenient to apply patches).
Two patches follow.
*** java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java.org
Thu Aug 26 12:07:32 2004
--- java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
Fri Sep 3 18:14:17 2004
***************
*** 897,899 ****
theLog.close();
! theLog=
privRandomAccessFile(logFile, "rws");
//postion the
log at the current end postion
--- 897,899 ----
theLog.close();
! theLog=
privRandomAccessFile(logFile, "rwd");
//postion the
log at the current end postion
***************
*** 933,935 ****
if(isWriteSynced)
! theLog
= privRandomAccessFile(logFile, "rws");
else
--- 933,935 ----
if(isWriteSynced)
! theLog
= privRandomAccessFile(logFile, "rwd");
else
***************
*** 1933,1935 ****
newLog.close();
! newLog=
privRandomAccessFile(newLogFile, "rws");
newLog.seek(endPosition);
--- 1933,1935 ----
newLog.close();
! newLog=
privRandomAccessFile(newLogFile, "rwd");
newLog.seek(endPosition);
***************
*** 3023,3025 ****
theLog.close();
! theLog= privRandomAccessFile(logFile, "rws");
//postion the log at the current log end
postion
--- 3023,3025 ----
theLog.close();
! theLog= privRandomAccessFile(logFile, "rwd");
//postion the log at the current log end
postion
***************
*** 4849,4851 ****
if(isWriteSynced)
! return privRandomAccessFile(logFile, "rws");
else
--- 4849,4851 ----
if(isWriteSynced)
! return privRandomAccessFile(logFile, "rwd");
else
-=-
I believe the following code was intended to preserve the "rwd" if
rwsOK==TRUE (as with the "rws" preservation). On that assumption and
to enable "rwd" to take effect (it was replaced with "rw" under
original code), I force intended operator precedence with an additional
pair of parens.
*** java/engine/org/apache/derby/impl/io/DirFile4.java.org Tue Aug
31 22:09:51 2004
--- java/engine/org/apache/derby/impl/io/DirFile4.java Fri Sep 3
17:23:12 2004
***************
*** 241,244 ****
// Assume that modes "rws" and "rwd" are not supported.
! if(!rwsOK && "rws".equals( mode) || "rwd".equals( mode))
mode = "rw";
return new DirRandomAccessFile4( (File) this, mode);
--- 241,245 ----
// Assume that modes "rws" and "rwd" are not supported.
! if( !rwsOK && ("rws".equals( mode) || "rwd".equals( mode)))
mode = "rw";
return new DirRandomAccessFile4( (File) this, mode);
-=-
I hope that all makes sense and proves useful.
Cheers,
= Joe =
Re: java1.4.2 "rws" mode fix: LogToFile.java diff
Posted by Suresh Thalamati <ts...@Source-Zone.org>.
Tested this case with a simple Java program that opens a file in "rw"
mode first and then reopens in "rws": mode similar to the
calls derby logging system makes. It also failed with the similar error
on latest jdk142 (build 1.4.2_05-1) from Apple:
Exception in thread "main" Java.io.FileNotFoundException: log.dat (File
exists)
Test program works fine on Win2k with jdk142. I think this is bug in
latest jdk142 from Apple. Work around for this problem is disabling the
write sync mechanism for transaction log. Write sync mode can be
disables by setting "derby.storage.fileSyncTransactionLog=true" in
derby.properties. When this property is set to true logging system
does file syncs on commits similar to what happens on jvms before jdk142.
Insert/deletes/updated ..etc can also fail on databases that were
created with earlier jvm's when
booted with the latest jvm because log switch also make similar I/O
calls. If write sync mode is disabled on these
database, they will work fine.
Write Sync Test Java Program:
import java.io.*;
/**
* Test synchronous writes on MAC with JDK1.4.2(updated 1).
*/
public class TestWriteSync {
public static void main(String [] args) throws Exception {
RandomAccessFile raf;
File file = new File("log.dat");
if (file.exists())
file.delete();
byte[] data = new byte[4096]; ;
// open the file in rw mode
raf = new RandomAccessFile(file,"rw");
//just write some bytes
raf.write(data);
raf.close();
// reopen the above file in write sync mode
// Note: following call is failing on MAC
raf = new RandomAccessFile(file,"rws");
raf.seek(4096);
//just write some bytes
raf.write(data);
raf.close();
System.out.println("RWS MODE IS WORKING FINE");
}
}
-suresh
Mike Matrigali wrote:
> Joe I don't have access to an OSX 10.3.5. This error is strange, from
> my reading of the java interfaces and the code the first call is
> creating the file, and the second call should just be opening the
> existing file - and should not be getting a file exists error.
>
> I have tested this on a sun jdk 1.4.2 and an ibm 1.42 on windows and I
> believe it has also been tested against a linux jdk 1.4.2.
>
> Do you have any time to write a test case of the I/O calls separate
> from derby? This has the feel of a JVM bug, but maybe the interfaces
> are not being used correctly. This is a relatively new feature in
> jvm's (and new code in derby) so could be a bug in either area.
>
>
> It would be nice if a work around can be found to get this up and
> running in the OSX environment but not have to pay the extra
> performance cost across all the other JVM's.
>
> Joseph Grace wrote:
>
>> Dear Suresh:
>>
>> Thank you for your informative reply and explanations of the original
>> code. Much appreciated. I am relearning java and learning derby as
>> I go here, so I'll answer your questions as I can. Add salt to taste
>> as most of my "knowledge" I gleaned from the comments in the code I
>> modified.
>>
>> FYI, I am using the most up-to-date OSX 10.3.5 and ditto for OSX java:
>>
>> java version "1.4.2_05"
>> Java(TM) 2 Runtime Environment, Standard Edition 4(build 1.4.2_05-11)
>> Java HotSpot(TM) Client VM (build 1.4.2-38, mixed mode)
>>
>> and I have not tested on any other platform.
>>
>>
>> I believe your assessments below are correct.
>>
>> Suresh Thalamati wrote:
>>
>>> I am trying to understand the problem you described above. What is
>>> the error you are seeing when you try to create
>>> the database in the Mac environment. Are u seeing this problem
>>> with JDK1.4.2 on any other OS ?
>>> Could you please explain more on how database can be created
>>> twice ?
>>> From the changes described here, what I find is you are
>>> trying to
>>> avoid open/create
>>> of log file in "rw" mode first and then in "rws" mode by
>>> making
>>> it a single privRandomAccess File call:
>>>
>>> >> StorageRandomAccessFile theLog = privRandomAccessFile( logFile,
>>> isWriteSynced? "rws": "rw");
>>
>>
>>
>> Yes, I merged the file creations to get the code working (and avoid a
>> "File exists" exception:
>>
>> ~/derby$ java -cp jars/sane/derby.jar:jars/sane/derbytools.jar
>> org.apache.derby.tools.ij
>> ij version 10.0 (C) Copyright IBM Corp. 1997, 2004.
>> ij> connect 'jdbc:derby:test;create=true';
>> ERROR XJ041: Failed to create database 'test', see the next exception
>> for details.
>> ERROR XBM01: Startup failed due to an exception, see next exception
>> for details.
>> ERROR XJ001: Java exception:
>> '/Users/occam/dev/java/derby/test/log/log1.dat (File exists):
>> java.io.FileNotFoundException'.
>> ij>
>>
>> I thought there may have been some rush changes in the handoff from
>> IBM to Apache which left a bug overlooked in java 1.4.2 (mea culpa).
>> I did not realize the double-open was intended as an optimization
>> (since it fails on my system and so seemed a bug).
>>
>> The error is a little misleading but, looking under the covers, I was
>> able to confirm the existence of "log1.dat" (or somesuch) at the time
>> of the error report attempt to recreate/open "log1.dat". So, "File
>> exists" is the correct complaint. I have no idea whether that's
>> in/correct behavior. If there is incorrect behavior on OSX's java
>> 1.4.2_05, please describe it, and I shall submit it to Apple (or you
>> can, as desired).
>>
>>> I think the following part of the changes might increase database
>>> creation time when write sync is enabled..
>>
>>
>>
>> Aha. Yes, it does take quite a long time now that you mention it.
>> I'm glad that may not be normal.
>>
>>> Please correct me if my observation is not right . I think the
>>> Reason behind opening files in "RW" mode first
>>> and then reopen in "RWS" might have been to make preallocation of
>>> the log file finish faster.
>>> . Preallocation of the log file by doing writes to a file opened in
>>> "rws" mode will be much slower than
>>> doing writes to file opened in "rw" mode .
>>
>>
>>
>> Sounds good to me (i.e., I'll take your word for it :-).
>>
>> Apologies for any confusion. Please let me know whether this fixes a
>> bug or not, or whether I should submit a bug report to Apple for OSX
>> java instead?
>>
>> Thanks,
>>
>> = Joe =
>>
>>
>
Re: java1.4.2 "rws" mode fix: LogToFile.java diff
Posted by Mike Matrigali <mi...@sbcglobal.net>.
Joe I don't have access to an OSX 10.3.5. This error is strange, from my
reading of the java interfaces and the code the first call is creating
the file, and the second call should just be opening the existing file -
and should not be getting a file exists error.
I have tested this on a sun jdk 1.4.2 and an ibm 1.42 on windows and I
believe it has also been tested against a linux jdk 1.4.2.
Do you have any time to write a test case of the I/O calls separate from
derby? This has the feel of a JVM bug, but maybe the interfaces are not
being used correctly. This is a relatively new feature in jvm's (and
new code in derby) so could be a bug in either area.
It would be nice if a work around can be found to get this up and
running in the OSX environment but not have to pay the extra performance
cost across all the other JVM's.
Joseph Grace wrote:
> Dear Suresh:
>
> Thank you for your informative reply and explanations of the original
> code. Much appreciated. I am relearning java and learning derby as I
> go here, so I'll answer your questions as I can. Add salt to taste as
> most of my "knowledge" I gleaned from the comments in the code I modified.
>
> FYI, I am using the most up-to-date OSX 10.3.5 and ditto for OSX java:
>
> java version "1.4.2_05"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-141)
> Java HotSpot(TM) Client VM (build 1.4.2-38, mixed mode)
>
> and I have not tested on any other platform.
>
>
> I believe your assessments below are correct.
>
> Suresh Thalamati wrote:
>
>> I am trying to understand the problem you described above. What is
>> the error you are seeing when you try to create
>> the database in the Mac environment. Are u seeing this problem
>> with JDK1.4.2 on any other OS ?
>> Could you please explain more on how database can be created
>> twice ?
>> From the changes described here, what I find is you are trying to
>> avoid open/create
>> of log file in "rw" mode first and then in "rws" mode by making
>> it a single privRandomAccess File call:
>>
>> >> StorageRandomAccessFile theLog = privRandomAccessFile( logFile,
>> isWriteSynced? "rws": "rw");
>
>
> Yes, I merged the file creations to get the code working (and avoid a
> "File exists" exception:
>
> ~/derby$ java -cp jars/sane/derby.jar:jars/sane/derbytools.jar
> org.apache.derby.tools.ij
> ij version 10.0 (C) Copyright IBM Corp. 1997, 2004.
> ij> connect 'jdbc:derby:test;create=true';
> ERROR XJ041: Failed to create database 'test', see the next exception
> for details.
> ERROR XBM01: Startup failed due to an exception, see next exception for
> details.
> ERROR XJ001: Java exception:
> '/Users/occam/dev/java/derby/test/log/log1.dat (File exists):
> java.io.FileNotFoundException'.
> ij>
>
> I thought there may have been some rush changes in the handoff from IBM
> to Apache which left a bug overlooked in java 1.4.2 (mea culpa). I did
> not realize the double-open was intended as an optimization (since it
> fails on my system and so seemed a bug).
>
> The error is a little misleading but, looking under the covers, I was
> able to confirm the existence of "log1.dat" (or somesuch) at the time of
> the error report attempt to recreate/open "log1.dat". So, "File exists"
> is the correct complaint. I have no idea whether that's in/correct
> behavior. If there is incorrect behavior on OSX's java 1.4.2_05, please
> describe it, and I shall submit it to Apple (or you can, as desired).
>
>> I think the following part of the changes might increase database
>> creation time when write sync is enabled..
>
>
> Aha. Yes, it does take quite a long time now that you mention it. I'm
> glad that may not be normal.
>
>> Please correct me if my observation is not right . I think the
>> Reason behind opening files in "RW" mode first
>> and then reopen in "RWS" might have been to make preallocation of
>> the log file finish faster.
>> . Preallocation of the log file by doing writes to a file opened in
>> "rws" mode will be much slower than
>> doing writes to file opened in "rw" mode .
>
>
> Sounds good to me (i.e., I'll take your word for it :-).
>
> Apologies for any confusion. Please let me know whether this fixes a
> bug or not, or whether I should submit a bug report to Apple for OSX
> java instead?
>
> Thanks,
>
> = Joe =
>
>
Re: java1.4.2 "rws" mode fix: LogToFile.java diff
Posted by Joseph Grace <oc...@serv.net>.
Dear Suresh:
Thank you for your informative reply and explanations of the original
code. Much appreciated. I am relearning java and learning derby as I
go here, so I'll answer your questions as I can. Add salt to taste as
most of my "knowledge" I gleaned from the comments in the code I
modified.
FYI, I am using the most up-to-date OSX 10.3.5 and ditto for OSX java:
java version "1.4.2_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-141)
Java HotSpot(TM) Client VM (build 1.4.2-38, mixed mode)
and I have not tested on any other platform.
I believe your assessments below are correct.
Suresh Thalamati wrote:
> I am trying to understand the problem you described above. What is
> the error you are seeing when you try to create
> the database in the Mac environment. Are u seeing this problem
> with JDK1.4.2 on any other OS ?
> Could you please explain more on how database can be created
> twice ?
> From the changes described here, what I find is you are trying
> to
> avoid open/create
> of log file in "rw" mode first and then in "rws" mode by
> making
> it a single privRandomAccess File call:
>
> >> StorageRandomAccessFile theLog = privRandomAccessFile( logFile,
> isWriteSynced? "rws": "rw");
Yes, I merged the file creations to get the code working (and avoid a
"File exists" exception:
~/derby$ java -cp jars/sane/derby.jar:jars/sane/derbytools.jar
org.apache.derby.tools.ij
ij version 10.0 (C) Copyright IBM Corp. 1997, 2004.
ij> connect 'jdbc:derby:test;create=true';
ERROR XJ041: Failed to create database 'test', see the next exception
for details.
ERROR XBM01: Startup failed due to an exception, see next exception for
details.
ERROR XJ001: Java exception:
'/Users/occam/dev/java/derby/test/log/log1.dat (File exists):
java.io.FileNotFoundException'.
ij>
I thought there may have been some rush changes in the handoff from IBM
to Apache which left a bug overlooked in java 1.4.2 (mea culpa). I did
not realize the double-open was intended as an optimization (since it
fails on my system and so seemed a bug).
The error is a little misleading but, looking under the covers, I was
able to confirm the existence of "log1.dat" (or somesuch) at the time
of the error report attempt to recreate/open "log1.dat". So, "File
exists" is the correct complaint. I have no idea whether that's
in/correct behavior. If there is incorrect behavior on OSX's java
1.4.2_05, please describe it, and I shall submit it to Apple (or you
can, as desired).
> I think the following part of the changes might increase database
> creation time when write sync is enabled..
Aha. Yes, it does take quite a long time now that you mention it. I'm
glad that may not be normal.
> Please correct me if my observation is not right . I think the
> Reason behind opening files in "RW" mode first
> and then reopen in "RWS" might have been to make preallocation of
> the log file finish faster.
> . Preallocation of the log file by doing writes to a file opened in
> "rws" mode will be much slower than
> doing writes to file opened in "rw" mode .
Sounds good to me (i.e., I'll take your word for it :-).
Apologies for any confusion. Please let me know whether this fixes a
bug or not, or whether I should submit a bug report to Apple for OSX
java instead?
Thanks,
= Joe =
Re: java1.4.2 "rws" mode fix: LogToFile.java diff
Posted by Mi...@objectweb.org.
Mike Matrigali <mi...@sbcglobal.net> wrote on 09/03/2004 09:21:58 AM:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> is your log preallocated or not?
The log files are normally pre-allocated. I do not delete the files
before or after a test, so files get reused. I have noticed that the test
actually runs a little faster when it creates new files, and we have yet
to explain that.
> Are your writes block bounded?
The block size is configurable. The default block is 2K bytes. Each
block is written when it becomes full. The channel.force() is called when
the write queue is empty, so if the system is lightly loaded, force() is
called for each buffer, but if system is loaded, force() gets called less
frequently. Depending on the hardware and OS, the average number of
buffers that are forced ranges from 1.5 to 8 or 9.
My measurements do not include any db IO. The test driver only logs XA
protocol records, with zero think time. The objective is to determine
that the log will not be a bottleneck for the TM.
When I tested with "rwd" I did not change any logic, so the batching of
writes into a single force() was still going on, and the force() probably
was not needed because the writes were already forced by the "rwd" mode. I
guess I should modify that code to get a better number when using "rwd".
Michael Giroux
Re: java1.4.2 "rws" mode fix: LogToFile.java diff
Posted by Mike Matrigali <mi...@sbcglobal.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
is your log preallocated or not? Until darby switched to preallocated
non-growing files no performance gain was seen going to rws. Little or
no difference was seen using rws vs rwd on linux and windows where it
was tested.
Are your writes block bounded?
Michael.Giroux@objectweb.org wrote:
| I have been developing a log facility specifically for Transaction
Manager
|
| XA Commit protocol. The project (howl.objectweb.org) has been working
| toward a throughput target of 10,000 tx/sec to the journal. I have tried
| both "rw" with appropriate force() calls and "rwd". What I found is that
| the "rwd" mode is a little slower than "rw". Difference depends on the
| type of disk. On my 7200 rpm ATA drive, the "rwd" is almost 40% slower
| than "rw". On my 10,000 rpm SATA drive, the "rwd" is only about 12%
| slower than "rw".
|
| The IO pattern is quite different for XA protocol than it will be for
| database logging, specifically, there are only two log records per
| XA commit, and the first one must be forced.
|
| I will be interested is hearing how "rwd" does with the Derby log.
|
| The HOWL logger will be used by Apache Geroninmo Transaction
| Manager and is being used by ActiveMq. There may be an opportunity
| to apply lessons learned from our projects (Derby and HOWL) to
| both log facilities.
|
| Michael Giroux, Objectweb.org
|
| Jan Hlavaty <hl...@code.cz> wrote on 09/03/2004 05:57:05 AM:
|
|
|>Steen Jansdal wrote:
|>
|>>You are probably right. I don't know what mode I'm trying since I'm
|>>using the derby code unmodified. I just trying to tell you what I'm
|>>seeing with my file monitor. I'm not a derby expert, yet, so I don't
|>>now all the small technical details.
|>
|>Yes, Derby code in org.apache.derby.impl.store.raw.log.LogToFile is
|>using "rws" mode heavily, and no "rwd" at all. I suggest we try "rwd"
|>and see if performance is improved.
|>
|>Jan
|
|
|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFBOJokEpeslyHqPs0RAgmSAKDY+rVEkLD8Nkbtnuo/pZ21zmQVlACgvcpd
yxkBF/xATAGo+CDHpOciK9c=
=czHn
-----END PGP SIGNATURE-----
Re: java1.4.2 "rws" mode fix: LogToFile.java diff
Posted by Mi...@objectweb.org.
I have been developing a log facility specifically for Transaction Manager
XA Commit protocol. The project (howl.objectweb.org) has been working
toward a throughput target of 10,000 tx/sec to the journal. I have tried
both "rw" with appropriate force() calls and "rwd". What I found is that
the "rwd" mode is a little slower than "rw". Difference depends on the
type of disk. On my 7200 rpm ATA drive, the "rwd" is almost 40% slower
than "rw". On my 10,000 rpm SATA drive, the "rwd" is only about 12%
slower than "rw".
The IO pattern is quite different for XA protocol than it will be for
database logging, specifically, there are only two log records per
XA commit, and the first one must be forced.
I will be interested is hearing how "rwd" does with the Derby log.
The HOWL logger will be used by Apache Geroninmo Transaction
Manager and is being used by ActiveMq. There may be an opportunity
to apply lessons learned from our projects (Derby and HOWL) to
both log facilities.
Michael Giroux, Objectweb.org
Jan Hlavaty <hl...@code.cz> wrote on 09/03/2004 05:57:05 AM:
> Steen Jansdal wrote:
> > You are probably right. I don't know what mode I'm trying since I'm
> > using the derby code unmodified. I just trying to tell you what I'm
> > seeing with my file monitor. I'm not a derby expert, yet, so I don't
> > now all the small technical details.
>
> Yes, Derby code in org.apache.derby.impl.store.raw.log.LogToFile is
> using "rws" mode heavily, and no "rwd" at all. I suggest we try "rwd"
> and see if performance is improved.
>
> Jan
Re: java1.4.2 "rws" mode fix: LogToFile.java diff
Posted by Jan Hlavaty <hl...@code.cz>.
Steen Jansdal wrote:
> You are probably right. I don't know what mode I'm trying since I'm
> using the derby code unmodified. I just trying to tell you what I'm
> seeing with my file monitor. I'm not a derby expert, yet, so I don't
> now all the small technical details.
Yes, Derby code in org.apache.derby.impl.store.raw.log.LogToFile is
using "rws" mode heavily, and no "rwd" at all. I suggest we try "rwd"
and see if performance is improved.
Jan
Re: java1.4.2 "rws" mode fix: LogToFile.java diff
Posted by Steen Jansdal <st...@jansdal.dk>.
Jan Hlavaty wrote:
> Guys you are trying the wrong mode - I think you want "rwd", not "rws"!
>
> Jan
>
>
You are probably right. I don't know what mode I'm trying since I'm
using the derby code unmodified. I just trying to tell you what I'm
seeing with my file monitor. I'm not a derby expert, yet, so I don't
now all the small technical details.
Steen
Re: java1.4.2 "rws" mode fix: LogToFile.java diff
Posted by Jan Hlavaty <hl...@code.cz>.
Guys you are trying the wrong mode - I think you want "rwd", not "rws"!
Jan
Re: java1.4.2 "rws" mode fix: LogToFile.java diff
Posted by Mike Matrigali <mi...@sbcglobal.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
This is interesting. What is the ddl used to create the test table, I
would like to understand the size of the log records being written
Darby internally uses buffered I/O so from the darby code I would only
expect a single write call to the jvm per insert/commit (unless the
records are really long due to data types in the table). We use a JVM
buffered stream, I wonder if this is somehow changing our one write into
2 - the second writes all seem to be 4k page size writes on a 4k size
block boundary.
It may have something to do with the fact that log writes are not block
bounded, so when the commit comes in we are likely doing an write call
beginning at a non 4k offset. It may be better in the future to only do
log I/O on page boundaries as the system already does with data pages.
Originally the system was designed to use as few resources as possible
as so that it could run on small devices like cell phones, so the log
file was not preallocated, the size of log files was very small, and
they were deleted as quickly as possible. Now that the system is
preallocating log file space it may be worth doing to work to block the
log file I/O from the darby code into page size chunks.
I have not used this tool, does it trace actual OS system calls coming
out of the JVM?
The I/O's I was talking about are actual I/O's to the disk, I believe
these writes are to the OS cache. Before doing preallocation the sync
call made would force the OS to force both the most recently changed
page (for small log records this was usually one page), and also
whatever page the OS maintained metadata on (like allocation information
and last modified time). This is very OS and filesystem dependent
(logged filesystems are likely to perform very differently).
Which OS/filesystem are you using?
Steen Jansdal wrote:
| Mike Matrigali wrote:
|
|> I think that was tried when the original change was made and the
|> system did not see the expected IO performance that was expected at
|> log commit time. The problem this change is addresses is that
|> performance of the log sync call at commit time was sometimes 2 to 3
|> times slower than other databases for single user short transaction
|> benchmarks. The difference depends on OS/JVM/and disk types.
|>
|> Previous to jdk1.4 the only pure java way to sync data to disk was a
|> call that told the JVM to basically sync the whole file. Our
|> investigation determined that at least on windows each extending write
|> using this mechansism was causing multiple I/O's to the log file -
|> likely one for the data and one for system metadata about the file.
|>
|> In jdk1.4 a new interface was added which guaranteed sync of writes
|> for each write executed. Unfortunately on some jvm's in jdk1.4.1 it
|> did not
|> actually do the sync. This bug was fixed in jdk1.4.2 jvms.
|>
|> So in jdk1.4.2 jvm's the new interface was used. But testing showed the
|> system still got the multiple I/O performance unless the system wrote to
|> a preallocated log file rather than an ever growing one. So at the
|> same time the code being discussed here was added to preallocate log
|> files.
|>
|> I would worry that the suggested trick would actually not allocate all
|> pages to the file (on all OS/JVM's), and that subsequent sync writes
|> at commit time would again see the multiple I/O peformance that was
|> trying to be avoided.
|>
|> Making allocation run fast is good, but only if the subsequent syncing
|> writes as part of commits are optimized. Log file allocation can be
|> made asynchronous to client application work, but the syncing
|> peformance directly affects clients performance.
|>
|> It is unfortunate that the jvm documentation is so bad in this area,
|> as you say the behaviour in this situation is undocumented. From
|> documentation we can't even tell what "metadata" is being discussed
|> when using the "rws" and "rwd" modes.
|>
|
|
| Are you telling me that on my jdk1.4.2_03 commits will only generate one
| I/O write to the log file. By using a file monitoring tool I can see
| that each commit generate two log writes.
|
| I wrote a little test program:
|
|
|
| stmt.execute ( "INSERT INTO test (idx,str) VALUES (1,'hello')" );
|
| // wait 10 seconds
| for ( int sec = 0; sec < 10; sec++ ) {
| start = System.currentTimeMillis();
| while ( System.currentTimeMillis() < start + 1000 )
| ;
| System.out.print ( "%" );
| }
|
| stmt.execute ( "INSERT INTO test (idx,str) VALUES (1,'hello')" );
|
| // wait 10 seconds
| for ( int sec = 0; sec < 10; sec++ ) {
| start = System.currentTimeMillis();
| while ( System.currentTimeMillis() < start + 1000 )
| ;
| System.out.print ( "&" );
| }
|
| con.setAutoCommit(false);
| for ( int j = 0; j < 10; j++ )
| stmt.execute ( "INSERT INTO test (idx,str) VALUES (1,'hello')" );
| con.commit();
|
|
|
| And by monitoring with FileMon (freeware from www.sysinternals.com)
| I get the following output
|
| 1 09:17:02 javaw.exe:304 WRITE
| C:\src\DatabaseBenchmark\databases\derby\log\log2.dat SUCCESS
| Offset: 332944 Length: 132
| 2 09:17:02 javaw.exe:304 WRITE
| C:\src\DatabaseBenchmark\databases\derby\log\log2.dat SUCCESS
| Offset: 331776 Length: 4096
| 3 09:17:12 javaw.exe:304 WRITE
| C:\src\DatabaseBenchmark\databases\derby\log\log2.dat SUCCESS
| Offset: 333076 Length: 132
| 4 09:17:12 javaw.exe:304 WRITE
| C:\src\DatabaseBenchmark\databases\derby\log\log2.dat SUCCESS
| Offset: 331776 Length: 4096
| 5 09:17:22 javaw.exe:304 WRITE
| C:\src\DatabaseBenchmark\databases\derby\log\log2.dat SUCCESS
| Offset: 333208 Length: 699
| 6 09:17:22 javaw.exe:304 WRITE
| C:\src\DatabaseBenchmark\databases\derby\log\log2.dat SUCCESS
| Offset: 331776 Length: 4096
|
|
|
| This shows that each commit generates two disk writes. And whats more
| strange is that first 132 bytes are written and then its overwritten by
| 4096 bytes. (See the offsets and lengths of the writes)
|
| Steen
|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFBOJiWEpeslyHqPs0RAq4EAJ9veEdr4hnaDkhLrjNt7C5tXSgElgCfQila
m/If5qEmcEhqFy2z+LTy/v4=
=snfd
-----END PGP SIGNATURE-----
Re: java1.4.2 "rws" mode fix: LogToFile.java diff
Posted by Steen Jansdal <st...@jansdal.dk>.
Mike Matrigali wrote:
> I think that was tried when the original change was made and the system
> did not see the expected IO performance that was expected at log commit
> time. The problem this change is addresses is that performance of the
> log sync call at commit time was sometimes 2 to 3 times slower than
> other databases for single user short transaction benchmarks. The
> difference depends on OS/JVM/and disk types.
>
> Previous to jdk1.4 the only pure java way to sync data to disk was a
> call that told the JVM to basically sync the whole file. Our
> investigation determined that at least on windows each extending write
> using this mechansism was causing multiple I/O's to the log file -
> likely one for the data and one for system metadata about the file.
>
> In jdk1.4 a new interface was added which guaranteed sync of writes for
> each write executed. Unfortunately on some jvm's in jdk1.4.1 it did not
> actually do the sync. This bug was fixed in jdk1.4.2 jvms.
>
> So in jdk1.4.2 jvm's the new interface was used. But testing showed the
> system still got the multiple I/O performance unless the system wrote to
> a preallocated log file rather than an ever growing one. So at the same
> time the code being discussed here was added to preallocate log files.
>
> I would worry that the suggested trick would actually not allocate all
> pages to the file (on all OS/JVM's), and that subsequent sync writes at
> commit time would again see the multiple I/O peformance that was trying
> to be avoided.
>
> Making allocation run fast is good, but only if the subsequent syncing
> writes as part of commits are optimized. Log file allocation can be
> made asynchronous to client application work, but the syncing peformance
> directly affects clients performance.
>
> It is unfortunate that the jvm documentation is so bad in this area, as
> you say the behaviour in this situation is undocumented. From
> documentation we can't even tell what "metadata" is being discussed when
> using the "rws" and "rwd" modes.
>
Are you telling me that on my jdk1.4.2_03 commits will only generate one
I/O write to the log file. By using a file monitoring tool I can see
that each commit generate two log writes.
I wrote a little test program:
stmt.execute ( "INSERT INTO test (idx,str) VALUES (1,'hello')" );
// wait 10 seconds
for ( int sec = 0; sec < 10; sec++ ) {
start = System.currentTimeMillis();
while ( System.currentTimeMillis() < start + 1000 )
;
System.out.print ( "%" );
}
stmt.execute ( "INSERT INTO test (idx,str) VALUES (1,'hello')" );
// wait 10 seconds
for ( int sec = 0; sec < 10; sec++ ) {
start = System.currentTimeMillis();
while ( System.currentTimeMillis() < start + 1000 )
;
System.out.print ( "&" );
}
con.setAutoCommit(false);
for ( int j = 0; j < 10; j++ )
stmt.execute ( "INSERT INTO test (idx,str) VALUES (1,'hello')" );
con.commit();
And by monitoring with FileMon (freeware from www.sysinternals.com)
I get the following output
1 09:17:02 javaw.exe:304 WRITE
C:\src\DatabaseBenchmark\databases\derby\log\log2.dat SUCCESS Offset:
332944 Length: 132
2 09:17:02 javaw.exe:304 WRITE
C:\src\DatabaseBenchmark\databases\derby\log\log2.dat SUCCESS Offset:
331776 Length: 4096
3 09:17:12 javaw.exe:304 WRITE
C:\src\DatabaseBenchmark\databases\derby\log\log2.dat SUCCESS Offset:
333076 Length: 132
4 09:17:12 javaw.exe:304 WRITE
C:\src\DatabaseBenchmark\databases\derby\log\log2.dat SUCCESS Offset:
331776 Length: 4096
5 09:17:22 javaw.exe:304 WRITE
C:\src\DatabaseBenchmark\databases\derby\log\log2.dat SUCCESS Offset:
333208 Length: 699
6 09:17:22 javaw.exe:304 WRITE
C:\src\DatabaseBenchmark\databases\derby\log\log2.dat SUCCESS Offset:
331776 Length: 4096
This shows that each commit generates two disk writes. And whats more
strange is that first 132 bytes are written and then its overwritten by
4096 bytes. (See the offsets and lengths of the writes)
Steen
Re: java1.4.2 "rws" mode - log write performance - Linux numbers
Posted by Davide Savazzi <ds...@apache.org>.
On Saturday 04 September 2004 15:07, Jan Hlavatý wrote:
> I've ran the test on my crappy Linux based Celeron 800 firewall machine.
> It has RedHat linux 9.0 on single old IDE disk formatted with ext3
> filesystem.
> I'd really like to see what numbers I'd get with different filesystems,
> like reiser4 - ext3 has a reputation of being a bit slow...
My Linux box is a PIII 667, with a single 80GB IDE disk formatted with
reiser3. It runs Gentoo Linux 1.4.
I've attached the results...
It seems that with a preallocated file all the methods have the same (good)
performance.
Cheers,
--
Davide Savazzi
Re: java1.4.2 "rws" mode - log write performance - Linux numbers
Posted by Jan Hlavatý <hl...@code.cz>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I've ran the test on my crappy Linux based Celeron 800 firewall machine.
It has RedHat linux 9.0 on single old IDE disk formatted with ext3 filesystem.
On linux, preallocated files do seem to help a lot too - theyre about 3 times faster
than growing files. Interesting thing here is that "rw"+sync() is as fasr (slow) as "rws"/"rwd"
on growing files here. "rws" on preallocated file seems to be best here, like on Windows.
I'd really like to see what numbers I'd get with different filesystems, like reiser4 -
ext3 has a reputation of being a bit slow...
Here are the numbers:
- ---------------------------------------------
1. System info:
- ---------------------------------------------
OS Platform: Linux/i386/2.4.20-20.9
Java spec: Java Platform API Specification version 1.5 from Sun Microsystems Inc.
Java VM: Java HotSpot(TM) Client VM version 1.5.0-rc-b63 from Sun Microsystems Inc.
Java home: /usr/java/jdk1.5.0/jre
Test file: /data/iotest/test.bin
Test file exists, deleting...
- ---------------------------------------------------------------------
2. Testing growing file using RandomAccessFile "rw" + .getFD().sync()
- ---------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 117320 ms
Writes per second: 85.237 writes/s
Time per chunk: 11.732 ms
Write bandwidth: 350.0KB/s
- ---------------------------------------------------------------------------
3. Testing preallocated file using RandomAccessFile "rw" + .getFD().sync()
- ---------------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 162398 ms
Writes per second: 61.577 writes/s
Time per chunk: 16.24 ms
Write bandwidth: 251.0KB/s
- ---------------------------------------------------------------------
4. Testing growing file using RandomAccessFile "rws"
- ---------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 118010 ms
Writes per second: 84.739 writes/s
Time per chunk: 11.801 ms
Write bandwidth: 346.0KB/s
- ---------------------------------------------------------------------
5. Testing preallocated file using RandomAccessFile "rws"
- ---------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 38827 ms
Writes per second: 257.553 writes/s
Time per chunk: 3.883 ms
Write bandwidth: 1.0MB/s
- ---------------------------------------------------------------------
6. Testing growing file using RandomAccessFile "rwd"
- ---------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 117842 ms
Writes per second: 84.859 writes/s
Time per chunk: 11.784 ms
Write bandwidth: 346.0KB/s
- ---------------------------------------------------------------------
7. Testing preallocated file using RandomAccessFile "rwd"
- ---------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 22387 ms
Writes per second: 446.688 writes/s
Time per chunk: 2.239 ms
Write bandwidth: 1.0MB/s
- ------------------------------------------------------------------------------
8. Testing growing file using direct buffer + FileChannel "rw" + force(true)
- ------------------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 116817 ms
Writes per second: 85.604 writes/s
Time per chunk: 11.682 ms
Write bandwidth: 350.0KB/s
- -----------------------------------------------------------------------------------
9. Testing preallocated file using direct buffer + FileChannel "rw" + force(true)
- -----------------------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 84007 ms
Writes per second: 119.038 writes/s
Time per chunk: 8.401 ms
Write bandwidth: 491.0KB/s
- ------------------------------------------------------------------------------
10. Testing growing file using direct buffer + FileChannel "rw" + force(false)
- ------------------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 116254 ms
Writes per second: 86.019 writes/s
Time per chunk: 11.625 ms
Write bandwidth: 355.0KB/s
- ------------------------------------------------------------------------------
11. Testing preallocated file using direct buffer + FileChannel "rw" + force(false)
- ------------------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 83028 ms
Writes per second: 120.441 writes/s
Time per chunk: 8.303 ms
Write bandwidth: 495.0KB/s
- ------------------------------------------------------------------------------
12. Testing growing file using direct buffer + FileChannel "rws"
- ------------------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 117226 ms
Writes per second: 85.305 writes/s
Time per chunk: 11.723 ms
Write bandwidth: 350.0KB/s
- ------------------------------------------------------------------------------
13. Testing preallocated file using direct buffer + FileChannel "rws"
- ------------------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 20279 ms
Writes per second: 493.121 writes/s
Time per chunk: 2.028 ms
Write bandwidth: 1.0MB/s
- ------------------------------------------------------------------------------
14. Testing growing file using direct buffer + FileChannel "rwd"
- ------------------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 117511 ms
Writes per second: 85.098 writes/s
Time per chunk: 11.751 ms
Write bandwidth: 350.0KB/s
- ------------------------------------------------------------------------------
15. Testing preallocated file using direct buffer + FileChannel "rwd"
- ------------------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 20724 ms
Writes per second: 482.532 writes/s
Time per chunk: 2.072 ms
Write bandwidth: 1.0MB/s
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iQEVAwUBQTm+D3FDePgyse5HAQI3mAf/ekh37zW8MUH3roZbP0P8rSEDxrtJSAzl
LTY4BjXrP2hfWbz25L/Ki2eiXRyKpgXsXl2gRzQG7CVpFOza7i70WWXYVdp+cXB6
SYP3QyTjPiXp7Nv6Qx8kv77gEPHIIOY2wS/yyJmfOLEg2jnJ4GQOFHXFuaOAGcc0
oJLAtlqCU7vpQYpqaIRstU3lKhfKKdxdi6E/c1oHq168n7+3KELCpd5slaFfm5U1
rO8AwapTq2Al8jZ8TeCyf8rjkIv2kirbMmQldbUJ9yt6t/R6qUjkEdbT+K08Ql06
5IQxDvjPM/+rFgiu+9c3PNVUD0y4VbRWeyTNIJ/M/ZQlTxNL7L0RRw==
=ITMV
-----END PGP SIGNATURE-----
Re: java1.4.2 "rws" mode - log write performance
Posted by Jan Hlavatý <hl...@code.cz>.
As this seems crucial for log performance,
I made a test to see for myself what's really the best way to write a log.
It tests various forced sequential write methods, with growing and preallocated file.
Using direct buffers doesn't seem to have any effect over plain RandomAccessFile.write(byte[]).
Following results are from my Athlon XP 1700+ Windows XP Professional machine,
with IDE disk that can dish out unsynced writes at 40MB/s, running JDK1.5 RC.
It proves Mike's point about "rws" being best on preallocated files on Windows.
That is, it can write 10MB/s in 4228 byte chunks, that is about 2490 chunks per sec.
So if you want to get 10000 transactions/sec, you will have to combine logs and
write them in one chunk. I think that's exactly what Derby does. So we're all good ;)
It also shows that sync() / force() are thing to avoid at all costs on Windows ;)
Can anyone run the test on another OS? I've attached the source file for the tests.
(warning: 10000 records test ran for 30minutes ;-) You can decrease the chunk count)
---------------------------------------------
1. System info:
---------------------------------------------
OS Platform: Windows XP/x86/5.1
Java spec: Java Platform API Specification version 1.5 from Sun Microsystems Inc.
Java VM: Java HotSpot(TM) Client VM version 1.5.0-rc-b63 from Sun Microsystems Inc.
Java home: C:\java\jdk1.5.0\jre
Test file: C:\Documents and Settings\hlavac\iotest\test.bin
Test file exists, deleting...
---------------------------------------------------------------------
2. Testing growing file using RandomAccessFile "rw" + .getFD().sync()
---------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 283527 ms
Writes per second: 35.27 writes/s
Time per chunk: 28.353 ms
Write bandwidth: 144.0KB/s
---------------------------------------------------------------------------
3. Testing preallocated file using RandomAccessFile "rw" + .getFD().sync()
---------------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 276988 ms
Writes per second: 36.103 writes/s
Time per chunk: 27.699 ms
Write bandwidth: 148.0KB/s
---------------------------------------------------------------------
4. Testing growing file using RandomAccessFile "rws"
---------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 9173 ms
Writes per second: 1090.156 writes/s
Time per chunk: 0.917 ms
Write bandwidth: 4.0MB/s
---------------------------------------------------------------------
5. Testing preallocated file using RandomAccessFile "rws"
---------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 4016 ms
Writes per second: 2490.04 writes/s
Time per chunk: 0.402 ms
Write bandwidth: 10.0MB/s
---------------------------------------------------------------------
6. Testing growing file using RandomAccessFile "rwd"
---------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 10264 ms
Writes per second: 974.279 writes/s
Time per chunk: 1.026 ms
Write bandwidth: 3.0MB/s
---------------------------------------------------------------------
7. Testing preallocated file using RandomAccessFile "rwd"
---------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 5598 ms
Writes per second: 1786.352 writes/s
Time per chunk: 0.56 ms
Write bandwidth: 7.0MB/s
------------------------------------------------------------------------------
8. Testing growing file using direct buffer + FileChannel "rw" + force(true)
------------------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 281445 ms
Writes per second: 35.531 writes/s
Time per chunk: 28.144 ms
Write bandwidth: 144.0KB/s
-----------------------------------------------------------------------------------
9. Testing preallocated file using direct buffer + FileChannel "rw" + force(true)
-----------------------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 276638 ms
Writes per second: 36.148 writes/s
Time per chunk: 27.664 ms
Write bandwidth: 148.0KB/s
------------------------------------------------------------------------------
10. Testing growing file using direct buffer + FileChannel "rw" + force(false)
------------------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 283908 ms
Writes per second: 35.223 writes/s
Time per chunk: 28.391 ms
Write bandwidth: 144.0KB/s
------------------------------------------------------------------------------
11. Testing preallocated file using direct buffer + FileChannel "rw" + force(false)
------------------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 277960 ms
Writes per second: 35.976 writes/s
Time per chunk: 27.796 ms
Write bandwidth: 144.0KB/s
------------------------------------------------------------------------------
12. Testing growing file using direct buffer + FileChannel "rws"
------------------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 8733 ms
Writes per second: 1145.082 writes/s
Time per chunk: 0.873 ms
Write bandwidth: 4.0MB/s
------------------------------------------------------------------------------
13. Testing preallocated file using direct buffer + FileChannel "rws"
------------------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 3805 ms
Writes per second: 2628.121 writes/s
Time per chunk: 0.381 ms
Write bandwidth: 10.0MB/s
------------------------------------------------------------------------------
14. Testing growing file using direct buffer + FileChannel "rwd"
------------------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 10595 ms
Writes per second: 943.841 writes/s
Time per chunk: 1.06 ms
Write bandwidth: 3.0MB/s
------------------------------------------------------------------------------
15. Testing preallocated file using direct buffer + FileChannel "rwd"
------------------------------------------------------------------------------
Chunk size: 4228 bytes
Count: 10000
Total time: 5508 ms
Writes per second: 1815.541 writes/s
Time per chunk: 0.551 ms
Write bandwidth: 7.0MB/s
Re: java1.4.2 "rws" mode fix: LogToFile.java diff
Posted by Mike Matrigali <mi...@sbcglobal.net>.
I think that was tried when the original change was made and the system
did not see the expected IO performance that was expected at log commit
time. The problem this change is addresses is that performance of the
log sync call at commit time was sometimes 2 to 3 times slower than
other databases for single user short transaction benchmarks. The
difference depends on OS/JVM/and disk types.
Previous to jdk1.4 the only pure java way to sync data to disk was a
call that told the JVM to basically sync the whole file. Our
investigation determined that at least on windows each extending write
using this mechansism was causing multiple I/O's to the log file -
likely one for the data and one for system metadata about the file.
In jdk1.4 a new interface was added which guaranteed sync of writes for
each write executed. Unfortunately on some jvm's in jdk1.4.1 it did not
actually do the sync. This bug was fixed in jdk1.4.2 jvms.
So in jdk1.4.2 jvm's the new interface was used. But testing showed the
system still got the multiple I/O performance unless the system wrote to
a preallocated log file rather than an ever growing one. So at the same
time the code being discussed here was added to preallocate log files.
I would worry that the suggested trick would actually not allocate all
pages to the file (on all OS/JVM's), and that subsequent sync writes at
commit time would again see the multiple I/O peformance that was trying
to be avoided.
Making allocation run fast is good, but only if the subsequent syncing
writes as part of commits are optimized. Log file allocation can be
made asynchronous to client application work, but the syncing peformance
directly affects clients performance.
It is unfortunate that the jvm documentation is so bad in this area, as
you say the behaviour in this situation is undocumented. From
documentation we can't even tell what "metadata" is being discussed when
using the "rws" and "rwd" modes.
Jan Hlavatý wrote:
> Suresh Thalamati wrote:
> | . Preallocation of the log file by doing writes to a file opened in
> | "rws" mode will be much slower than doing writes to file opened in
> | "rw" mode .
>
> I have a trick for this - instead of writing whole file,
> write a single block on the end (last block) - that will create the big
> file faster, rws or not ;-)
> Rest of file gets zeroed out on windows, dunno about other platforms
> (it's unspecified).
>
> Jan
Re: java1.4.2 "rws" mode fix: LogToFile.java diff
Posted by Jan Hlavatý <hl...@code.cz>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Suresh Thalamati wrote:
| . Preallocation of the log file by doing writes to a file opened in
| "rws" mode will be much slower than doing writes to file opened in
| "rw" mode .
I have a trick for this - instead of writing whole file,
write a single block on the end (last block) - that will create the big file faster, rws or not ;-)
Rest of file gets zeroed out on windows, dunno about other platforms (it's unspecified).
Jan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iQEVAwUBQTaM13FDePgyse5HAQLTywgAm55JxXGhpl3QJ9etkkcTM+fyU5ic4MI7
DUCOic545R45hSZEfF1qmgTvwxfmheVoZ1iuRGgwvuuxHkKfLhvLBF+VxGRO9I8w
jQsE5LpC1TmMcpDhVciQMcxVm1VS5ROb+J8vQpGa/5bFQlrXplDmSrqIvX4jzfBQ
DtNAaTLqmX4O6AVaYgLQ5DRJIf5C+Kie2L3RGAi+P1tbOjLikVovhX6SlvvnCJk/
v6qedzDhXfBejI9DUoA3EArMiP+7Ch8IGhjY8mH0kCs2tDtpQ3I6Mc+WAXhov7iY
OH1r7uxFHjMHSKzyBUk7rDBYXYpgFdxbXGCTTvWDJKO+IqC/0YVS+w==
=DhPw
-----END PGP SIGNATURE-----
Re: java1.4.2 "rws" mode fix: LogToFile.java diff
Posted by Suresh Thalamati <ts...@Source-Zone.org>.
Joseph Grace wrote:
> Dear derby-dev:
>
> Apologies for any faux-pas. I'm not sure what diff to use, so I used
> diff -c2 to make the following patch.
>
> I made this change to get derby running under java 1.4.2 on Mac OSX
> 10.3.5 (i.e., the latest and greatest version). I believe the patch
> fixes a bug where the database gets created twice unnecessarily. This
> bug was causing the simple instructions example ("connect
> 'jdbc:derby:test;create=true';") to choke with a file already exists
> error. Apparently, this situation crops up whenever "rws" mode was
> available, and would not occur prior to 1.4.1 (since apparently "rws"
> was too buggy to use until 1.4.2 and, so, was avoided). Anyway,
> here's what I believe is a fix for that issue and, at least, got the
> database to initialize per instructions on my system.
>
Hi Joe ,
I am trying to understand the problem you described above. What is
the error you are seeing when you try to create
the database in the Mac environment. Are u seeing this problem
with JDK1.4.2 on any other OS ?
Could you please explain more on how database can be created
twice ?
From the changes described here, what I find is you are trying to
avoid open/create
of log file in "rw" mode first and then in "rws" mode by making
it a single privRandomAccess File call:
>> StorageRandomAccessFile theLog = privRandomAccessFile( logFile,
isWriteSynced? "rws": "rw");
>
>
> *** LogToFile.java.org Thu Aug 26 12:07:32 2004
> --- LogToFile.java Tue Aug 31 22:19:16 2004
> ***************
> *** 889,902 ****
> lastFlush =
> endPosition;
>
>
I think the following part of the changes might increase database
creation time when write sync is enabled..
Please correct me if my observation is not right . I think the
Reason behind opening files in "RW" mode first
and then reopen in "RWS" might have been to make preallocation of
the log file finish faster.
. Preallocation of the log file by doing writes to a file opened in
"rws" mode will be much slower than
doing writes to file opened in "rw" mode .
> ***************
> *** 3004,3008 ****
>
> // don't need to try to delete
> it, we know it isn't there
> ! StorageRandomAccessFile theLog =
> privRandomAccessFile(logFile, "rw");
>
> if (!initLogFile(theLog,
> logFileNumber, LogCounter.INVALID_LOG_INSTANT))
> --- 3004,3008 ----
>
> // don't need to try to delete
> it, we know it isn't there
> ! StorageRandomAccessFile theLog =
> privRandomAccessFile( logFile, isWriteSynced? "rws": "rw");
>
> if (!initLogFile(theLog,
> logFileNumber, LogCounter.INVALID_LOG_INSTANT))
> ***************
> *** 3015,3028 ****
> lastFlush =
> theLog.getFilePointer();
>
> ! //if write sync is true , prellocate the log file
> ! //and reopen the file in rws mode.
> ! if(isWriteSynced)
> {
> ! //extend the file by wring zeros to it
> ! preAllocateNewLogFile(theLog);
> ! theLog.close();
> ! theLog= privRandomAccessFile(logFile, "rws");
> ! //postion the log at the current log end
> postion
> ! theLog.seek(endPosition);
> }
> logOut = new
> LogAccessFile(theLog, logBufferSize);
> --- 3015,3026 ----
> lastFlush =
> theLog.getFilePointer();
>
> ! // if write sync is true , preallocate the log
> file
> ! // and reposition cursor.
> ! if( isWriteSynced)
> {
> ! // extend the file by writing zeros to it
> ! preAllocateNewLogFile( theLog);
> ! // position the log at the current log end
> position
> ! theLog.seek( endPosition);
> }
> logOut = new
> LogAccessFile(theLog, logBufferSize);
>
Thanks
-suresh