Ensure All Roads Lead to Your Goal (+ Ruby Threads)

The Zen Abstract Design Side

Our world is a function of pre-existing inertia (environment), uncontrollable events, and my personal favorite the malleable future that we craft together. We are challenged daily to pull our sum experiences together to overcome barriers. The greater our ability to collaborate and scale these walls, the further we can go, and the more wonderous our creations. Take stock of your victories, even if they appear to be the product of luck!

Design Challenge, Calling And Waiting on APIs is too Slow

Last night while working with Tyler on improving extracted keywords/entities we discovered a design tradeoff. In this case it was speed versus quality. We focused on the delays of superior quality entity returns and it occurred to me we could spawn many threads to simultaneously call the processing API to relieve sequential user wait time. Neither of us has done multithreaded Ruby coding before so it was new ground. Background processing of information is our main approach but the Twitter streaming API isn’t fully open, and since we are focused on growth we expect many new users (for which we won’t have preprocessed results).

Ruby just happens to make threading incredibly simple to implement:
threadID = Thread.new {
*threadcode*
}

threadID.join()

Literally. in a manner of seconds we had sped up a series of API calls to a single batch call (N x user calls was now the slowest of all the calls, a speedup up of potentially hundreds of seconds for large lists of new users). The only detail is when to rejoin the threads. Naturally collapsing the calls will happen before visualizing their outputs. Additional care must be taken for memory writing and storing their returns in a structure. Threads allow local storage to keep API returns, and we need to ensure that we don’t create a thread for the same user more than once (should have that working this afternoon). The coding experience has been phenomenal compared to threading in C++ (a bit trickier), so kudos to Ruby language designers. Many modern languges keep the simplicity of concurrency at the top of their priority list (even C++ is including simpler handling in the new standard).

Now Back to Zen thanks to Dave

I’ll leave off with a powerful poem passed along by my “cynicism guru” Daveinhackensack (Dave believes the scarcity of optimism boosts its value ;) ).
“It comes from this poem by the great New Jersey man of letters Stephen Crane”

There was set before me a mighty hill,
And long days I climbed
Through regions of snow.
When I had before me the summit-view,
It seemed that my labour
Had been to see gardens
Lying at impossible distances.

May all paths lead to beautiful gardens.

Reblog this post [with Zemanta]
Share and Enjoy:
  • Digg
  • Facebook
  • Google Bookmarks
  • HackerNews
  • Reddit
  • StumbleUpon
  • Twitter

About Mark Essel

I’m Mark Essel, a dataminer & systems engineer that’s added cofounder, web developer and author to my bag of tricks. My quest is to rediscover my life’s passions, and leverage that drive into profitable business ventures.
This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.
  • http://www.thehackensack.blogspot.com/ DaveinHackensack

    It's funny how you focus on the beautiful gardens instead of the impossible distances. You're a true optimist, which is a good thing. Beats the alternative.

    I don't think Crane was much of an optimist, but his poetry is enriched by his world-weariness. Here's a great poem of his to keep in mind next time you get drawn into an argument on the Internet:

    I saw a man pursuing the horizon;
    Round and round they sped.
    I was disturbed at this;
    I accosted the man.
    “It is futile,” I said,
    “You can never -”

    “You lie,” he cried,
    And ran on.

  • http://www.victusspiritus.com/ Mark Essel

    You have me pegged, I had utterly missed the impossible distance as just a minor inconvenience. The garden draws out my best so that is what I focus on. I'm fully capable of believing the worst of people and situations, but I find that myself and the world benefits more from seeing the best in others. It's so easy to forget all that we accomplish, and all the good we do because cognitively we hardwired to remember the negative more clearly.

  • http://www.thehackensack.blogspot.com/ DaveinHackensack

    I'll leave you with a more positive Stephen Crane poem, which I think you might like:

    There was a man with tongue of wood
    Who essayed to sing,
    And in truth it was lamentable.
    But there was one who heard
    The clip-clapper of this tongue of wood
    And knew what the man
    Wished to sing,
    And with that the singer was content.

  • http://www.victusspiritus.com/2010/01/01/practical-first-rails-threading-example/ Practical First Rails Threading Example » Victus Spiritus

    [...] Ensure All Roads Lead to Your Goal (+ Ruby Threads) Candy to the Imagination, a Day Trip to [...]

blog comments powered by Disqus