我正在为基于 Oracle 数据库的产品开发 API,我尝试使用 ruby-oci8 gem,但我遇到了一个奇怪的问题 - OCI8.new 非常慢,连接需要 1,2-1,5 秒到数据库。
例如:
~ 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 >
在 php (oci_new_connect) 中,同样的事情需要大约 0.1-0.2 秒来建立连接并返回处理程序。
除了连接池还有其他解决方案吗?
附言ruby API 代码由 method_profiler 和 Benchmark、oracle v - 11g 分析
最佳答案
你也可以使用这个gem连接到oracle
https://github.com/rsim/oracle-enhanced
确保您已正确安装 oracle,您可以通过以下链接进行安装:How to install ruby-oci8?
关于ruby OCI8 初始化缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26003514/