oldmoe-neverblock 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/active_record/connection_adapters/neverblock_mysql_adapter.rb +6 -4
- data/lib/active_record/connection_adapters/neverblock_postgresql_adapter.rb +24 -19
- data/lib/never_block/db/fibered_postgres_connection.rb +2 -2
- data/lib/never_block/frameworks/rails.rb +16 -1
- data/lib/never_block/servers/thin.rb +3 -12
- data/lib/never_block.rb +6 -0
- data/neverblock.gemspec +2 -2
- metadata +2 -2
@@ -45,10 +45,12 @@ class ActiveRecord::ConnectionAdapters::NeverBlockMysqlAdapter < ActiveRecord::C
|
|
45
45
|
end
|
46
46
|
conn.ssl_set(@config[:sslkey], @config[:sslcert], @config[:sslca], @config[:sslcapath], @config[:sslcipher]) if @config[:sslkey]
|
47
47
|
conn.real_connect(*@connection_options)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
NB.neverblock(false) do
|
49
|
+
conn.query("SET NAMES '#{encoding}'") if encoding
|
50
|
+
# By default, MySQL 'where id is null' selects the last inserted id.
|
51
|
+
# Turn this off. http://dev.rubyonrails.org/ticket/6778
|
52
|
+
conn.query("SET SQL_AUTO_IS_NULL=0")
|
53
|
+
end
|
52
54
|
conn.register_with_event_loop(:em)
|
53
55
|
conn
|
54
56
|
end
|
@@ -41,29 +41,34 @@ class ActiveRecord::ConnectionAdapters::NeverBlockPostgreSQLAdapter < ActiveReco
|
|
41
41
|
# See: http://www.postgresql.org/docs/current/static/runtime-config-compatible.html
|
42
42
|
# If PostgreSQL doesn't know the standard_conforming_strings parameter then it doesn't
|
43
43
|
# support escape string syntax. Don't override the inherited quoted_string_prefix.
|
44
|
-
|
45
|
-
if supports_standard_conforming_strings?
|
46
|
-
self.class.instance_eval do
|
47
|
-
define_method(:quoted_string_prefix) { 'E' }
|
48
|
-
end
|
49
|
-
end
|
44
|
+
NB.neverblock(false) do
|
50
45
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
::ActiveRecord::ConnectionAdapters::PostgreSQLColumn.module_eval(<<-end_eval)
|
56
|
-
def extract_precision(sql_type)
|
57
|
-
if sql_type =~ /^money$/
|
58
|
-
#{money_precision}
|
59
|
-
else
|
60
|
-
super
|
46
|
+
@connection.begin_db_transaction
|
47
|
+
if supports_standard_conforming_strings?
|
48
|
+
self.class.instance_eval do
|
49
|
+
define_method(:quoted_string_prefix) { 'E' }
|
61
50
|
end
|
62
51
|
end
|
63
|
-
end_eval
|
64
52
|
|
65
|
-
|
66
|
-
|
53
|
+
# Money type has a fixed precision of 10 in PostgreSQL 8.2 and below, and as of
|
54
|
+
# PostgreSQL 8.3 it has a fixed precision of 19. PostgreSQLColumn.extract_precision
|
55
|
+
# should know about this but can't detect it there, so deal with it here.
|
56
|
+
money_precision = (postgresql_version >= 80300) ? 19 : 10
|
57
|
+
::ActiveRecord::ConnectionAdapters::PostgreSQLColumn.module_eval(<<-end_eval)
|
58
|
+
def extract_precision(sql_type)
|
59
|
+
if sql_type =~ /^money$/
|
60
|
+
#{money_precision}
|
61
|
+
else
|
62
|
+
super
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end_eval
|
66
|
+
|
67
|
+
configure_connection
|
68
|
+
@connection.commit_db_transaction
|
69
|
+
|
70
|
+
end
|
71
|
+
|
67
72
|
end
|
68
73
|
|
69
74
|
# Close then reopen the connection.
|
@@ -22,7 +22,7 @@ module NeverBlock
|
|
22
22
|
super(*args)
|
23
23
|
@fd = socket
|
24
24
|
@io = IO.new(socket)
|
25
|
-
setnonblocking(true)
|
25
|
+
#setnonblocking(true)
|
26
26
|
end
|
27
27
|
|
28
28
|
# Assuming the use of NeverBlock fiber extensions and that the exec is run in
|
@@ -76,7 +76,7 @@ module NeverBlock
|
|
76
76
|
def process_command
|
77
77
|
# make sure all commands are sent
|
78
78
|
# before attempting to read
|
79
|
-
return unless self.flush
|
79
|
+
#return unless self.flush
|
80
80
|
self.consume_input
|
81
81
|
unless is_busy
|
82
82
|
res, data = 0, []
|
@@ -1,5 +1,6 @@
|
|
1
|
+
require 'neverblock' unless defined?(NeverBlock)
|
1
2
|
#require 'actionpack'
|
2
|
-
require 'action_controller'
|
3
|
+
#require 'action_controller'
|
3
4
|
|
4
5
|
# Rails tries to protect dispatched actions
|
5
6
|
# by wrapping them in a synchronized code
|
@@ -8,6 +9,8 @@ require 'action_controller'
|
|
8
9
|
# transform it (without it knowing) to
|
9
10
|
# something more subtle
|
10
11
|
|
12
|
+
|
13
|
+
=begin
|
11
14
|
class ActionController::Dispatcher
|
12
15
|
|
13
16
|
# let's show this guard who is
|
@@ -20,3 +23,15 @@ class ActionController::Dispatcher
|
|
20
23
|
block.call
|
21
24
|
end
|
22
25
|
end
|
26
|
+
=end
|
27
|
+
|
28
|
+
|
29
|
+
require 'thread'
|
30
|
+
|
31
|
+
# now you synchronize
|
32
|
+
class Mutex
|
33
|
+
def synchronize(&block)
|
34
|
+
# now you don't!
|
35
|
+
block.call
|
36
|
+
end
|
37
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'neverblock' unless defined?(NeverBlock)
|
1
3
|
require 'thin'
|
2
4
|
|
3
5
|
module Thin
|
@@ -8,7 +10,7 @@ module Thin
|
|
8
10
|
# in fibers
|
9
11
|
class Server
|
10
12
|
|
11
|
-
DEFAULT_FIBER_POOL_SIZE =
|
13
|
+
DEFAULT_FIBER_POOL_SIZE = 20
|
12
14
|
|
13
15
|
def fiber_pool
|
14
16
|
@fiber_pool ||= NB::Pool::FiberPool.new(DEFAULT_FIBER_POOL_SIZE)
|
@@ -31,16 +33,5 @@ module Thin
|
|
31
33
|
|
32
34
|
end # Connection
|
33
35
|
|
34
|
-
module Backends
|
35
|
-
class Base
|
36
|
-
def config
|
37
|
-
# EM.epoll
|
38
|
-
# Set the maximum number of socket descriptors that the server may open.
|
39
|
-
# The process needs to have required privilege to set it higher the 1024 on
|
40
|
-
# some systems.
|
41
|
-
@maximum_connections = EventMachine.set_descriptor_table_size(@maximum_connections) unless Thin.win?
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end # Backends
|
45
36
|
|
46
37
|
end # Thin
|
data/lib/never_block.rb
CHANGED
@@ -73,6 +73,12 @@ require 'never_block/pool/fiber_pool'
|
|
73
73
|
require 'never_block/pool/fibered_connection_pool'
|
74
74
|
|
75
75
|
module NeverBlock
|
76
|
+
def self.neverblock(nb = true, &block)
|
77
|
+
status = Fiber.current[:neverblock]
|
78
|
+
Fiber.current[:neverblock] = nb
|
79
|
+
block.call
|
80
|
+
Fiber.current[:neverblock] = status
|
81
|
+
end
|
76
82
|
end
|
77
83
|
|
78
84
|
NB = NeverBlock
|
data/neverblock.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "neverblock"
|
3
|
-
s.version = "0.1.
|
4
|
-
s.date = "2008-
|
3
|
+
s.version = "0.1.2"
|
4
|
+
s.date = "2008-09-04"
|
5
5
|
s.summary = "Utilities for non-blocking stack components"
|
6
6
|
s.email = "oldmoe@gmail.com"
|
7
7
|
s.homepage = "http://github.com/oldmoe/neverblock"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oldmoe-neverblock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Muhammad A. Ali
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2008-
|
14
|
+
date: 2008-09-04 00:00:00 -07:00
|
15
15
|
default_executable:
|
16
16
|
dependencies: []
|
17
17
|
|