| Author |
Message |
< Yaws mailing list ~ A dirty patch for serving static data with fcgi |
| Guest |
Posted: Sun Sep 13, 2009 2:57 pm |
|
|
|
Guest
|
Hi
It's been a few days with erlang, and one day with yaws, so please warn me if i'm digging
the wrong hole
Considering replacing my lighttpd+django setups with yaws+django, i began playing with yaws yesterday.
By following the rails on yaws example setting at http://wiki.github.com/klacke/yaws/run-rails-under-yaws
managed to run django with fcgi on yaws. One thing that bugged me was, all the requests are passed to
fcgi instance, whether it's dynamic or static content request, causing unnecessary load on fcgi app.
see snippet below
out(Arg) ->
case yaws_cgi:call_fcgi_responder(Arg) of
R when is_list(R) ->
case proplists:get_value(status, R) of
404 -> {page, Arg#arg.server_path}; % Let Yaws try to serve static files
_ -> R
end;
X -> X
end.
i've added a per-server "static_paths" parameter to yaws.conf. sample usage below
<server blah>
...
static_paths = /media/, /files/
</server
which enables some more control over the static content handling in my django appmod. snippet below
...
out(Arg) ->
case lists:filter(fun(Y) -> string:rstr(Arg#arg.server_path, Y) =/= 0 end, Arg#arg.static_paths) of
[_|_] ->
%% serve static
error_logger:info_msg("static serving ~p~n",[Arg#arg.server_path]),
{page, Arg#arg.server_path};
_ ->
error_logger:info_msg("dynamic serving ~p~n",[Arg#arg.server_path]),
case yaws_cgi:call_fcgi_responder(Arg) of
R when is_list(R) ->
case proplists:get_value(status, R) of
404 ->
{page, Arg#arg.server_path}; % Let Yaws try to serve static files
_ -> R
end;
X -> X
end
end.
Regards
--
Ozgur <hinoglu@gmail.com>
Post received from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Sun Sep 13, 2009 4:02 pm |
|
|
|
Guest
|
On Sun, Sep 13, 2009 at 10:58 AM, Ozgur <hinoglu@gmail.com (hinoglu@gmail.com)> wrote:
Quote: Hi
It's been a few days with erlang, and one day with yaws, so please warn me if i'm digging
the wrong hole
Considering replacing my lighttpd+django setups with yaws+django, i began playing with yaws yesterday.
By following the rails on yaws example setting at http://wiki.github.com/klacke/yaws/run-rails-under-yaws
managed to run django with fcgi on yaws. One thing that bugged me was, all the requests are passed to
fcgi instance, whether it's dynamic or static content request, causing unnecessary load on fcgi app.
see snippet below
out(Arg) ->
|
|
|
| Back to top |
|
| Guest |
Posted: Sun Sep 13, 2009 8:55 pm |
|
|
|
Guest
|
> and take appropriate action if it is. If you'd rather keep the list of
> static paths out of your code so it can be easily changed, you could use the
> opaque field of the server conf and set it to whatever you like. You could
> also use a yapp instead of an appmod and keep the list of static paths as
> part of the environment in your .app file.
>
> Can you try one of these approaches instead and see how you get on, then let
> us know?
Steve thanks for pointers. following is my final mod_django.erl with vanilla yaws
seems to work good
out(Arg) ->
case proplists:get_value("static_paths", Arg#arg.opaque) of
P when is_list(P) ->
Sp = lists:filter(fun(Y) -> Y =/= [] end,
lists:map(fun(X)-> string:strip(X) end, string:tokens(P, ","))),
case lists:filter(fun(Y) -> string:rstr(Arg#arg.server_path, Y) == 1 end, Sp) of
[_|_] ->
%% serve static
error_logger:info_msg("static serving ~p~n",[Arg#arg.server_path]),
{page, Arg#arg.server_path};
_ ->
error_logger:info_msg("dynamic serving ~p~n",[Arg#arg.server_path]),
case yaws_cgi:call_fcgi_responder(Arg) of
R when is_list(R) ->
case proplists:get_value(status, R) of
404 ->
{page, Arg#arg.server_path}; % Let Yaws try to serve static files
_ -> R
end;
X -> X
end
end;
_ ->
{page, Arg#arg.server_path} % Let Yaws try to serve static files
end.
--
Ozgur <hinoglu@gmail.com>
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post received from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Sun Sep 13, 2009 11:30 pm |
|
|
|
Guest
|
| On Sun, Sep 13, 2009 at 4:56 PM, Ozgur |
|
|
| Back to top |
|
| Guest |
Posted: Mon Sep 14, 2009 9:22 am |
|
|
|
Guest
|
> Great, glad to hear it works for you. You might consider adding an entry to
> the Yaws wiki about your work.
I will update the wiki in a few days.
>
> There's one other part of your original patch that caught my eye: the
> increase on the FCGI timeout. Should that be boosted? Both your patch and
Yes, 1 sec is too short for fcgi application to return a response. All the pages of my application required local
database interaction and i did not try the response time by calling a test page that just returns a fixed string, so i'm not sure
what is the real bottleneck here, yet increasing the read timeout value fixes "fcgi failed" problem.
Regards,
Özgür
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post received from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Mon Sep 14, 2009 10:28 am |
|
|
|
Guest
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|
|