ruby-thread | Various extensions to the base thread library | Architecture library
kandi X-RAY | ruby-thread Summary
kandi X-RAY | ruby-thread Summary
Various extensions to the base thread library.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of ruby-thread
ruby-thread Key Features
ruby-thread Examples and Code Snippets
Community Discussions
Trending Discussions on ruby-thread
QUESTION
I am trying to ping a large amount of urls and retrieve information regarding the certificate of the url. As I read in this thoughtbot article here Thoughtbot Threads and others, I've read that the best way to do this is by using Threads. When I implement threads however, I keep running into Timeout errors and other problems for urls that I can retrieve successfully on their own. I've been told in another related question that I asked earlier that I should not use Timeout with Threads. However, the examples I see wrap API/NET::HTTP/TCPSocket calls in the Timeout block and based opn what I've read, that entire API/NET::HTTP/TCP Socket call will be nested within the Thread. Here is my code:
...ANSWER
Answered 2020-Feb-11 at 11:16There are several issues:
- You'd not spawn thousands of threads, use a connection pool (e.g https://github.com/mperham/connection_pool) so you have maximum 20-30 concurrent requests going (this maximum number should be determined by testing at which point network performance drops and you get these timeouts).
- It's difficult to guarantee that your code is not broken when you use threads, that's why I suggest you use something where others figured it out for you, like https://github.com/httprb/http (with examples for thread safety and concurrent requests like https://github.com/httprb/http/wiki/Thread-Safety). There are other libs out there (Typhoeus, patron) but this one is pure Ruby so basic thread safety is easier to achieve.
- You should not use
Timeout
(see https://jvns.ca/blog/2015/11/27/why-rubys-timeout-is-dangerous-and-thread-dot-raise-is-terrifying and https://medium.com/@adamhooper/in-ruby-dont-use-timeout-77d9d4e5a001). UseIO.select
or something else.
Also, I suggest you learn about threading issues like deadlocks, starvations and all the gotchas. In your case you are doing a starvation of network resources because all the threads are fighting for bandwidth/network.
QUESTION
I'm attempting to save something to my database via ActiveRecord using ruby-thread's Thread.pool in a Sidekiq job. The odd thing is that the code works fine when executing it manually in my Rails console, but it hangs, without any error, when it is run in Sidekiq.
Here is an example of what I am doing:
...ANSWER
Answered 2017-Feb-14 at 04:43Figured out that this was caused by a deadlock in the dev environment, which explains why it worked in the rails console but not within the dev environment of my rails app. Appears to be specific to Rails 5. It's explained here.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ruby-thread
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page