Tuesday, July 11, 2006

Get the Best Performance out of Java in the Database

When you run Java in the database, what are the various execution modes? Are you taking the most efficient approach? In this post I'll touch on the various execution modes for running Java in the Oracle database.

As we all know, the best execution performance for Java is achieved via binary executables obtained through compilation (JIT compilers and/or static compilers). The Oracle Database currently furnishes a static native Java compiler known as NCOMP, which must be explictly invoked ahead of the deployment.

There are currently three execution modes: (i) fully interpret, (ii) NCOMPed System classes, and (iii) fully NCOMPed (or NCOMPed User Classes).

Fully Interpreted (System and User Classes)
In this mode, both system classes and the user classes, run interpreted. During the database installation, the non-compiled Java VM system classes are installed. By default, user classes also run interpreted and most customers stick to the default mode and are happy with the level of performance obtained, mostly because, as explained in previous posts and in my book, the combination of Java and SQL run faster in the database (even fully interpreted). However, this is not the most efficient execution mode.

NCOMPed System Classes and Interpreted User Classes
In this mode, the system classes run natively compiled while user classes run interpreted. The natively compiled system classes (NCOMP libraries) are installed explictly following the default database install, from the companion CD. Without further explcit action, the user classes run interpreted on top of the natively compiled system classes. The overall peformance is greater than the previous mode (i.e., fully interpreted).

Fully NCOMPed (System and User Classes)
In this mode, the system and user classes run natively compiled. User NCOMP requires an explicit action from the developers. It comprises three commands/steps: 'NCOMP', 'STATUSNC', and 'DEPLOYNC'.

NCOMP

This command takes Java bytecodes that have been resolved and verified during the loading phase (loadjava) and can therefore be trusted and expected to execute correctly, then does three things:
  1. gathers class info, generates a script that will drive the NCOMPing process, and produces the list of NEED_NCOMPNG orALREADY_NCOMPED methods
  2. Pauses for the Java-to-C translation: C compilation and linkage of each package involved into platform-specific DLLs
  3. Deployment/installation of the resulting DLL (unless -noDeploy) is specified


ncomp [ options ] class_designation_file
-user -u username/password [@database_url]
[-load]
[-projectDir -d project_directory]
[-force]
[-lightweightDeployment]
[-noDeploy]
[-outputJarFile -o jar_filename]
[-thin]
[-oci -oci8]
[-update]
[-verbose]

STATUSNC

This command checks whether the JAR files, ZIP files, or CLASSES files are NCOMPed or not.
statusnc [ options ] .jar .zip
.classes.
-user /[@database]
[-output -o ]
[-projectDir -d ]
[-thin]
[-oci -oci8]

DEPLOYNC

This command deployd the natively compiled deployment JAR file, to the database.
deploync [options] deployment.jar
-user -u username/password [@database_url]
[-projectDir -d project_directory]
[-thin]
[-oci -oci8]

Conclusions

NCOMP may give an order of magnitude speed up (i.e., 10 times) compared to interpreted execution. But as usual, there is no absolute figure; it all depends on what exactly you are NCOMPing as NCOMP speeds up only Java code, not the embedded SQL.

See more details in the Java Developer's Guide of the Oracle Database documentation nd in my book.

14 comments:

Anonymous said...

I bought your book and hoped it would be straight forward to finally got my java classes ncomp'd. Unfortunately I even failed to get the first example to work. Well, the first part where the code is interpreted works but then ncomping it fails.

I got a bunch of error messages, advising me to add additional grants, i.e.

