├── .rspec ├── .editorconfig ├── .gitignore ├── Gemfile ├── Rakefile ├── examples └── rack │ ├── schema.rb │ └── config.ru ├── .travis.yml ├── spec ├── async │ ├── postgres_spec.rb │ └── activerecord_spec.rb └── spec_helper.rb ├── async-postgres.gemspec ├── lib └── async │ ├── postgres │ ├── version.rb │ ├── connection.rb │ └── pool.rb │ └── postgres.rb └── README.md /.rspec: -------------------------------------------------------------------------------- 1 | --format documentation 2 | --backtrace 3 | --warnings 4 | --require spec_helper -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | indent_size = 2 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /_yardoc/ 4 | /coverage/ 5 | /doc/ 6 | /pkg/ 7 | /spec/reports/ 8 | /tmp/ 9 | 10 | # rspec failure tracking 11 | .rspec_status 12 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | 5 | gem "pg" 6 | 7 | group :development do 8 | gem 'pry' 9 | end 10 | 11 | group :test do 12 | gem 'simplecov' 13 | gem 'coveralls', require: false 14 | end 15 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require "rspec/core/rake_task" 3 | 4 | RSpec::Core::RakeTask.new(:test) 5 | 6 | task :default => :test 7 | 8 | task :console do 9 | require 'pry' 10 | 11 | require_relative 'lib/ffi/postgres' 12 | 13 | Pry.start 14 | end -------------------------------------------------------------------------------- /examples/rack/schema.rb: -------------------------------------------------------------------------------- 1 | gem 'pg' 2 | 3 | if defined?(Falcon) 4 | $stderr.puts "Loading async/postgres" 5 | require_relative '../../lib/async/postgres' 6 | end 7 | 8 | require 'active_record' 9 | 10 | ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "test", pool: 1024) 11 | ActiveRecord::Base.logger = Console.logger 12 | -------------------------------------------------------------------------------- /examples/rack/config.ru: -------------------------------------------------------------------------------- 1 | 2 | require_relative 'schema' 3 | 4 | run lambda {|env| 5 | connection_pool = ActiveRecord::Base.connection_pool 6 | connection = connection_pool.checkout(10) 7 | 8 | 10.times do 9 | connection.execute("SELECT pg_sleep(1)") 10 | end 11 | 12 | connection_pool.checkin(connection) 13 | # ActiveRecord::Base.clear_active_connections! 14 | 15 | [200, {}, ["Asynchronous Postgres\n"]] 16 | } 17 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | dist: xenial 3 | cache: bundler 4 | 5 | services: 6 | - postgresql 7 | before_script: 8 | - psql -c 'create database test;' -U postgres 9 | 10 | matrix: 11 | include: 12 | - rvm: 2.3 13 | - rvm: 2.4 14 | - rvm: 2.5 15 | - rvm: 2.6 16 | - rvm: 2.7 17 | - rvm: 2.6 18 | env: COVERAGE=BriefSummary,Coveralls 19 | - rvm: ruby-head 20 | - rvm: truffleruby 21 | - rvm: jruby-head 22 | env: JRUBY_OPTS="--debug -X+O" 23 | allow_failures: 24 | - rvm: ruby-head 25 | - rvm: truffleruby 26 | - rvm: jruby-head 27 | -------------------------------------------------------------------------------- /spec/async/postgres_spec.rb: -------------------------------------------------------------------------------- 1 | 2 | require 'async/postgres/connection' 3 | 4 | RSpec.describe Async::Postgres::Connection do 5 | include_context Async::RSpec::Reactor 6 | 7 | let(:connection_string) {"host=localhost dbname=test"} 8 | let(:connection) {Async::Postgres::Connection.new(connection_string)} 9 | 10 | it "should execute query" do 11 | reactor.async do 12 | results = connection.async_exec("SELECT 42 AS LIFE") 13 | 14 | expect(results.each.to_a).to be == [{"life" => "42"}] 15 | 16 | connection.close 17 | end 18 | end 19 | 20 | it "should behave like real connection" do 21 | reactor.async do 22 | expect(connection.respond_to?(:conninfo)).to be true 23 | 24 | connection.close 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | 2 | require 'covered/rspec' 3 | require 'async/rspec' 4 | 5 | begin 6 | require 'ruby-prof' 7 | 8 | RSpec.shared_context "profile" do 9 | before(:all) do 10 | RubyProf.start 11 | end 12 | 13 | after(:all) do 14 | result = RubyProf.stop 15 | 16 | # Print a flat profile to text 17 | printer = RubyProf::FlatPrinter.new(result) 18 | printer.print(STDOUT) 19 | end 20 | end 21 | rescue LoadError 22 | RSpec.shared_context "profile" do 23 | before(:all) do 24 | puts "Profiling not supported on this platform." 25 | end 26 | end 27 | end 28 | 29 | RSpec.configure do |config| 30 | # Enable flags like --only-failures and --next-failure 31 | config.example_status_persistence_file_path = ".rspec_status" 32 | 33 | config.expect_with :rspec do |c| 34 | c.syntax = :expect 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /spec/async/activerecord_spec.rb: -------------------------------------------------------------------------------- 1 | 2 | require 'active_record' 3 | 4 | class Book < ActiveRecord::Base 5 | end 6 | 7 | # Good ol' ActiveRecord and it's global state 8 | # https://tenderlovemaking.com/2011/10/20/connection-management-in-activerecord.html 9 | 10 | RSpec.describe ActiveRecord do 11 | include_context Async::RSpec::Reactor 12 | 13 | it "should work using async adapter" do 14 | reactor.async do 15 | ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "test") 16 | ActiveRecord::Base.logger = Logger.new(STDOUT) 17 | 18 | ActiveRecord::Schema.define do 19 | create_table :books, force: true do |t| 20 | t.string :name 21 | t.timestamps 22 | end 23 | end 24 | 25 | Book.create(name: "How to use a fork") 26 | 27 | # This closes the underlying connection. 28 | ActiveRecord::Base.remove_connection 29 | end 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /async-postgres.gemspec: -------------------------------------------------------------------------------- 1 | 2 | require_relative 'lib/async/postgres/version' 3 | 4 | Gem::Specification.new do |spec| 5 | spec.name = "async-postgres" 6 | spec.version = Async::Postgres::VERSION 7 | spec.authors = ["Samuel Williams"] 8 | spec.email = ["samuel.williams@oriontransfer.co.nz"] 9 | spec.summary = %q{Access postgres without blocking.} 10 | spec.homepage = "https://github.com/socketry/async-postgres" 11 | spec.license = "MIT" 12 | 13 | spec.files = `git ls-files`.split($/) 14 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 15 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 16 | spec.require_paths = ["lib"] 17 | 18 | spec.add_dependency "async", "~> 1.3" 19 | spec.add_dependency "pg" 20 | 21 | spec.add_development_dependency "async-rspec" 22 | spec.add_development_dependency "activerecord" 23 | 24 | spec.add_development_dependency "covered" 25 | spec.add_development_dependency "bundler" 26 | spec.add_development_dependency "rspec", "~> 3.6" 27 | spec.add_development_dependency "rake" 28 | end 29 | -------------------------------------------------------------------------------- /lib/async/postgres/version.rb: -------------------------------------------------------------------------------- 1 | # Copyright, 2018, by Samuel G. D. Williams. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | # THE SOFTWARE. 20 | 21 | module Async 22 | module Postgres 23 | VERSION = "0.1.0" 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /lib/async/postgres.rb: -------------------------------------------------------------------------------- 1 | # Copyright, 2018, by Samuel G. D. Williams. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | # THE SOFTWARE. 20 | 21 | require_relative "postgres/version" 22 | require_relative "postgres/connection" 23 | require_relative "postgres/pool" 24 | 25 | require 'pg' 26 | 27 | module PG 28 | def self.connect(connection_string) 29 | Async::Postgres::Proxy.new(connection_string) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /lib/async/postgres/connection.rb: -------------------------------------------------------------------------------- 1 | # Copyright, 2018, by Samuel G. D. Williams. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | # THE SOFTWARE. 20 | 21 | require 'async/wrapper' 22 | 23 | require 'pg/connection' 24 | 25 | module Async 26 | module Postgres 27 | class Connection < Wrapper 28 | def initialize(connection_string, reactor = nil) 29 | @connection = PG::Connection.connect_start(connection_string) 30 | 31 | super(@connection.socket_io, reactor) 32 | 33 | status = @connection.connect_poll 34 | 35 | while true 36 | if status == PG::PGRES_POLLING_FAILED 37 | raise PG::Error.new(@connection.error_message) 38 | elsif status == PG::PGRES_POLLING_READING 39 | self.wait_readable 40 | elsif(status == PG::PGRES_POLLING_WRITING) 41 | self.wait_writable 42 | elsif status == PG::PGRES_POLLING_OK 43 | break 44 | end 45 | 46 | status = @connection.connect_poll 47 | end 48 | end 49 | 50 | def async_exec(*args) 51 | @connection.send_query(*args) 52 | last_result = result = true 53 | 54 | while true 55 | wait_readable 56 | 57 | @connection.consume_input 58 | 59 | while @connection.is_busy == false 60 | if result = @connection.get_result 61 | last_result = result 62 | 63 | yield result if block_given? 64 | else 65 | return last_result 66 | end 67 | end 68 | end 69 | ensure 70 | @connection.get_result until result.nil? 71 | end 72 | 73 | alias exec async_exec 74 | alias exec_params exec 75 | 76 | def respond_to?(*args) 77 | @connection.respond_to?(*args) 78 | end 79 | 80 | def method_missing(*args) 81 | @connection.send(*args) 82 | end 83 | end 84 | end 85 | end 86 | -------------------------------------------------------------------------------- /lib/async/postgres/pool.rb: -------------------------------------------------------------------------------- 1 | # Copyright, 2018, by Samuel G. D. Williams. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | # THE SOFTWARE. 20 | 21 | require 'async/reactor' 22 | 23 | module Async 24 | class Reactor < Node 25 | attr_accessor :postgres_pools 26 | end 27 | 28 | module Postgres 29 | class Proxy 30 | def initialize(connection_string, task: Task.current) 31 | @connection_string = connection_string 32 | 33 | pools = task.reactor.postgres_pools ||= {} 34 | 35 | @pool = pools[@connection_string] ||= Pool.new do 36 | Connection.new(@connection_string) 37 | end 38 | end 39 | 40 | def close 41 | @pool.close 42 | end 43 | 44 | def async_exec(*args) 45 | @pool.acquire do |connection| 46 | connection.async_exec(*args) 47 | end 48 | end 49 | 50 | def respond_to?(*args) 51 | @pool.acquire do |connection| 52 | connection.respond_to?(*args) 53 | end 54 | end 55 | 56 | def method_missing(*args, &block) 57 | @pool.acquire do |connection| 58 | connection.send(*args, &block) 59 | end 60 | end 61 | end 62 | 63 | # This pool doesn't impose a maximum number of open resources, but it WILL block if there are no available resources and trying to allocate another one fails. 64 | class Pool 65 | def initialize(&block) 66 | @available = [] 67 | @waiting = [] 68 | 69 | @constructor = block 70 | end 71 | 72 | def acquire 73 | resource = wait_for_next_available 74 | 75 | begin 76 | yield resource 77 | ensure 78 | @available << resource 79 | 80 | if task = @waiting.pop 81 | task.resume 82 | end 83 | end 84 | end 85 | 86 | def close 87 | @available.each(&:close) 88 | @available.clear 89 | end 90 | 91 | def wait_for_next_available 92 | until resource = next_available 93 | @waiting << Fiber.current 94 | Task.yield 95 | end 96 | 97 | return resource 98 | end 99 | 100 | def next_available 101 | if @available.empty? 102 | return @constructor.call 103 | else 104 | return @available.pop 105 | end 106 | end 107 | end 108 | end 109 | end 110 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Async::Postgres 2 | 3 | **This gem is experimental and unmaintained. Please see https://github.com/socketry/db-postgres for an event driven driver for Postgres.** 4 | 5 | ## Motivation 6 | 7 | We have some IO bound web APIs generating statistics and we sometimes have issues when using [passenger] due to thread/process exhaustion. In addition, we make a lot of upstream HTTP RPCs and these are also IO bound. 8 | 9 | This library, in combination with [async-http], ensure that we don't become IO bound in many cases. In addition, we don't need to tune the intermediate server as it will simply scale according to backend resource availability and IO throughput. 10 | 11 | [passenger]: https://github.com/phusion/passenger 12 | [async-http]: https://github.com/socketry/async-http 13 | 14 | ## Installation 15 | 16 | Add this line to your application's Gemfile: 17 | 18 | ```ruby 19 | gem 'async-postgres' 20 | ``` 21 | 22 | And then execute: 23 | 24 | $ bundle 25 | 26 | Or install it yourself as: 27 | 28 | $ gem install async-postgres 29 | 30 | ## Performance 31 | 32 | For database-bound workloads, this approach yields significant improvements to throughput and ultimately latency. 33 | 34 | Using the example provided, which sleeps in the database for 10x10ms, we expect 10 sequential requests/second: 35 | 36 | ```ruby 37 | run lambda {|env| 38 | 10.times do 39 | ActiveRecord::Base.connection.execute("SELECT pg_sleep(0.01)") 40 | end 41 | 42 | ActiveRecord::Base.clear_active_connections! 43 | 44 | [200, {}, []] 45 | } 46 | ``` 47 | 48 | When running on [puma], with 16 threads, we could expect roughly 16 threads * 10 sequential requests/second. 49 | 50 | ``` 51 | % puma 52 | Puma starting in single mode... 53 | * Version 3.11.2 (ruby 2.5.0-p0), codename: Love Song 54 | * Min threads: 0, max threads: 16 55 | * Environment: development 56 | * Listening on tcp://0.0.0.0:9292 57 | Use Ctrl-C to stop 58 | 59 | % wrk -c 512 -t 128 -d 30 http://localhost:9292 60 | Running 30s test @ http://localhost:9292 61 | 128 threads and 512 connections 62 | Thread Stats Avg Stdev Max +/- Stdev 63 | Latency 105.77ms 4.05ms 176.61ms 98.61% 64 | Req/Sec 37.83 5.64 40.00 84.64% 65 | 4544 requests in 30.09s, 230.75KB read 66 | Requests/sec: 151.00 67 | Transfer/sec: 7.67KB 68 | ``` 69 | 70 | We can see we get close to the theoretical throughput given the number of available threads. 71 | 72 | If we start [puma] with more threads, we get increased throughput. 73 | 74 | ``` 75 | % puma -t 128:128 76 | Puma starting in single mode... 77 | * Version 3.11.2 (ruby 2.5.0-p0), codename: Love Song 78 | * Min threads: 128, max threads: 128 79 | * Environment: development 80 | * Listening on tcp://0.0.0.0:9292 81 | Use Ctrl-C to stop 82 | 83 | % wrk -c 512 -t 128 -d 30 http://localhost:9292 84 | Running 30s test @ http://localhost:9292 85 | 128 threads and 512 connections 86 | Thread Stats Avg Stdev Max +/- Stdev 87 | Latency 153.92ms 27.06ms 597.36ms 95.11% 88 | Req/Sec 26.34 9.14 40.00 70.04% 89 | 24985 requests in 30.10s, 1.24MB read 90 | Socket errors: connect 0, read 49, write 0, timeout 0 91 | Requests/sec: 830.06 92 | Transfer/sec: 42.15KB 93 | ``` 94 | 95 | The theoretical throughput in this case is 128 threads * 10 sequential requests/second. Unfortunately, [puma] in it's current configuration quickly becomes CPU bound: 96 | 97 | ``` 98 | % puma -t 512:512 99 | Puma starting in single mode... 100 | * Version 3.11.2 (ruby 2.5.0-p0), codename: Love Song 101 | * Min threads: 512, max threads: 512 102 | * Environment: development 103 | * Listening on tcp://0.0.0.0:9292 104 | Use Ctrl-C to stop 105 | 106 | % wrk -c 512 -t 128 -d 30 http://localhost:9292 107 | Running 30s test @ http://localhost:9292 108 | 128 threads and 512 connections 109 | Thread Stats Avg Stdev Max +/- Stdev 110 | Latency 452.46ms 96.97ms 1.71s 80.84% 111 | Req/Sec 10.12 5.52 40.00 77.06% 112 | 23343 requests in 30.10s, 1.16MB read 113 | Requests/sec: 775.49 114 | Transfer/sec: 39.38KB 115 | ``` 116 | 117 | When running with [falcon], we are limited by the database. Postgres has been configured with up to 1024 connections, and falcon runs one process per available (hyper-)core, 8 in this case. With up to 1024 connections, we could expect an upper bound of 512 connections * 10 sequential requests/second. 118 | 119 | ``` 120 | % falcon --quiet serve --forked 121 | 122 | % wrk -c 512 -t 128 -d 30 http://localhost:9292 123 | Running 30s test @ http://localhost:9292 124 | 128 threads and 512 connections 125 | Thread Stats Avg Stdev Max +/- Stdev 126 | Latency 158.85ms 20.33ms 263.33ms 68.57% 127 | Req/Sec 25.25 8.97 40.00 72.16% 128 | 96641 requests in 30.10s, 4.52MB read 129 | Requests/sec: 3210.90 130 | Transfer/sec: 153.65KB 131 | ``` 132 | 133 | We get close to the theoretical 5120 requests/second limit, but at this point the entire test becomes CPU bound within Ruby/Falcon. 134 | 135 | ## Usage 136 | 137 | In theory, this is a drop-in replacement for ActiveRecord. But, it must be used with an [async] capable server like [falcon]. 138 | 139 | [async]: https://github.com/socketry/async 140 | [falcon]: https://github.com/socketry/falcon 141 | [puma]: https://github.com/puma/puma 142 | 143 | ## Contributing 144 | 145 | 1. Fork it 146 | 2. Create your feature branch (`git checkout -b my-new-feature`) 147 | 3. Commit your changes (`git commit -am 'Add some feature'`) 148 | 4. Push to the branch (`git push origin my-new-feature`) 149 | 5. Create new Pull Request 150 | 151 | ## License 152 | 153 | Copyright, 2018, by Samuel G. D. Williams. 154 | 155 | Permission is hereby granted, free of charge, to any person obtaining a copy 156 | of this software and associated documentation files (the "Software"), to deal 157 | in the Software without restriction, including without limitation the rights 158 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 159 | copies of the Software, and to permit persons to whom the Software is 160 | furnished to do so, subject to the following conditions: 161 | 162 | The above copyright notice and this permission notice shall be included in 163 | all copies or substantial portions of the Software. 164 | 165 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 166 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 167 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 168 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 169 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 170 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 171 | THE SOFTWARE. 172 | --------------------------------------------------------------------------------