webroar 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +10 -0
- data/README +116 -86
- data/doc/user-guide.html +2 -2
- data/doc/user-guide.txt +65 -65
- data/lib/command_runner.rb +5 -3
- data/src/head/wr_application.c +249 -294
- data/src/head/wr_application.h +28 -21
- data/src/head/wr_config.h +7 -1
- data/src/head/wr_connection.c +1 -1
- data/src/head/wr_controller.c +2 -4
- data/src/head/wr_request.c +1 -1
- data/src/head/wr_request.h +3 -3
- data/src/head/wr_resolver.c +2 -2
- data/src/head/wr_worker.c +16 -17
- data/src/ruby_lib/ruby_interface/version.rb +1 -1
- data/tasks/gem.rake +1 -1
- metadata +3 -3
data/src/head/wr_application.h
CHANGED
@@ -21,39 +21,46 @@
|
|
21
21
|
|
22
22
|
#include <wr_server.h>
|
23
23
|
|
24
|
-
#define
|
25
|
-
#define TOTAL_WORKER_COUNT(app) (app->pending_wkr + WR_QUEUE_SIZE(app->wkr_que))
|
24
|
+
#define TOTAL_WORKER_COUNT(app) (WR_QUEUE_SIZE(app->q_pending_workers) + WR_QUEUE_SIZE(app->q_workers))
|
26
25
|
|
27
26
|
typedef struct wr_req_s wr_req_t;
|
28
27
|
typedef struct wr_wkr_s wr_wkr_t;
|
29
|
-
|
28
|
+
|
29
|
+
typedef int wr_pending_wkr_t;
|
30
|
+
|
31
|
+
typedef enum{
|
32
|
+
WR_APP_NEW,
|
33
|
+
WR_APP_ACTIVE,
|
34
|
+
WR_APP_RESTART,
|
35
|
+
WR_APP_RESTARTING,
|
36
|
+
WR_APP_DESTROY
|
37
|
+
}wr_app_state_t;
|
30
38
|
|
31
39
|
/** Application structure */
|
32
40
|
struct wr_app_s {
|
33
|
-
|
34
|
-
|
35
|
-
wr_queue_t *
|
36
|
-
wr_queue_t *
|
37
|
-
|
38
|
-
|
39
|
-
|
41
|
+
|
42
|
+
wr_queue_t *q_pending_workers; /**< Pending worker queue */
|
43
|
+
wr_queue_t *q_workers; /**< List of workers */
|
44
|
+
wr_queue_t *q_free_workers; /**< List of free workers */
|
45
|
+
|
46
|
+
wr_queue_t *q_messages; /**< Pending message queue */
|
47
|
+
|
48
|
+
wr_app_conf_t *conf; /**< Application configuration parameters */
|
40
49
|
wr_svr_t *svr; /**< Server pointer */
|
41
50
|
wr_ctl_t *ctl;
|
42
51
|
|
43
52
|
short low_ratio; /** Ratio to remove the worker */
|
44
53
|
short high_ratio; /** Ratio to add the worker */
|
45
|
-
short in_use; /** Application status flag */
|
46
|
-
|
47
|
-
/** Variables used to reload an application without any downtime */
|
48
|
-
short restarted; /** Application restart status flag */
|
49
|
-
short old_workers; /** Number of old workers to be removed */
|
50
|
-
short add_workers; /** Number of new workers to be created */
|
51
|
-
|
52
|
-
wr_u_short last_wkr_pid[WR_MAX_PENDING_WKR]; /**< PID of the last worker */
|
53
54
|
|
55
|
+
wr_app_state_t state; /** Application status flag */
|
56
|
+
|
57
|
+
short timeout_counter; /**< Worker add timeout counter */
|
58
|
+
|
54
59
|
ev_timer t_add; /**< Timer to add worker */
|
55
60
|
ev_timer t_remove; /**< Timer to remove worker */
|
56
61
|
ev_timer t_add_timeout; /**< Timer to wait for add signal from worker */
|
62
|
+
|
63
|
+
wr_app_t *next;
|
57
64
|
};
|
58
65
|
|
59
66
|
/** Destroy application */
|
@@ -62,8 +69,6 @@ void wr_app_free(wr_app_t*);
|
|
62
69
|
void wr_app_print(wr_app_t*);
|
63
70
|
/** Create worker for application */
|
64
71
|
int wr_app_wkr_add(wr_app_t*);
|
65
|
-
/** Insert application based on application configuration */
|
66
|
-
//int wr_app_insert(wr_svr_t*, wr_app_conf_t*);
|
67
72
|
/** Add request message in pending queue */
|
68
73
|
int wr_app_message_insert(wr_svr_t*, wr_req_t*);
|
69
74
|
/** Check load balance to add the worker */
|
@@ -71,7 +76,7 @@ void wr_app_chk_load_to_add_wkr(wr_app_t*);
|
|
71
76
|
/** Check load balance to remove the worker */
|
72
77
|
void wr_app_chk_load_to_remove_wkr(wr_app_t*);
|
73
78
|
/** Add newly created worker to application */
|
74
|
-
int
|
79
|
+
int wr_app_wkr_insert(wr_svr_t *, wr_wkr_t*, const wr_ctl_msg_t*);
|
75
80
|
/** Remove application from application list */
|
76
81
|
int wr_app_remove(wr_svr_t*, const char* app_name);
|
77
82
|
/** Initialize the applications */
|
@@ -84,6 +89,8 @@ void wr_app_remove_cb(wr_ctl_t*, const wr_ctl_msg_t*);
|
|
84
89
|
void wr_app_reload_cb(wr_ctl_t*, const wr_ctl_msg_t*);
|
85
90
|
/** Worker added to application callback */
|
86
91
|
void wr_app_wkr_added_cb(wr_app_t *app);
|
92
|
+
/** Balance worker count for an application */
|
93
|
+
void wr_app_wkr_balance(wr_app_t *app);
|
87
94
|
|
88
95
|
/**************************/
|
89
96
|
|
data/src/head/wr_config.h
CHANGED
@@ -29,6 +29,9 @@
|
|
29
29
|
// Maximum value allowed for number of workers
|
30
30
|
#define WR_ALLOWED_MAX_WORKERS 20
|
31
31
|
|
32
|
+
#define WR_MAX_PENDING_WKR 10
|
33
|
+
#define WR_MAX_ADD_TIMEOUT_COUNTER 3
|
34
|
+
|
32
35
|
#ifdef HAVE_GNUTLS
|
33
36
|
// Default SSL listining port
|
34
37
|
#define WR_DEFAULT_SSL_PORT 443
|
@@ -84,7 +87,7 @@
|
|
84
87
|
// File to store Server process id
|
85
88
|
#define WR_PID_FILE "/var/run/webroar.pid"
|
86
89
|
#define WR_SERVER "WebROaR"
|
87
|
-
#define WR_VERSION "0.
|
90
|
+
#define WR_VERSION "0.3.1"
|
88
91
|
#define WR_MIME_TYPE_PATH "/conf/mime_type.yml"
|
89
92
|
#define WR_CONF_PATH "/conf/config.yml"
|
90
93
|
#define WR_SERVER_INTERNAL_CONF_PATH "/conf/server_internal_config.yml"
|
@@ -156,4 +159,7 @@
|
|
156
159
|
|
157
160
|
#define WR_MAX_HOST_NAMES 16
|
158
161
|
|
162
|
+
#define TRUE 1
|
163
|
+
#define FALSE 0
|
164
|
+
|
159
165
|
#endif /*WR_CONFIG_H_*/
|
data/src/head/wr_connection.c
CHANGED
@@ -318,7 +318,7 @@ void wr_conn_err_resp(wr_conn_t *conn, wr_resp_status_t resp_code) {
|
|
318
318
|
} else if(req->app) {
|
319
319
|
// Remove req from application message list
|
320
320
|
LOG_DEBUG(DEBUG,"Request is inserted into Application message queue.");
|
321
|
-
wr_queue_remove(conn->req->app->
|
321
|
+
wr_queue_remove(conn->req->app->q_messages, conn->req);
|
322
322
|
wr_req_free(req);
|
323
323
|
} else {
|
324
324
|
LOG_DEBUG(DEBUG,"Request is still in parsing phase.");
|
data/src/head/wr_controller.c
CHANGED
@@ -517,10 +517,8 @@ void wr_ctl_free(wr_ctl_t* ctl) {
|
|
517
517
|
wr_wkr_free(ctl->wkr);
|
518
518
|
|
519
519
|
//create new worker if required
|
520
|
-
if(app && app->
|
521
|
-
|
522
|
-
app->msg_que->q_count > app->high_ratio ) ) {
|
523
|
-
wr_app_wkr_add(app);
|
520
|
+
if(app && app->state == WR_APP_ACTIVE){
|
521
|
+
wr_app_wkr_balance(app);
|
524
522
|
}
|
525
523
|
}
|
526
524
|
if(ctl->app) {
|
data/src/head/wr_request.c
CHANGED
@@ -472,7 +472,7 @@ void wr_req_complete_cb(ebb_request * request) {
|
|
472
472
|
// ebb_request parsing completed, send call back to Server
|
473
473
|
if(req->app){
|
474
474
|
int rv;
|
475
|
-
WR_QUEUE_INSERT(req->app->
|
475
|
+
WR_QUEUE_INSERT(req->app->q_messages, req, rv)
|
476
476
|
if(rv == 0){
|
477
477
|
wr_wkr_dispatch_req(req);
|
478
478
|
return;
|
data/src/head/wr_request.h
CHANGED
@@ -67,9 +67,9 @@ ebb_request* wr_new_req_cb(ebb_connection*);
|
|
67
67
|
/** Dispatch a pending message to free worker */
|
68
68
|
#define WR_APP_MSG_DISPATCH(app, req, worker) \
|
69
69
|
void *_w=NULL,*_r=NULL;\
|
70
|
-
if(app->
|
71
|
-
WR_QUEUE_FETCH(app->
|
72
|
-
WR_QUEUE_FETCH(app->
|
70
|
+
if(app->q_messages->q_count > 0 && app->q_free_workers->q_count > 0){\
|
71
|
+
WR_QUEUE_FETCH(app->q_free_workers, _w)\
|
72
|
+
WR_QUEUE_FETCH(app->q_messages, _r)}\
|
73
73
|
req = (wr_req_t*) _r;\
|
74
74
|
worker = (wr_wkr_t*) _w;
|
75
75
|
|
data/src/head/wr_resolver.c
CHANGED
@@ -49,7 +49,7 @@ int wr_req_resolve_static_content(wr_req_t *req){
|
|
49
49
|
int len;
|
50
50
|
wr_str_t decoded_req_path;
|
51
51
|
|
52
|
-
if(req->app->svr->static_app->
|
52
|
+
if(WR_QUEUE_SIZE(req->app->svr->static_app->q_workers) <= 0){
|
53
53
|
LOG_ERROR(SEVERE,"Static content server is down.")
|
54
54
|
return -1;
|
55
55
|
}
|
@@ -296,7 +296,7 @@ int wr_req_resolve_http_req(wr_svr_t *server, wr_req_t *req) {
|
|
296
296
|
app = server->default_app;
|
297
297
|
}
|
298
298
|
|
299
|
-
if(app && app->
|
299
|
+
if(app && WR_QUEUE_SIZE(app->q_workers) > 0) {
|
300
300
|
// int rv = 0;
|
301
301
|
req->app = app;
|
302
302
|
wr_req_resolve_static_content(req);
|
data/src/head/wr_worker.c
CHANGED
@@ -42,12 +42,12 @@ static inline void wr_wrk_allocate(wr_wkr_t* worker) {
|
|
42
42
|
wr_svr_t* server = app->svr;
|
43
43
|
int retval;
|
44
44
|
//do we need high load ratio check here?
|
45
|
-
if(app && app->
|
45
|
+
if(app && app->q_messages->q_count > 0) {
|
46
46
|
//There is pending request
|
47
|
-
WR_QUEUE_FETCH(app->
|
47
|
+
WR_QUEUE_FETCH(app->q_messages, req) ;
|
48
48
|
|
49
49
|
if(req == NULL) {
|
50
|
-
WR_QUEUE_INSERT(app->
|
50
|
+
WR_QUEUE_INSERT(app->q_free_workers, worker, retval) ;
|
51
51
|
} else {
|
52
52
|
LOG_DEBUG(4,"Allocate worker %d to req id %d", worker->id , req->id);
|
53
53
|
req->wkr = worker;
|
@@ -59,7 +59,7 @@ static inline void wr_wrk_allocate(wr_wkr_t* worker) {
|
|
59
59
|
} else if(app) {
|
60
60
|
//No any pending request. Add Worker to free worker list
|
61
61
|
LOG_DEBUG(4,"Message queue is empty");
|
62
|
-
WR_QUEUE_INSERT(app->
|
62
|
+
WR_QUEUE_INSERT(app->q_free_workers, worker, retval) ;
|
63
63
|
} else {
|
64
64
|
//Remove worker
|
65
65
|
LOG_ERROR(SEVERE,"wr_wrk_allocate: Remove worker with pid %d.", worker->pid);
|
@@ -366,7 +366,7 @@ static inline void wr_wkr_recreate(wr_wkr_t *worker) {
|
|
366
366
|
wr_wkr_remove(worker, 0);
|
367
367
|
//create new worker if required
|
368
368
|
if(TOTAL_WORKER_COUNT(app) < app->conf->min_worker ||
|
369
|
-
app->
|
369
|
+
app->q_messages->q_count > app->high_ratio) {
|
370
370
|
wr_app_wkr_add(app);
|
371
371
|
}
|
372
372
|
}
|
@@ -504,19 +504,19 @@ int wr_wkr_remove(wr_wkr_t *worker, int flag) {
|
|
504
504
|
worker->state -= WR_WKR_ACTIVE;
|
505
505
|
|
506
506
|
if(app) {
|
507
|
-
LOG_INFO("Removing worker %d with pid %d...app->
|
508
|
-
worker->id, worker->pid,app->
|
507
|
+
LOG_INFO("Removing worker %d with pid %d...app->q_workers->q_count=%d, q_front=%d, q_rear=%d app=%s",
|
508
|
+
worker->id, worker->pid,app->q_workers->q_count,app->q_workers->q_front,app->q_workers->q_rear,
|
509
509
|
app->conf->name.str);
|
510
510
|
} else {
|
511
511
|
LOG_INFO("Removing worker %d with pid %d", worker->id, worker->pid);
|
512
512
|
}
|
513
513
|
|
514
|
-
if(app && wr_queue_remove(app->
|
514
|
+
if(app && wr_queue_remove(app->q_workers, worker) == 0) {
|
515
515
|
app->high_ratio = TOTAL_WORKER_COUNT(app) * WR_MAX_REQ_RATIO;
|
516
|
-
app->low_ratio = WR_QUEUE_SIZE(app->
|
516
|
+
app->low_ratio = WR_QUEUE_SIZE(app->q_workers) * WR_MIN_REQ_RATIO;
|
517
517
|
|
518
518
|
if(flag) {
|
519
|
-
wr_queue_remove(app->
|
519
|
+
wr_queue_remove(app->q_free_workers, worker);
|
520
520
|
}
|
521
521
|
wr_wkr_free(worker);
|
522
522
|
return 0;
|
@@ -679,7 +679,7 @@ int wr_wkr_connect(wr_ctl_t *ctl, const wr_ctl_msg_t *ctl_msg) {
|
|
679
679
|
worker->state += WR_WKR_CONNECTING;
|
680
680
|
|
681
681
|
// Insert newly added Worker to application list*/
|
682
|
-
if(
|
682
|
+
if(wr_app_wkr_insert(server, worker, ctl_msg)!=0) {
|
683
683
|
LOG_INFO("No more workers required.");
|
684
684
|
free(worker);
|
685
685
|
return -1;
|
@@ -765,14 +765,14 @@ int wr_wkr_connect(wr_ctl_t *ctl, const wr_ctl_msg_t *ctl_msg) {
|
|
765
765
|
return -1;
|
766
766
|
}
|
767
767
|
|
768
|
-
if(wr_queue_insert(worker->app->
|
768
|
+
if(wr_queue_insert(worker->app->q_workers, worker) < 0){
|
769
769
|
LOG_ERROR(WARN,"Worker queue is full.");
|
770
770
|
worker->app->high_ratio = TOTAL_WORKER_COUNT(worker->app) * WR_MAX_REQ_RATIO;
|
771
771
|
return -1;
|
772
772
|
}
|
773
773
|
|
774
774
|
//Setting low load ratio for application, refer "wr_worker_remove_cb" in wr_server.c for details.
|
775
|
-
worker->app->low_ratio = worker->app->
|
775
|
+
worker->app->low_ratio = worker->app->q_workers->q_count * WR_MIN_REQ_RATIO;
|
776
776
|
ctl->wkr = worker;
|
777
777
|
LOG_DEBUG(DEBUG,"Added Worker %d",worker->id);
|
778
778
|
|
@@ -783,7 +783,8 @@ int wr_wkr_connect(wr_ctl_t *ctl, const wr_ctl_msg_t *ctl_msg) {
|
|
783
783
|
wr_wrk_allocate(worker);
|
784
784
|
LOG_DEBUG(5,"Successfully connected to worker");
|
785
785
|
LOG_DEBUG(DEBUG,"Allocated task to newly added worker %d",worker->id);
|
786
|
-
|
786
|
+
wr_app_wkr_balance(worker->app);
|
787
|
+
//wr_app_wkr_added_cb(worker->app);
|
787
788
|
|
788
789
|
return 0;
|
789
790
|
}
|
@@ -837,9 +838,7 @@ void wr_wkr_remove_cb(wr_ctl_t *ctl, const wr_ctl_msg_t *ctl_msg) {
|
|
837
838
|
wr_ctl_resp_write(ctl);
|
838
839
|
|
839
840
|
// Create new worker if required
|
840
|
-
if(app && app->
|
841
|
-
wr_app_wkr_add(app);
|
842
|
-
}
|
841
|
+
if(app && app->state == WR_APP_ACTIVE) wr_app_wkr_balance(app);
|
843
842
|
}
|
844
843
|
|
845
844
|
/** Worker ping callback */
|
data/tasks/gem.rake
CHANGED
@@ -35,7 +35,7 @@ spec = Gem::Specification.new do |s|
|
|
35
35
|
s.version = Webroar::VERSION::STRING
|
36
36
|
s.platform = Gem::Platform::RUBY
|
37
37
|
s.summary = "A ruby application server."
|
38
|
-
s.description = "WebROaR is
|
38
|
+
s.description = "WebROaR is an application server that makes deployments of ruby web applications extremely simple. It provides an integrated solution to view the run time performance numbers and email notifications in case any exceptions occur in any of the deployed applications. It is 5 to 55% faster than all other comparable deployment stacks for Ruby on Rails applications. Check out http://webroar.in for more details."
|
39
39
|
s.authors = ["Aditya Babbar", "Dharmarth Shah", "Nikunj Limbaseeya"]
|
40
40
|
s.email = ["aditya.babbar@webroar.in", "dharmarth.shah@webroar.in", "nikunj.limbaseeya@webroar.in"]
|
41
41
|
s.homepage = "http://webroar.in"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webroar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aditya Babbar
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2010-03-
|
14
|
+
date: 2010-03-22 00:00:00 +05:30
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -84,7 +84,7 @@ dependencies:
|
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: 2.3.12
|
86
86
|
version:
|
87
|
-
description: WebROaR is
|
87
|
+
description: WebROaR is an application server that makes deployments of ruby web applications extremely simple. It provides an integrated solution to view the run time performance numbers and email notifications in case any exceptions occur in any of the deployed applications. It is 5 to 55% faster than all other comparable deployment stacks for Ruby on Rails applications. Check out http://webroar.in for more details.
|
88
88
|
email:
|
89
89
|
- aditya.babbar@webroar.in
|
90
90
|
- dharmarth.shah@webroar.in
|