swiftiply 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/CONTRIBUTORS +2 -0
  2. data/README +1 -1
  3. data/bin/echo_client +26 -0
  4. data/bin/swiftiply +21 -8
  5. data/ext/fastfilereader/extconf.rb +161 -0
  6. data/ext/fastfilereader/mapper.cpp +200 -0
  7. data/ext/fastfilereader/mapper.h +59 -0
  8. data/ext/fastfilereader/rubymain.cpp +127 -0
  9. data/external/test_support.rb +13 -0
  10. data/setup.rb +7 -2
  11. data/src/fastfilereader.rb +109 -0
  12. data/src/swiftcore/Swiftiply.rb +432 -103
  13. data/src/swiftcore/Swiftiply/support_pagecache.rb +56 -0
  14. data/src/swiftcore/Swiftiply/swiftiply_client.rb +57 -0
  15. data/src/swiftcore/evented_mongrel.rb +32 -4
  16. data/src/swiftcore/swiftiplied_mongrel.rb +50 -38
  17. data/src/swiftcore/types.rb +1583 -0
  18. data/swiftiply.gemspec +4 -4
  19. data/test/TC_ProxyBag.rb +185 -0
  20. data/test/TC_Swiftiply.rb +458 -0
  21. data/test/TC_Swiftiply/mongrel/evented_hello.rb +25 -0
  22. data/test/TC_Swiftiply/mongrel/swiftiplied_hello.rb +25 -0
  23. data/test/TC_Swiftiply/mongrel/threaded_hello.rb +25 -0
  24. data/test/TC_Swiftiply/slow_echo_client +26 -0
  25. metadata +34 -121
  26. data/src/ramaze/adapter/evented_mongrel.rb +0 -2
  27. data/src/ramaze/adapter/swiftiplied_mongrel.rb +0 -2
  28. data/test/rails/README +0 -182
  29. data/test/rails/Rakefile +0 -10
  30. data/test/rails/app/controllers/application.rb +0 -6
  31. data/test/rails/app/controllers/tests_controller.rb +0 -15
  32. data/test/rails/app/helpers/application_helper.rb +0 -3
  33. data/test/rails/config/boot.rb +0 -45
  34. data/test/rails/config/database.yml +0 -36
  35. data/test/rails/config/environment.rb +0 -60
  36. data/test/rails/config/environments/development.rb +0 -21
  37. data/test/rails/config/environments/production.rb +0 -18
  38. data/test/rails/config/environments/production_no_caching.rb +0 -18
  39. data/test/rails/config/environments/test.rb +0 -19
  40. data/test/rails/config/routes.rb +0 -23
  41. data/test/rails/doc/README_FOR_APP +0 -2
  42. data/test/rails/observe_ram.rb +0 -10
  43. data/test/rails/public/404.html +0 -30
  44. data/test/rails/public/500.html +0 -30
  45. data/test/rails/public/dispatch.cgi +0 -10
  46. data/test/rails/public/dispatch.fcgi +0 -24
  47. data/test/rails/public/dispatch.rb +0 -10
  48. data/test/rails/public/favicon.ico +0 -0
  49. data/test/rails/public/images/rails.png +0 -0
  50. data/test/rails/public/index.html +0 -277
  51. data/test/rails/public/javascripts/application.js +0 -2
  52. data/test/rails/public/javascripts/controls.js +0 -833
  53. data/test/rails/public/javascripts/dragdrop.js +0 -942
  54. data/test/rails/public/javascripts/effects.js +0 -1088
  55. data/test/rails/public/javascripts/prototype.js +0 -2515
  56. data/test/rails/public/robots.txt +0 -1
  57. data/test/rails/script/about +0 -3
  58. data/test/rails/script/breakpointer +0 -3
  59. data/test/rails/script/console +0 -3
  60. data/test/rails/script/destroy +0 -3
  61. data/test/rails/script/generate +0 -3
  62. data/test/rails/script/performance/benchmarker +0 -3
  63. data/test/rails/script/performance/profiler +0 -3
  64. data/test/rails/script/plugin +0 -3
  65. data/test/rails/script/process/inspector +0 -3
  66. data/test/rails/script/process/reaper +0 -3
  67. data/test/rails/script/process/spawner +0 -3
  68. data/test/rails/script/runner +0 -3
  69. data/test/rails/script/server +0 -3
  70. data/test/rails/test/test_helper.rb +0 -28
  71. data/test/ramaze/conf/benchmark.yaml +0 -35
  72. data/test/ramaze/conf/debug.yaml +0 -34
  73. data/test/ramaze/conf/live.yaml +0 -33
  74. data/test/ramaze/conf/silent.yaml +0 -31
  75. data/test/ramaze/conf/stage.yaml +0 -33
  76. data/test/ramaze/main.rb +0 -18
  77. data/test/ramaze/public/404.jpg +0 -0
  78. data/test/ramaze/public/css/coderay.css +0 -105
  79. data/test/ramaze/public/css/ramaze_error.css +0 -42
  80. data/test/ramaze/public/error.zmr +0 -77
  81. data/test/ramaze/public/favicon.ico +0 -0
  82. data/test/ramaze/public/js/jquery.js +0 -1923
  83. data/test/ramaze/public/ramaze.png +0 -0
  84. data/test/ramaze/src/controller/main.rb +0 -8
  85. data/test/ramaze/src/element/page.rb +0 -17
  86. data/test/ramaze/src/model.rb +0 -6
  87. data/test/ramaze/template/index.xhtml +0 -6
  88. data/test/ramaze/yaml.db +0 -0
