Code Monkey home page Code Monkey logo

tarantool.cr's Introduction

Tarantool

Built with Crystal Build status API Docs Releases Awesome vladfaust.com Patrons count Gitter chat

The Tarantool driver for Crystal.

Supporters

Thanks to all my patrons, I can continue working on beautiful Open Source Software! ๐Ÿ™

Lauri Jutila, Alexander Maslov, Dainel Vera

You can become a patron too in exchange of prioritized support and other perks

Become Patron

About

Tarantool is a super-fast NoSQL* in-memory database. Crystal is a super-fast compiled language. Take both.

* It is planned to fully support SQL in version 2, which is currently in alpha

Benchmarks

Recent benchmarking of 100k select requests on a single 0.90Ghz CPU core with Tarantool running on the same machine via Docker:

$ crystal bench/select.cr --release
  1.530000   1.070000   2.600000 (  2.597737)

Resulting performance is 38.4k RPS, averaging in 26ฮผs per request.

Projects using Tarantool

Installation

Add this to your application's shard.yml:

dependencies:
  tarantool:
    github: vladfaust/tarantool.cr
    version: ~> 0.2.2

This shard follows Semantic Versioning 2.0.0, so see releases and change the version accordingly.

Usage

After you installed and run Tarantool and setup your schema, do:

require "tarantool"

db = Tarantool::Connection.new("localhost", 3301) # Initiate the connection
db.parse_schema # Save current box schema to db instance
db.insert(:examples, {1, "hello"}) # Insert "hello" tuple
db.update(:examples, :primary, {1}, {"=", 1, "hello world"}) # Replace "hello" with "hello world"
db.select(:examples, :name, {"hello world"}).body.data # => [[1, "hello world"]]

All Tarantool::Connection#* requests are synchronous, they will be waiting until the response is received. However, a single Tarantool instance itself is capable of handling lots of simultaneous connections, so for the best perfomance consider running requests in multiple fibers:

32.times do
  spawn do
    db.ping # All 32 pings are executed concurrently
  end
end

Testing

  1. Run docker run --name mytarantool -d -p 3301:3301 -v /var/lib/docker/volumes/tarantool:/var/lib/tarantool tarantool/tarantool:1
  2. Connect to tarantool via console (docker exec -i -t mytarantool console) and apply schema found in /spec/helpers.lua
  3. crystal spec

Contributing

  1. Fork it ( https://github.com/vladfaust/tarantool.cr/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

tarantool.cr's People

Contributors

delef avatar vladfaust avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

tarantool.cr's Issues

Can't compile with Crystal 0.31

In lib/tarantool/src/tarantool/connection.cr:30:5

 30 | @channels = {} of UInt64 => Channel::Unbuffered(Response)
      ^--------
Error: can't infer the type of instance variable '@channels' of Tarantool::Connection

Shorthands

  • Shorthanded iterators (:<=, "lte)
  • Spaces by names (?)
  • Indexes by names (?)

Multiple connections seem to overlap each other

Code to reproduce (add it to the /spec folder):

require "./spec_helper"

db = Tarantool::Connection.new("localhost", 3301)

describe Tarantool do
  context "request with read timeout" do
    it "raises IO::Timeout" do
      db1 = Tarantool::Connection.new("localhost", 3301, read_timeout: 1.second)

      expect_raises IO::Timeout do
        db1.eval("fiber = require('fiber'); fiber.sleep(5)")
      end
    end
  end

  describe "#ping" do
    it do
      db.ping
    end
  end
end

Output:

.E

Failures:

  1) Tarantool #ping assert

       Error sending datagram: Bad file descriptor (Errno)
         from /usr/share/crystal/src/socket.cr:269:5 in 'send'
         from src/tarantool/connection.cr:183:9 in 'send'
         from src/tarantool/connection.cr:171:15 in 'send'
         from src/tarantool/connection/requests.cr:13:11 in 'ping'
         from spec/tarantool_spec.cr:18:7 in '->'
         from /usr/share/crystal/src/spec/methods.cr:255:3 in 'it'

No file: /spec/schema.lua

Connect to tarantool via console (docker exec -i -t mytarantool console) and apply schema found in /spec/schema.lua

/opt/tarantool # ls /spec/schema.lua
ls: /spec/schema.lua: No such file or directory

Benchmarking

Shock the community with the performance ๐Ÿ˜ฆ

Can't install

shards install
Fetching https://github.com/vladfaust/tarantool-crystal.git
Error resolving tarantool (~> 0.1.0)

Others github dependencies install without problems.

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.