4

I'm developing API for product based on Oracle database and I tried to use ruby-oci8 gem, but I faced a strange problem - OCI8.new is very slow, it takes 1,2-1,5 second to connect to database.

For example:

~ mmulev$ irb
2.1.1 :001 > require 'oci8'
 => true 
2.1.1 :002 > def test
2.1.1 :003?>   t0 = Time.now
2.1.1 :004?>   OCI8.new('SCHEMA', 'STRONG_PASS', '//db_host:port/service_name')
2.1.1 :005?>   Time.now - t0
2.1.1 :006?>   end
 => :test 
2.1.1 :007 > test
 => 1.217809 
2.1.1 :008 >

The same thing in php (oci_new_connect) needs approximately 0,1-0,2 second to establish connection and return handler.

Is there any other solutions besides connection pooling?

P.S. ruby API code was profiled by method_profiler and by Benchmark, oracle v - 11g

Mike Mulev
  • 76
  • 7
  • Are you using the exact same connection string for PHP? Do you have multiple `ORACLE_HOME`s on your client? – Frank Schmitt Sep 23 '14 at 20:23
  • Sure, use a [n-tier](http://en.wikipedia.org/wiki/Multitier_architecture) design and connect from ruby (or php) to your middle-tier. Of course, your middle-tier will probably need a connection pool to connect to your database with decent performance. – Elliott Frisch Sep 24 '14 at 00:25
  • @frank-schmitt, connection string is the same and ORACLE_HOME is only one – Mike Mulev Sep 24 '14 at 04:32
  • 4
    Use the force. Use strace, and you will see where it hangs. – ibre5041 Sep 24 '14 at 20:59
  • FWIW, this is not reproducible. Connecting to a local XE instance in a Docker container with `OCI8.new('user', 'pass', '//localhost:1521/xe')` took 0.015 seconds. – Frank Schmitt Jan 07 '16 at 19:10

1 Answers1

-1

You can also use this gem to connect to oracle

https://github.com/rsim/oracle-enhanced

Make sure that you have installed oracle properly you can install this by following link : How to install ruby-oci8?

Community
  • 1
  • 1
Ranjith
  • 145
  • 6
  • How does this answer the question? That gem seems to be an ActiveRecord wrapper around ruby-oci8 - how could using that be faster than plain ruby-oci8? – Frank Schmitt Mar 05 '15 at 11:35
  • using the oracle-enhanced gem you can easily configure your rails app and query the database . If database read/write becomes slow then you may have to index some fields or some other issues with database :) – Ranjith Mar 05 '15 at 12:43
  • Sorry, but this is totally irrelevant to the question. The OP didn't mention Rails at all (*Ruby != Rails*), and creating indices will certainly *not* speedup logging on to the database. – Frank Schmitt Mar 05 '15 at 14:27
  • ? The question doesn't contain the words *Rails* or *REST*, so IMHO this answer is still irrelevant. But YMMV, of course. – Frank Schmitt Mar 06 '15 at 07:21