The PL/SQL to grant this is dbms_java.g
rant_permission( 'SCOTT', 'SYS:oracle.aurora.rdbms.HandlePermission', 'HandleInp
utStream.SYS.java.lang.Object', '' )
ORA-06512: in "SYS.DBMS_JAVA", Zeile 198
ORA-06512: in "SCOTT.JACCELERATOR_GET_CLASS_BITS", Zeile 1

However following the advice does not help at all.

Since it seems that your book is the only one on that subject and also google queries do not return helpfull results, I'm a bit wondering whether non Oracle developers really use ncomping.

Another question, not covered in the book and nowhere else (oracle docs, google,.. ) are prerequistes for ncomping (in addition to the companion cd), e.g. does one need a C compiler (if yes, which one), etc ...

Maybe you could unveil some more of the secrets of Oracle Database Java Programming.

Kuassi Mensah said...

Hi,

Before ncomping, the schema where it runs must be granted javasyspriv
and java_deploy from sqlplus, as follows:

sqlplus sys/install
grant javasyspriv to scott;
grant java_deploy to scott;
exit

Regarding the need for a C compiler, in NCOMP Configuration and PLanning in section 2.6.6, i mention the Settings_os.properties
file which is preconfigured for gcc. Sorry if this was not clear enough.
Let me know how it goes, Kuassi

Anonymous said...

Hi,

thank your for your answer.

I already was aware of these required
role grants. So I'll still stuck with the described error where the reported ncom problem on executing

select jaccelerator_get_class_bits('java/lang/Object', 'SYS'), jaccelerator_get_class_digest('java/lang/Object', 'SYS') from dual

fails (either for ncomp and sqlplus) and the suggested soltution to add the lacking permission SYS:oracle.aurora.rdbms.HandlePermission
does not help.


Regarding the need for a C compiler
for which configuration is mentioned in 2.6.7 in my copy of your book my understanding of that section was that there are some for options available for applying some more fine tuning. So it was not clear at all, that the separate installation of a C compiler is mandatory.
(which I've already fixed now for my test environment but obviously this isn't the problem at the moment).

Do you have any further idea?
Would it be reasonable to post a request to Oracle metalink?

Kuassi Mensah said...

Hi,

Regarding the C compiler, you are right, i should have been more explicit.

Regarding the error message, we have seen similar error messages and most of the time, granting JAVA_DEPLOY fixes the problem.

It seems like you have already gone through all this, so i'd suggest to file a Metalink TAR so that Support and development can look into this.

Thanks, Kuassi

Anonymous said...

dbms_java.grant_permission( 'SCOTT', 'SYS:oracle.aurora.rdbms.HandlePermission', 'HandleInp
utStream.SYS.java.lang.Object', '' ) is invalid.
valid is :
dbms_java.grant_permission( 'SCOTT', 'SYS:oracle.aurora.rdbms.HandlePermission', 'HandleInp
utStream.SYS.java.lang.Object', '*' )

Unknown said...

Hi kuassi,
I have a problem running ncomp. I ncompED my JAR file, but when i see in the database there are some classes that are incompiled. why is that?
The classes are:
MinimizeNcompListAndDumpTC
TransitiveClosureDump
[JAR Filename]_minimalClassLib

I try to compile mannualy with Toad but doesnt compile, and didnt show any code or description in the error.

I couldnt run my program without compiling these classes because i make a validate the connection with this query :
select * from user_objects where status != 'VALID';

Thanks in advance
Juan

Kuassi Mensah said...

Hello,

These classes are used internally by NCOMP itself; you need to exclude these from your query results.

Kuassi

Unknown said...

thanks a lot,
One more question, it's normal that these classes keep incompiled?

Anonymous said...

情趣用品,情趣用品,情趣用品,情趣用品,情趣,情趣,情趣,情趣,按摩棒,震動按摩棒,微調按摩棒,情趣按摩棒,逼真按摩棒,G點,跳蛋,跳蛋,跳蛋,性感內衣,飛機杯,充氣娃娃,情趣娃娃,角色扮演,性感睡衣,SM,潤滑液,威而柔,香水,精油,芳香精油,自慰套,自慰,性感吊帶襪,吊帶襪,情趣用品加盟AIO交友愛情館,情人歡愉用品,美女視訊,情色交友,視訊交友,辣妹視訊,美女交友,嘟嘟成人網,成人網站,A片,A片下載,免費A片,免費A片下載愛情公寓,情色,舊情人,情色貼圖,情色文學,情色交友,色情聊天室,色情小說,一葉情貼圖片區,情色小說,色情,色情遊戲,情色視訊,情色電影,aio交友愛情館,色情a片,一夜情,辣妹視訊,視訊聊天室,免費視訊聊天,免費視訊,視訊,視訊美女,美女視訊,視訊交友,視訊聊天,免費視訊聊天室,情人視訊網,影音視訊聊天室,視訊交友90739,成人影片,成人交友,美女交友,微風成人,嘟嘟成人網,成人貼圖,成人電影,A片,豆豆聊天室,聊天室,UT聊天室,尋夢園聊天室,男同志聊天室,UT男同志聊天室,聊天室尋夢園,080聊天室,080苗栗人聊天室,6K聊天室,女同志聊天室,小高聊天室,上班族聊天室,080中部人聊天室,同志聊天室,聊天室交友,中部人聊天室,成人聊天室,一夜情聊天室,情色聊天室,寄情築園小遊戲情境坊歡愉用品,情趣用品,成人網站,情人節禮物,情人節,AIO交友愛情館,情色,情色貼圖,情色文學,情色交友,色情聊天室,色情小說,七夕情人節,色情,情色電影,色情網站,辣妹視訊,視訊聊天室,情色視訊,免費視訊聊天,美女視訊,視訊美女,美女交友,美女,情色交友,成人交友,自拍,本土自拍,情人視訊網,視訊交友90739,生日禮物,情色論壇,正妹牆,免費A片下載,AV女優,成人影片,色情A片,成人論壇,情趣,免費成人影片,成人電影,成人影城,愛情公寓,成人影片,保險套,舊情人,微風成人,成人,成人遊戲,成人光碟,色情遊戲,跳蛋,按摩棒,一夜情,男同志聊天室,肛交,口交,性交,援交,免費視訊交友,視訊交友,一葉情貼圖片區,性愛,視訊,視訊聊天,A片,A片下載,免費A片,嘟嘟成人網,寄情築園小遊戲,女同志聊天室,免費視訊聊天室,一夜情聊天室,聊天室

vuong said...

先物 比較
先物 比較
先物 比較
先物 比較
先物 比較
先物 比較
先物 比較
先物 比較
事業再生
経営計画書
経営改革
経営改善
会社分割
経営コンサルティング
お見合いパーティー 名古屋
お見合いパーティー 名古屋
お見合いパーティー 名古屋
お見合いパーティー 名古屋
お見合いパーティー 名古屋
お見合いパーティー 名古屋
お見合いパーティー 名古屋
お見合いパーティー 名古屋
お見合いパーティー 名古屋
お見合いパーティー 名古屋
浮気調査 浅草
浮気調査 市川
備考調査 追跡調査 東京
不倫調査 離婚調査 東京
浮気調査 素行調査 東京 
ストーカー相談 ストーカー対策 東京
結婚調査 結婚詐欺 東京
信用調査 企業調査 東京
調査料金 東京
身上調査 身元調査 身辺調査 東京
所在調査 東京
夫 妻 浮気 東京

vuong said...

大規模修繕
大規模修繕
大規模修繕
大規模修繕
大規模修繕
大規模修繕
大規模修繕
大規模修繕
大規模修繕
大規模修繕
英会話 横浜
英語 メール
英語塾
社会人入試
toeic対策
ライムライト
紙箱
会社設立 手続き
派遣 事務
東横 賃貸
田園都市 賃貸
デザイナーズ 賃貸
恵比寿 賃貸
学芸大学 賃貸
目黒 賃貸
中目黒 賃貸
新築 賃貸
ペット可 賃貸
三軒茶屋 賃貸
パチンコ求人
販売管理
債務整理
任意整理
液晶テレビ 激安
先物 比較
先物 比較

Anonymous said...

Kauassi,
We use java stored procedure extensivly in our application. We have two version of functionality one is in interactive mode (web app) and in batch mode. The same code is used in java stored procedure. What we have noticed that Java stored procedure run lot slower that weblogic execution. I am using native compiliation with the help of loadjava command, (loadjava -nativecompile -v -u prod/password@schema /u01/oracle/gmapps/gpsc/int/dbproc.jar)

which helped, still we need performance enhancement. When I am trying to use ncomp I am getting

/u01/oracle/product/11.01.00.06/bin/ncomp: -DJA_HOME=/u01/oracle/product/11.01.00.06/javavm/jahome: not found

But I can traverse to the directory.

Any idea ?

Kuassi Mensah said...

Hi,

I am glad to read that you use Java in the database.
NCOMP does not understand -D; i think you should set ORACLE_HOME and JA_HOME beforehand. As you know the JIT is much more transparent but requires 11g database.

Regarding performance, i assume you have installed the NCOMP libraries for the system classes.
If both the system classes and your application classes are NCOMPed, and you are doing database operations (SQL), Java in the database should be faster; unless your application is very compute-bound.

Kuassi.

facebook entrar said...

Mother pretended phone input jack see it muttering something at the side facebook entrar perfil , facebook entrar mi cuenta , facebook entrar login , girl.go.games , facebook entrar , facebook entrar , facebook entrar