data/CONTRIBUTORS CHANGED
@@ -1,4 +1,6 @@
1
1
  Swiftiply is written by Kirk Haines (wyhaines@gmail.com).
2
2
 
3
+ The fastfilereader extension was contributed by Francis Cianfrocca.
4
+
3
5
  Ezra Zygmuntowicz contributed swiftiply_mongrel_rails and edits to
4
6
  mongrel_rails.
data/README CHANGED
@@ -1,4 +1,4 @@
1
- Swiftiply v. 0.5.0 (http://swiftiply.swiftcore.org)
1
+ Swiftiply v. 0.6.0 (http://swiftiply.swiftcore.org)
2
2
 
3
3
  Swiftiply is a backend agnostic clustering proxy for web applications that is
4
4
  specifically designed to support HTTP traffic from web frameworks. Unlike Pen
data/bin/echo_client ADDED
@@ -0,0 +1,26 @@
1
+ # This is a very simple, naive Swiftiply client. All that is does is echo whatever
2
+ # request it receives as its response, in a very simplistic way.
3
+
4
+ require 'swiftcore/Swiftiply/swiftiply_client'
5
+
6
+ class EchoClient < SwiftiplyClientProtocol
7
+ def post_init
8
+ @httpdata = ''
9
+ super
10
+ end
11
+
12
+ def receive_data data
13
+ @httpdata << data
14
+ if @httpdata =~ /\r\n\r\n/
15
+ send_http_data(@httpdata)
16
+ @httpdata = ''
17
+ end
18
+ end
19
+ end
20
+
21
+ if ARGV[0] and ARGV[0].index(/:/) > 0
22
+ h,p = ARGV[0].split(/:/,2)
23
+ EventMachine.run { EchoClient.connect(h,p.to_i,ARGV[1] || '') }
24
+ else
25
+ puts "echo_client HOST:PORT [KEY]"
26
+ end
data/bin/swiftiply CHANGED
@@ -19,6 +19,7 @@ module Swiftcore
19
19
  class SwiftiplyExec
20
20
  Ccluster_address = 'cluster_address'.freeze
21
21
  Ccluster_port = 'cluster_port'.freeze
22
+ Cconfig_file = 'config_file'.freeze
22
23
  Cbackend_address = 'backend_address'.freeze
23
24
  Cbackend_port = 'backend_port'.freeze
24
25
  Cmap = 'map'.freeze
@@ -52,13 +53,15 @@ module Swiftcore
52
53
  # outgoing:
53
54
  #
54
55
  #####
55
- def self.parse_options(config = {})
56
+ def self.parse_options
57
+ config = @cliconfig || {}
58
+ @print = false
59
+
56
60
  OptionParser.new do |opts|
57
61
  opts.banner = 'Usage: swiftiply.rb [options]'
58
62
  opts.separator ''
59
63
  opts.on('-c','--config CONFFILE',"The configuration file to read.") do |conf|
60
- config = YAML.load(File.open(conf))
61
- postprocess_config_load(config)
64
+ config[Cconfig_file] = conf
62
65
  end
63
66
  opts.on('--cluster-address [ADDRESS]',String,'The hostname/IP address that swiftiply will listen for connections on.') do |address|
64
67
  config[Ccluster_address] = address
@@ -79,14 +82,24 @@ module Swiftcore
79
82
  config[Ctimeout] = timeout
80
83
  end
81
84
  opts.on('-p','--print-config','Print the full configuration.') do
82
- verify_config(config)
83
- require 'pp'
84
- pp config
85
- exit
85
+ @print = true
86
86
  end
87
87
 
88
88
  end.parse!
89
+ @cliconfig ||= config
90
+
91
+ fileconfig = {}
92
+ fileconfig = YAML.load(File.open(config['config_file'])) if config['config_file']
93
+ config = fileconfig.merge(@cliconfig)
94
+ postprocess_config_load(config)
89
95
  puts("Configuration failed validation; exiting.") && exit unless verify_config(config)
96
+
97
+ if @print
98
+ require 'pp'
99
+ pp config
100
+ exit
101
+ end
102
+
90
103
  config
91
104
  end
92
105
 
@@ -128,7 +141,7 @@ module Swiftcore
128
141
 
129
142
  def self.on_windows?
130
143
  return @on_windows unless @on_windows.nil?
131
- @on_windows = !![/mswin/i, /cygwin/i, /mingw/i, /bccwin/i, /wince/i].find {|p| RUBY_PLATFORM =~ p}
144
+ @on_windows = !![/mswin/i, /cygwin/i, /mingw/i, /bccwin/i, /wince/i].find {|p| RUBY_PLATFORM =~ p}
132
145
  end
133
146
  end
134
147
  end
@@ -0,0 +1,161 @@
1
+ # $Id: extconf.rb 4526 2007-07-03 18:04:34Z francis $
2
+ #
3
+ #----------------------------------------------------------------------------
4
+ #
5
+ # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
6
+ # Gmail: garbagecat10
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of either: 1) the GNU General Public License
10
+ # as published by the Free Software Foundation; either version 2 of the
11
+ # License, or (at your option) any later version; or 2) Ruby's License.
12
+ #
13
+ # See the file COPYING for complete licensing information.
14
+ #
15
+ #---------------------------------------------------------------------------
16
+ #
17
+ # extconf.rb for Fast File Reader
18
+ # We have to munge LDSHARED because this code needs a C++ link.
19
+ #
20
+
21
+ require 'mkmf'
22
+
23
+ flags = []
24
+
25
+ case RUBY_PLATFORM.split('-',2)[1]
26
+ when 'mswin32', 'mingw32', 'bccwin32'
27
+ unless have_header('windows.h') and
28
+ have_header('winsock.h') and
29
+ have_library('kernel32') and
30
+ have_library('rpcrt4') and
31
+ have_library('gdi32')
32
+ exit
33
+ end
34
+
35
+ flags << "-D OS_WIN32"
36
+ flags << '-D BUILD_FOR_RUBY'
37
+ flags << "-EHs"
38
+ flags << "-GR"
39
+
40
+ dir_config('ssl')
41
+ if have_library('ssleay32') and
42
+ have_library('libeay32') and
43
+ have_header('openssl/ssl.h') and
44
+ have_header('openssl/err.h')
45
+ flags << '-D WITH_SSL'
46
+ else
47
+ flags << '-D WITHOUT_SSL'
48
+ end
49
+
50
+ when /solaris/
51
+ unless have_library('pthread') and
52
+ have_library('nsl') and
53
+ have_library('socket')
54
+ exit
55
+ end
56
+
57
+ flags << '-D OS_UNIX'
58
+ flags << '-D OS_SOLARIS8'
59
+ flags << '-D BUILD_FOR_RUBY'
60
+
61
+ dir_config('ssl')
62
+ if have_library('ssl') and
63
+ have_library('crypto') and
64
+ have_header('openssl/ssl.h') and
65
+ have_header('openssl/err.h')
66
+ flags << '-D WITH_SSL'
67
+ else
68
+ flags << '-D WITHOUT_SSL'
69
+ end
70
+
71
+ # on Unix we need a g++ link, not gcc.
72
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
73
+
74
+ when /darwin/
75
+ flags << '-DOS_UNIX'
76
+ flags << '-DBUILD_FOR_RUBY'
77
+
78
+ dir_config('ssl')
79
+ if have_library('ssl') and
80
+ have_library('crypto') and
81
+ have_library('C') and
82
+ have_header('openssl/ssl.h') and
83
+ have_header('openssl/err.h')
84
+ flags << '-DWITH_SSL'
85
+ else
86
+ flags << '-DWITHOUT_SSL'
87
+ end
88
+ # on Unix we need a g++ link, not gcc.
89
+ # Ff line contributed by Daniel Harple.
90
+ CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
91
+
92
+ when /linux/
93
+ unless have_library('pthread')
94
+ exit
95
+ end
96
+
97
+ flags << '-DOS_UNIX'
98
+ flags << '-DBUILD_FOR_RUBY'
99
+
100
+ # Original epoll test is inadequate because 2.4 kernels have the header
101
+ # but not the code.
102
+ #flags << '-DHAVE_EPOLL' if have_header('sys/epoll.h')
103
+ if have_header('sys/epoll.h')
104
+ File.open("hasEpollTest.c", "w") {|f|
105
+ f.puts "#include <sys/epoll.h>"
106
+ f.puts "int main() { epoll_create(1024); return 0;}"
107
+ }
108
+ (e = system( "gcc hasEpollTest.c -o hasEpollTest " )) and (e = $?.to_i)
109
+ `rm -f hasEpollTest.c hasEpollTest`
110
+ flags << '-DHAVE_EPOLL' if e == 0
111
+ end
112
+
113
+ dir_config('ssl')
114
+ if have_library('ssl') and
115
+ have_library('crypto') and
116
+ have_header('openssl/ssl.h') and
117
+ have_header('openssl/err.h')
118
+ flags << '-DWITH_SSL'
119
+ else
120
+ flags << '-DWITHOUT_SSL'
121
+ end
122
+ # on Unix we need a g++ link, not gcc.
123
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
124
+
125
+ # Modify the mkmf constant LINK_SO so the generated shared object is stripped.
126
+ # You might think modifying CONFIG['LINK_SO'] would be a better way to do this,
127
+ # but it doesn't work because mkmf doesn't look at CONFIG['LINK_SO'] again after
128
+ # it initializes.
129
+ linkso = Object.send :remove_const, "LINK_SO"
130
+ LINK_SO = linkso + "; strip $@"
131
+
132
+ else
133
+ unless have_library('pthread')
134
+ exit
135
+ end
136
+
137
+ flags << '-DOS_UNIX'
138
+ flags << '-DBUILD_FOR_RUBY'
139
+
140
+ dir_config('ssl')
141
+ if have_library('ssl') and
142
+ have_library('crypto') and
143
+ have_header('openssl/ssl.h') and
144
+ have_header('openssl/err.h')
145
+ flags << '-DWITH_SSL'
146
+ else
147
+ flags << '-DWITHOUT_SSL'
148
+ end
149
+ # on Unix we need a g++ link, not gcc.
150
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
151
+
152
+ end
153
+
154
+ if $CPPFLAGS
155
+ $CPPFLAGS += ' ' + flags.join(' ')
156
+ else
157
+ $CFLAGS += ' ' + flags.join(' ')
158
+ end
159
+
160
+
161
+ create_makefile "fastfilereaderext"
@@ -0,0 +1,200 @@
1
+ /*****************************************************************************
2
+
3
+ $Id: mapper.cpp 4527 2007-07-04 10:21:34Z francis $
4
+
5
+ File: mapper.cpp
6
+ Date: 02Jul07
7
+
8
+ Copyright (C) 2007 by Francis Cianfrocca. All Rights Reserved.
9
+ Gmail: garbagecat10
10
+
11
+ This program is free software; you can redistribute it and/or modify
12
+ it under the terms of either: 1) the GNU General Public License
13
+ as published by the Free Software Foundation; either version 2 of the
14
+ License, or (at your option) any later version; or 2) Ruby's License.
15
+
16
+ See the file COPYING for complete licensing information.
17
+
18
+ *****************************************************************************/
19
+
20
+
21
+ //////////////////////////////////////////////////////////////////////
22
+ // UNIX implementation
23
+ //////////////////////////////////////////////////////////////////////
24
+
25
+
26
+ #ifdef OS_UNIX
27
+
28
+ #include <sys/types.h>
29
+ #include <sys/stat.h>
30
+ #include <sys/mman.h>
31
+ #include <fcntl.h>
32
+ #include <errno.h>
33
+
34
+ #include <iostream>
35
+ #include <string>
36
+ #include <stdexcept>
37
+ using namespace std;
38
+
39
+ #include "mapper.h"
40
+
41
+ /******************
42
+ Mapper_t::Mapper_t
43
+ ******************/
44
+
45
+ Mapper_t::Mapper_t (const string &filename)
46
+ {
47
+ /* We ASSUME we can open the file.
48
+ * (More precisely, we assume someone else checked before we got here.)
49
+ */
50
+
51
+ Fd = open (filename.c_str(), O_RDONLY);
52
+ if (Fd < 0)
53
+ throw runtime_error (strerror (errno));
54
+
55
+ struct stat st;
56
+ if (fstat (Fd, &st))
57
+ throw runtime_error (strerror (errno));
58
+ FileSize = st.st_size;
59
+
60
+ MapPoint = (const char*) mmap (0, FileSize, PROT_READ, MAP_SHARED, Fd, 0);
61
+ if (MapPoint == MAP_FAILED)
62
+ throw runtime_error (strerror (errno));
63
+ }
64
+
65
+
66
+ /*******************
67
+ Mapper_t::~Mapper_t
68
+ *******************/
69
+
70
+ Mapper_t::~Mapper_t()
71
+ {
72
+ Close();
73
+ }
74
+
75
+
76
+ /***************
77
+ Mapper_t::Close
78
+ ***************/
79
+
80
+ void Mapper_t::Close()
81
+ {
82
+ // Can be called multiple times.
83
+ // Calls to GetChunk are invalid after a call to Close.
84
+ if (MapPoint) {
85
+ munmap ((void*)MapPoint, FileSize);
86
+ MapPoint = NULL;
87
+ }
88
+ if (Fd >= 0) {
89
+ close (Fd);
90
+ Fd = -1;
91
+ }
92
+ }
93
+
94
+ /******************
95
+ Mapper_t::GetChunk
96
+ ******************/
97
+
98
+ const char *Mapper_t::GetChunk (unsigned start)
99
+ {
100
+ return MapPoint + start;
101
+ }
102
+
103
+
104
+
105
+ #endif // OS_UNIX
106
+
107
+
108
+ //////////////////////////////////////////////////////////////////////
109
+ // WINDOWS implementation
110
+ //////////////////////////////////////////////////////////////////////
111
+
112
+ #ifdef OS_WIN32
113
+
114
+ #include <windows.h>
115
+
116
+ #include <iostream>
117
+ #include <string>
118
+ #include <stdexcept>
119
+ using namespace std;
120
+
121
+ #include "mapper.h"
122
+
123
+ /******************
124
+ Mapper_t::Mapper_t
125
+ ******************/
126
+
127
+ Mapper_t::Mapper_t (const string &filename)
128
+ {
129
+ /* We ASSUME we can open the file.
130
+ * (More precisely, we assume someone else checked before we got here.)
131
+ */
132
+
133
+ hFile = INVALID_HANDLE_VALUE;
134
+ hMapping = NULL;
135
+ MapPoint = NULL;
136
+ FileSize = 0;
137
+
138
+ hFile = CreateFile (filename.c_str(), GENERIC_READ|GENERIC_WRITE, FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
139
+
140
+ if (hFile == INVALID_HANDLE_VALUE)
141
+ throw runtime_error ("File not found");
142
+
143
+ BY_HANDLE_FILE_INFORMATION i;
144
+ if (GetFileInformationByHandle (hFile, &i))
145
+ FileSize = i.nFileSizeLow;
146
+
147
+ hMapping = CreateFileMapping (hFile, NULL, PAGE_READWRITE, 0, 0, NULL);
148
+ if (!hMapping)
149
+ throw runtime_error ("File not mapped");
150
+
151
+ MapPoint = (const char*) MapViewOfFile (hMapping, FILE_MAP_WRITE, 0, 0, 0);
152
+ if (!MapPoint)
153
+ throw runtime_error ("Mappoint not read");
154
+ }
155
+
156
+
157
+ /*******************
158
+ Mapper_t::~Mapper_t
159
+ *******************/
160
+
161
+ Mapper_t::~Mapper_t()
162
+ {
163
+ Close();
164
+ }
165
+
166
+ /***************
167
+ Mapper_t::Close
168
+ ***************/
169
+
170
+ void Mapper_t::Close()
171
+ {
172
+ // Can be called multiple times.
173
+ // Calls to GetChunk are invalid after a call to Close.
174
+ if (MapPoint) {
175
+ UnmapViewOfFile (MapPoint);
176
+ MapPoint = NULL;
177
+ }
178
+ if (hMapping != NULL) {
179
+ CloseHandle (hMapping);
180
+ hMapping = NULL;
181
+ }
182
+ if (hFile != INVALID_HANDLE_VALUE) {
183
+ CloseHandle (hFile);
184
+ hMapping = INVALID_HANDLE_VALUE;
185
+ }
186
+ }
187
+
188
+
189
+ /******************
190
+ Mapper_t::GetChunk
191
+ ******************/
192
+
193
+ const char *Mapper_t::GetChunk (unsigned start)
194
+ {
195
+ return MapPoint + start;
196
+ }
197
+
198
+
199
+
200
+ #endif // OS_WINDOWS