Code Monkey home page Code Monkey logo

Comments (5)

georgediaz88 avatar georgediaz88 commented on July 1, 2024

@crysper,

So, global variables in general are known to cause some issues when used in a multi-threaded environment. A thread-safe way may be to just reinitialize the connection when used in the code.

For example, each time reinitialize the connection like such:

conn = SFTPClient.new(server, username, password)
# the `.new` above should achieve that

Do you see any problems doing it this way? If you need additional help, please paste some sample code and I'd be glad to take a look and make any further suggestions.

Thanks,
George

from fun_sftp.

crysper avatar crysper commented on July 1, 2024

Thanks for the reply.

The issue is speed and connection management. Each of our users has a SFTP account linked and can connect to their server. For example if they need to upload 20 items, it may require a more than 3 new SFTP connections initalizations in a multi-threaded environment, which takes a long time. It's also hard to disconnect all of them when there are multiple connections in different threads.

from fun_sftp.

georgediaz88 avatar georgediaz88 commented on July 1, 2024

Okay. This may be a more general ruby thing to solve . I haven't heard issues around this gem just yet around speed / connection issues. I'm glad you're bringing it up though.

The fun-sftp gem is a wrapper around Ruby's Net::SFTP library. So, anything you can do here, should funnel down to this library: http://www.rubydoc.info/gems/net-sftp/2.0.5/Net/SFTP. If there's a feature you need added to this gem from that library, we can surely add if it helps.

As for your use case, the fact that it worked in a single-threaded environment how you wanted seems promising and is now just a matter of figuring out for a multi-threaded environment, correct?

So, perhaps sharing information across threads is what you need? It's hard for me to truly understand the problem at whole without some kind of sample code -- here's a link that may help give you some inspiration with how folks used the ConnectionPool to spread connections: http://stackoverflow.com/questions/28113940/what-is-the-best-way-to-use-redis-in-a-multi-threaded-rails-environment-puma. Hope this helps.

from fun_sftp.

georgediaz88 avatar georgediaz88 commented on July 1, 2024

@crysper were you able to find a workaround? I can close this issue if you did.

from fun_sftp.

georgediaz88 avatar georgediaz88 commented on July 1, 2024

Closing due to no response.

from fun_sftp.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.