Solve the problem of fast and slow Jdbc connection to oracle 12c (12.1.0.1)

Source: Internet
Author: User
Tags firewall


A customer from a friend company helps with analysis. The customer uses oracle 12c (12.1.0.1), and the application uses jdbc to access the database. However, it is found that everything works normally through sqlplus access.
I thought it was a Firewall problem. I checked and found that the firewall was disabled or even modified selinux = disable.
Since several similar cases have been handled before, they are all about the jdbc version, so I asked them to change to several jdbc versions for testing and found that the problem persists. Similar results:


[Oracle @ 12c_single ~] $/Oracle/product/12.1/db_1/jdk/bin/java-jar a16_12101.jar
18:19:20
Start:
??????
??????
Init
??????
??????
Init
End.
18:19:21
[Oracle @ 12c_single ~] $/Oracle/product/12.1/db_1/jdk/bin/java-jar a16_12101.jar
18:19:23
Start:
??????
??????
Init
??????
??????
Init
End.
18:19:43
[Oracle @ 12c_single ~] $/Oracle/product/12.1/db_1/jdk/bin/java-jar a16_12101.jar
18:19:48
Start:
??????
??????
Init
??????
??????
Init
End.
18:19:56
[Oracle @ 12c_single ~] $/Oracle/product/12.1/db_1/jdk/bin/java-jar a16_12101.jar
18:19:59
Start:
??????
??????
Init
??????
??????
Init
End.
18:20:17

Later I found some clues through the strace trace, the following trace results:


Strace-fr/oracle/product/12.1/db_1/jdk/bin/java-jar a16_12101.jar
.....
[Pid 17242] 0.000142 stat ("/dev/random", {st_mode = S_IFCHR | 0666, st_rdev = makedev (1, 8),...}) = 0
[Pid 17242] 0.000084 stat ("/dev/urandom", {st_mode = S_IFCHR | 0666, st_rdev = makedev (1, 9),...}) = 0
[Pid 17242] 0.000376 lseek (3, 46548757, SEEK_SET) = 46548757
[Pid 17242] 0.000037 read (3, "PK \ 3 \ 4 \ n \ 0 \ 0 \ 0 \ 0 \ 201 ^ 8A \ 275} \ 357 ^ K \ 16 \ 0 \ 0K \ 16 \ 0 \ 0 \ 0/\ 0 \ 0 \ 0 ", 30) = 30
[Pid 17242] 0.000046 lseek (3, 46548834, SEEK_SET) = 46548834
[Pid 17242] 0.000032 read (3, "\ 312 \ 376 \ 272 \ 276 \ 0 \ 0 \ 0001 \ 0 \ 245 \ 10 \ 0 \ r \ 10 \ 0 \ 22 \ 10 \ 0) \ 10 \ 0. \ 10 \ 0: \ 10 \ 0 @ \ 1 \ 0 \ 3 ("..., 3659) = 3659
[Pid 17242] 0.000275 open ("/dev/random", O_RDONLY) = 10
[Pid 17242] 0.000042 fstat (10, {st_mode = S_IFCHR | 0666, st_rdev = makedev (1, 8),...}) = 0
[Pid 17242] 0.000033 fcntl (10, F_GETFD) = 0
[Pid 17242] 0.000023 fcntl (10, F_SETFD, FD_CLOEXEC) = 0
[Pid 17242] 0.000055 open ("/dev/urandom", O_RDONLY) = 11
[Pid 17242] 0.000032 fstat (11, {st_mode = S_IFCHR | 0666, st_rde
........
[Pid 17250] 0.000044 futex (0x7fb5ec0b9528, FUTEX_WAKE_PRIVATE, 1) = 0
[Pid 17250] 0.000058 futex (0x40110734, FUTEX_WAIT_BITSET_PRIVATE | FUTEX_CLOCK_REALTIME, 1, {1385288524,652 223000}, ffffffff) =-1 ETIMEDOUT (Connection timed out)
[Pid 17250] 0.050426 futex (0x7fb5ec0b9528, FUTEX_WAKE_PRIVATE, 1) = 0
[Pid 17250] 0.000060 futex (0x40110734, FUTEX_WAIT_BITSET_PRIVATE | FUTEX_CLOCK_REALTIME, 1, {1385288524,702 709000}, ffffffff) =-1 ETIMEDOUT (Connection timed out)
[Pid 17250] 0.050573 futex (0x7fb5ec0b9528, FUTEX_WAKE_PRIVATE, 1) = 0
[Pid 17250] 0.000044 futex (0x40110734, FUTEX_WAIT_BITSET_PRIVATE | FUTEX_CLOCK_REALTIME, 1, {1385288524,753 331000}, ffffffff) =-1 ETIMEDOUT (Connection timed out)
[Pid 17250] 0.050433 futex (0x7fb5ec0b9528, FUTEX_WAKE_PRIVATE, 1) = 0
........
Until the value of futex is timeout, which takes more than 10 seconds. Among them, open ("/dev/random", O_RDONLY) caught my attention. Many people have searched google for it.
Oracle has enhanced the security of jdbc since the 11g, which is probably explained as follows:
The JDBC 11g needs about 40 bytes of secure random numbers, gathered from/dev/random, to encrypt its connect string.
The solution is to modify the following content in the Java. security file under java_home:
Securerandom. source = file:/dev/random: securerandom. source = file:/dev/urandom
When I checked the configuration file, I found it was securerandom. source = file:/dev/urandom. At this point, I seem to have a problem with the jdbc version or 12c itself.
Upload the client's jar to your own 12.1.0.1 and 12.1.0.2 environments for testing. It is found that the phenomenon is the same, and the time is fast and slow.
After tracking through strace, we found that the information is similar to the strace result in the customer's environment, which is very strange.
I suspect that this configuration file does not work. Finally, I searched the mos and found a document:
How To Configure Database JVM (JavaVM) To Use/dev/urandom (In Order To Avoid JDBC Connection Delays Due To Lack Of Random Number Entropy) (ID 1594701.1)
We recommend that you directly modify the configuration file as follows:


1) Set a system property in your Java code:
 
System. setProperty ("java. security. egd", "file: // dev/urandom"); // the 3'/'are important to make it a URL
 
2) Set a database system property:
 
