Multiple exec calls on the same connection from threads

瀏覽次數:12 次
跳到第一則未讀訊息

Refael Dakar

未讀,
2017年7月11日 下午1:45:062017/7/11
收件者:ruby-pg
Hey,

I'm trying to run multiple exec calls from different threads asynchronous and I'm getting memory errors. I had to go back to opening and closing a connection for every thread which makes things work a lot slower.

Any ideas how this can be done ?

Thanks!

Refael

Lars Kanis

未讀,
2017年7月11日 下午2:10:242017/7/11
收件者:rub...@googlegroups.com


On Jul 11, 2017 19:45, "Refael Dakar" <refae...@gmail.com> wrote:
Hey,

I'm trying to run multiple exec calls from different threads asynchronous and I'm getting memory errors.

This is normal. Consider, there's a single TCP connection as communication channel, which is filled and read out by simultaneous threads. Command and result sequences get mixed to a great garbage.

I had to go back to opening and closing a connection for every thread which makes things work a lot slower.

Unfortunately that's the way to go.


Any ideas how this can be done ?

It is possible to use a single connection object from different threads - but only if you ensue, that any handover to a different thread is only done, when the connection is in idle state.

--
Regards,
Lars

Refael Dakar

未讀,
2017年7月12日 凌晨2:16:172017/7/12
收件者:rub...@googlegroups.com
Got it. Thanks man!

--
You received this message because you are subscribed to a topic in the Google Groups "ruby-pg" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ruby-pg/7NVpUYgay58/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ruby-pg+unsubscribe@googlegroups.com.
To post to this group, send email to rub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-pg/CAHXCYb1j%3D81TWJH69ZsRoE0dQxYE91KT%2BKhABFPDoUCG2BCG5g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Refael Dakar


Robert Klemme

未讀,
2017年7月12日 凌晨2:35:452017/7/12
收件者:rub...@googlegroups.com
On Wed, Jul 12, 2017 at 8:16 AM, Refael Dakar <refae...@gmail.com> wrote:
On Tue, Jul 11, 2017 at 9:10 PM, Lars Kanis <la...@greiz-reinsdorf.de> wrote:
On Jul 11, 2017 19:45, "Refael Dakar" <refae...@gmail.com> wrote:
 
I had to go back to opening and closing a connection for every thread which makes things work a lot slower.

Unfortunately that's the way to go.

Well, one can of course use a connection pool which avoids the repeated opening and closing of connections. Or use one connection per thread and close it only when the thread terminates. That all depends on the circumstances.

Cheers

robert

-- 
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can - without end}
http://blog.rubybestpractices.com/

Refael Dakar

未讀,
2017年7月12日 凌晨2:49:362017/7/12
收件者:rub...@googlegroups.com
Do you have a connection pool code I can use?

--
You received this message because you are subscribed to a topic in the Google Groups "ruby-pg" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ruby-pg/7NVpUYgay58/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ruby-pg+unsubscribe@googlegroups.com.
To post to this group, send email to rub...@googlegroups.com.

Robert Klemme

未讀,
2017年7月12日 凌晨3:17:522017/7/12
收件者:rub...@googlegroups.com
On Wed, Jul 12, 2017 at 8:49 AM, Refael Dakar <refae...@gmail.com> wrote:
> Do you have a connection pool code I can use?

Search: https://duckduckgo.com/?q=ruby+gem+pool&t=canonical&ia=software
Hit: https://rubygems.org/gems/connection_pool/versions/2.2.1

Refael Dakar

未讀,
2017年7月12日 清晨5:17:552017/7/12
收件者:ruby-pg
perfect. thanks!
回覆所有人
回覆作者
轉寄
0 則新訊息