Sanders the Softwarer
Sanders the Softwarer

Reputation: 2496

Unimaginable speed of sockets into Oracle JVM

I'm working with Oracle and I'm asked to speed up some legacy application. For this speedup I'm in need of some in-memory singleton containing temporary data; currently these data are stored into database permanent tables and it imposes much load to database. Temporary tables cannot be used due to multi-session access to data.

I tried to make this singleton using stored Java. Main problem I found - Oracle makes something like separate JVM for every database session (https://docs.oracle.com/cd/B28359_01/java.111/b31225/chtwo.htm#BABBDCDI), so singleton cannot be accessed via common memory.

I makes some API containting "server" (singleton) and "client" (access methods). Client communicates with server via local sockets. Because single-threaded nature of stored Java (https://docs.oracle.com/cd/B28359_01/java.111/b31225/chtwo.htm#BABHHHDG) server accepts and processes requests into a single thread like this (simplified):

    ServerSocket socket = new ServerSocket(..., InetAddress.getByName(null));
    while (!finished) {
      Socket client = socket.accept();
      ..
      output.println(process(input));
      ..
      client.close();
    }

Client sends request like this:

  Socket socket = new Socket(InetAddress.getByName(null), getPort(requestId));
  ..
  for (int i = 0; i < data.length; i++) output.println(data[i]);
  String result = in.readLine();
  ..
  socket.close();

While runnings tests as a stand-alone Java application, without Oracle, it works like this on my workstation:

34001 calls served at 3.178 sec.

Avg. 10698.86721208307 calls per second

Avg. wait time: 0.03199905885121026 ms.

Avg. process time: 0.0628510926149231 ms.

It's generally acceptable. But when loading into Oracle, such test shows a very different speed:

117 calls served at 24.218 sec.

Avg. 4.831117350730861 calls per second

Avg. wait time: 90.17094017094017 ms.

Avg. process time: 203.54700854700855 ms.

Why it's so slow? What can I do to repair this nonsense? Is there better way to communicate between sessions in Oracle/jvm?

Upvotes: 1

Views: 147

Answers (1)

Sanders the Softwarer
Sanders the Softwarer

Reputation: 2496

As a result of investigation.

  1. Administrators said nothing interesting about i/o quests requests length etc.

  2. Oracle's internal java is several times slower than stand-alone one. I wrote a simple example, in which converts integer to string and put it into map; it works about to 4 time slower in stored procedure. Penalty is different for various operations.

  3. I profiled class. Using different techniques (nodelay, reusing sockets, threading) I reached about to 8 times faster in stand-alone application and about to 100 times faster in stored Java, it was limit I can do.

  4. At this moment I refused of stored-java-only. I started an stand-alone application with server part near the database and set up client part into database to connect it. It grants me speed I required; in such case effective speed is about 80% of stand-alone application. This speed is enough for me; it stopped to be a bottleneck.

Upvotes: 1

Related Questions