Declare
C_property varchar2 (32767 );
Begin
C_property: = dbms_java.set_property ('Java. security. Egd', '/dev/urandom ');
End;
 
The database user needs a privilege in order to execute this call:
 
Begin
Dbms_java.grant_permission (
Grantee => '{Database Schema }',
Permission_type => 'sys: java. util. PropertyPermission ',
Permission_name => 'Java. security. Egd ',
Permission_action => 'Read, write'
);
End;

After modifying according to this docs, I tested again and found that everything was normal .... The test process is as follows:


[Oracle @ 12c_single ~] $/Oracle/product/12.1/db_1/jdk/bin/java-jar a16_12101_new.jar
19:06:41
Start:
??????
??????
Init
??????
??????
Init
End.
19:06:42
[Oracle @ 12c_single ~] $/Oracle/product/12.1/db_1/jdk/bin/java-jar a16_12101_new.jar
19:06:43
Start:
??????
??????
Init
??????
??????
Init
End.
19:06:43
[Oracle @ 12c_single ~] $/Oracle/product/12.1/db_1/jdk/bin/java-jar a16_12101_new.jar
19:06:45
Start:
??????
??????
Init
??????
??????
Init
End.
19:06:45

This case is not complex and simple. Please share it with us. Thank you!
Note: it is best to use oracle's own java to maintain the same version. I tested it here and found that if the OS's own java version is used, the connection will still be slow.


[Oracle @ 12c_single ~] $ Java-jar a16_121020.new.jar
19:09:20
Start:
??????
??????
Init
??????
??????
Init
End.
19:09:46
[Oracle @ 12c_single ~] $ Java-version
Java version "1.6.0 _ 22"
OpenJDK Runtime Environment (IcedTea6 1.10.4) (rhel-1.41.1.10.4.el6-x86_64)
OpenJDK 64-Bit Server VM (build plugin 0-b11, mixed mode)

This version is obviously lower than the requirements in the Oracle 12.1.0.1 official documentation. It must be 1.6.0 _ 37 or later.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.