Giter VIP home page Giter VIP logo

ione's Introduction

Ione

Build Status Coverage Status Blog

If you're reading this on GitHub, please note that this is the readme for the development version and that some features described here might not yet have been released. You can find the readme for a specific version either through rubydoc.info or via the release tags (here is an example).

Ione is a framework for reactive programming in Ruby. It is based on the reactive core of cql-rb, the Ruby driver for Cassandra.

Features

Futures & promises

At the core of Ione is a futures API. Futures make it easy to compose asynchronous operations.

Evented IO

A key piece of the framework is an IO reactor with which you can easily build network clients and servers.

Byte buffer

Networking usually means pushing lots of bytes around and in Ruby it's easy to make the mistake of using strings as buffers. Ione provides an efficient byte buffer implementation as an alternative.

Examples

The examples directory has some examples of what you can do with Ione, for example:

  • redis_client is a more or less full featured Redis client that uses most of Ione's features.
  • http_client is a simplistic HTTP client that uses Ione and http_parser.rb to make HTTP GET request. It also shows how to make TLS connections.
  • cql-rb is a high performance Cassandra driver and where Ione was originally developed.
  • cassandra-driver is the successor to cql-rb.
  • ione-rpc is a RPC framework built on Ione. It makes it reasonably easy to build networked applications without having to reinvent the wheel.

How to contribute

See CONTRIBUTING.md

Copyright

Copyright 2013โ€“2014 Theo Hultberg/Iconara and contributors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

ione's People

Contributors

eprothro avatar grddev avatar iconara avatar mthssdrbrg avatar rejeep avatar roguelazer avatar stenlarsson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ione's Issues

Ione::Future.all([]) broken

Ione::Future.all([]).value fails with "No live threads left. Deadlock?" instead of returning a resolved future.

Can be easily fixed by swapping the first two lines of the method.

EAGAIN / EWOULDBLOCK Error

A user running v2.1.5 of the DataStax Ruby driver encountered a 'write would block' error message when communicating with a node. We believe the underlying error is an EAGAIN or EWOULDBLOCK when attempting to write to the socket.

Looking at the ione code (v1.2.0 for C* driver 2.1.5), I don't see how we could end up with that error -- writes seem rely strictly on select returning a write-fd-set, so if the fd isn't writable, it shouldn't get a write attempt.

Nonetheless, it seems like in some cases it does get this error, so ione should catch it and drop it. Presumably a later write attempt will succeed as time elapses and the kernel buffer for the socket gradually empties.

Schedule work on next tick

If you need to execute something on the reactor thread, or need a simple way to break long-running handlers into multiple steps it would be nice to have a way to execute something at the next reactor tick.

While it is possible to achieve the same effect with short interval timers, I think it makes sense from an API standpoint to separate the two. Also, I'm sure this can be implemented with much lower overhead.

Performance problems when many timers are scheduled

The timer handling code does linear scans and copies on timer scheduling and checking. This make it very inefficient when many timers are scheduled (e.g. when many concurrent requests are sent to Cassandra with timeouts).

Issue with cassandra ruby driver, timecop and ione

Hello @iconara!

Figured this would be as good of a spot as any to ask this question, but we discovered an issue when using ione with the ruby cassandra driver and timecop. Specifically, this is the situation.

  1. Configure and launch a cassandra server locally.
  2. Configure an rspec suite for integration tests against the cassandra server.
  3. Ensure the cassandra idle_timeout is set to the default value (60)
  4. Adjust time using timecop to sometime in the future past 60 seconds.

Result:
The test will fail with a cassandra timeout error, as the scheduled ione timer for the idle_timeout has not been rescheduled, and the on_value timeout function has been called.

Given this, I could see an argument for either calling this a cassandra ruby driver issue, or a ione issue--if you'd like me to report this somewhere else, please let me know.

However, my question is: What is the best way to utilize timecop with ione?

Reactor dies unexpectedly

after modifying io_reactor.rb by adding the following on line 136:

rescue => e
  puts "#{e.class.name}: #{e.message}\n" + Array(e.backtrace).join("\n")

I get the following error:

TypeError: can't convert Ione::Io::Connection to IO (Ione::Io::Connection#to_io gives NilClass)
/home/kishan/.rvm/gems/ruby-1.9.3-p547@global/gems/ione-1.2.0/lib/ione/io/io_reactor.rb:396:in `select'
/home/kishan/.rvm/gems/ruby-1.9.3-p547@global/gems/ione-1.2.0/lib/ione/io/io_reactor.rb:396:in `tick'
/home/kishan/.rvm/gems/ruby-1.9.3-p547@global/gems/ione-1.2.0/lib/ione/io/io_reactor.rb:133:in `block in start'
integration/test.rb:38:in `join': deadlock detected (fatal)
    from integration/test.rb:38:in `block in create_sessions_concurrently2'
    from integration/test.rb:38:in `each'
    from integration/test.rb:38:in `create_sessions_concurrently2'
    from integration/test.rb:15:in `run_test'
    from integration/test.rb:61:in `<main>'

The issue is that the connections are created and closed from different threads, here is a trimmed down sample that consistently fails on linux, while passing on OS X:

require 'bundler/setup'
require 'cassandra'
require 'cassandra/version'

puts Cassandra::VERSION

class Test
  def run_test
    cluster_list = []
    cluster_list << Cassandra.cluster

    session_list = create_sessions_concurrently2(cluster_list[0], 1)
    p session_list
    session_list = close_sessions_concurrently2(session_list, 1)
    p session_list

    session_list2 = create_sessions_concurrently2(cluster_list[0], 1) # DEADLOCK HERE
    p session_list2

    session_list = close_sessions_concurrently2(session_list2, 1)
    p session_list
    cluster_list[0].close
  end

  def create_sessions_concurrently2(cluster, num_sessions)
    sessions = []
    threads = (1..num_sessions).map do
      Thread.new do
        begin
          session = cluster.connect
          sessions << session
        rescue Exception => e
          # session.close
          raise RuntimeError.new("Error while creating a session. #{e.class.name}: #{e.message}
                                          Backtrace: #{e.backtrace.inspect}")
        end
      end
    end

    threads.each {|th| th.join} # DEADLOCK HERE
    sessions
  end

  def close_sessions_concurrently2(session_list, num_sessions)
    session_list2 = session_list[0...num_sessions]
    threads = session_list2.map do |session|
      Thread.new do
        begin
          session.close
          session_list.delete(session)
        rescue Exception => e
          raise RuntimeError.new("Error while closing a session. #{e.class.name}: #{e.message}
                                  Backtrace: #{e.backtrace.inspect}")
        end
      end
    end

    threads.each {|th| th.join}
    session_list
  end
end

Test.new.run_test

I believe there is a race between close and connected? that causes a closing socket to be added to the poll list.

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.