Thread: [Cppcms-users] xsendfile
Brought to you by:
artyom-beilis
From: Markus R. <us...@ma...> - 2009-12-01 15:24:56
|
Hi list! I tried to use xsendfile to send files to the user from my cppcms application. I succeeded with lighttpd using: add_header("Content-Disposition: attachment; filename=\"" + my_path.leaf() + '"'); add_header("X-LIGHTTPD-send-file: " + root + "/" + file); only adding the option "allow-x-send-file" => "enable" in config file. (section $API.server) But because of another bug I can't use lighttpd (at least the 1.4.*): http://redmine.lighttpd.net/issues/show/729 So I tried the same with nginx - but without success. Maybe someone here can help me? add_header("X-Accel-Redirect: /Homepage/" + file) leads to this sequence of requests[0], having in log[1]. Ok, does not surprise much, because it is not really a sendfile, but rather a redirection feature (which can be misused to send files). So I added: location /Homepage { root /home/markus/Projekte; internal; } in the configuration inside server section. But this does not change anything[0,1]. Seems like that rule is simply ignored, maybe because of the other locations present in the config file? I directly changed cppcms_run to add that config snippet. Any hints? @Artyom: Do you plan to add sendfile support in the cppcms_run configs? At least for lighttpd it is very easy. thanks Markus Raab [0] X-Accel-Redirect: /Homepage/logo.png X-Accel-Redirect: /Homepage/Homepage/logo.png X-Accel-Redirect: /Homepage/Homepage/Homepage/logo.png X-Accel-Redirect: /Homepage/Homepage/Homepage/Homepage/logo.png ... X-Accel-Redirect: /Homepage/Homepage/Homepage/Homepage/Homepage/Homepage/Homepage/Homepage/Homepage/Homepage/Homepage/logo.png [1] 2009/12/01 16:09:42 [error] 4792#0: *1 rewrite or internal redirection cycle while internal redirect to "/Homepage/Homepage/Homepage/Homepage/Homepage/Homepage/Homepage/Homepage/Homepage/Homepage/Homepage/logo.png" while reading response header from upstream, client: 192.168.0.3, server: localhost, request: "GET /logo.png HTTP/1.1", upstream: "fastcgi://unix:/tmp/fcgi-hello.socket:", host: "markusbyte:8080" -- http://www.markus-raab.org | Das Mittelmaß ist gut dem Alter wie der -o) | Jugend, nur Mittelmäßigkeit allein ist Kernel 2.6.24-1-a /\ | keine Tugend. -- G.E.Lessing, Nathan der on a x86_64 _\_v | Weise |
From: Artyom <art...@ya...> - 2009-12-01 15:48:16
|
> But because of another bug I can't use lighttpd (at least the 1.4.*): > http://redmine.lighttpd.net/issues/show/729 Have you tried to use it with URL-rewriting? Url rewriting would solve this problem for you. > Any hints? What happens is that you redirect from /logo.png -> /Homepage/logo.png. So then it looks where "/Homepage/log.." is placed and all starts again. I assume that this would be problematic for you to serve files from "/" and do anything else from "/" as I told before. So, for most generic case I would still recommend to use URL-rewriting. > @Artyom: Do you plan to add sendfile support in the cppcms_run configs? At > least for lighttpd it is very easy. I don't, but it shouldn't be too hard. However I don't think this is really necessary. The real issue is that Apache, Nginx and Lighttpd have different semantics for X-Send-File... So the CppCMS based software should deal with them differently, when the script tryes to unify the access to all web servers -- so it some kind of contradiction. I would suggest, for special cases where you do need to tweak web server configuration, just create a configuration file and run web server directly like: /usr/sbin/lighttpd -D -f ligthy.conf That's it. You can keep it persistent and not shut down when you work, because in any case of new connection it would try to make a new one so when you shut CppCMS application down, web server would not even notice. Only thing that remains is to run ./foobar -c config.txt cppcms_run utility was mostly provided to simplify web server configuration for common case. It can't be replacement for real configuration that should be created for the web server. Artyom |
From: Markus R. <us...@ma...> - 2009-12-04 16:05:15
|
Artyom wrote: >> But because of another bug I can't use lighttpd (at least the 1.4.*): >> http://redmine.lighttpd.net/issues/show/729 > > Have you tried to use it with URL-rewriting? Url rewriting would solve > this problem for you. Yes, you are right, that works. But I have another strange error when using lighttpd: 2009-12-04 16:52:34: (mod_fastcgi.c.2900) backend is overloaded; we'll disable it for 2 seconds and send the request to another backend instead: reconnects: 0 load: 3 2009-12-04 16:52:34: (mod_fastcgi.c.3542) all handlers for /src/url_to_file/Bilder/Orte/Schweiz2008/Uni Lichthof.jpg on /src/url_to_file are down. 2009-12-04 16:52:37: (mod_fastcgi.c.2673) fcgi-server re-enabled: 0 /tmp/fcgi-hello.socket When I benchmarked it with ab (from apache-utils) I see that 2, 3 connections at once work without any problems, but when I change concurrency to about 5 it fails: Failed requests: 2 (Connect: 0, Receive: 0, Length: 2, Exceptions: 0) Its always 2 failed requests, the other "succeed" with 500 - Internal Server Error. This problem is also easily reproduceable without ab by just opening an image gallery (where the browser opens dotzends of connections to download all thumbnails). The Result is that some images are not displayed. The problem occurs with standard config by cppcms and also the config with url rewriting: ----- rewrite config ------- server.modules = ("mod_fastcgi", "mod_rewrite") server.document-root = "/home/markus/Projekte/Homepage/" server.pid-file = "/home/markus/cppcms/url_to_file/build64/cppcms_rundir/srv.pid" server.port = 8080 server.bind = "markusbyte" url.rewrite = ("^(.*)" => "/src/url_to_file/$0") fastcgi.server = ( "/src/url_to_file" => ( "localhost" => ( "check-local" => "disable", "max-procs" => 1, "idle-timeout" => 20, "socket" => "/tmp/fcgi-hello.socket", "allow-x-send-file" => "enable" ))) ----- rewrite config ------- > However I don't think this is really necessary. > > The real issue is that Apache, Nginx and Lighttpd have different semantics > for X-Send-File... So the CppCMS based software should deal with them > differently, when the script tryes to unify the access to all web servers > -- so it some kind of contradiction. You are correct about that. Might not be as useful to have it in default cppcms_run configs. > I would suggest, for special cases where you do need to tweak web server > configuration, just create a configuration file and run web server > directly like: > > /usr/sbin/lighttpd -D -f ligthy.conf > > That's it. You can keep it persistent and not shut down when you work, > because in any case of new connection it would try to make a new one so > when you shut CppCMS application down, web server would not even notice. > > Only thing that remains is to run ./foobar -c config.txt Thank you, good idea. Markus -- http://www.markus-raab.org | Es genügt nicht, keine Gedanken zu haben. -o) | Man muß auch unfähig sein, sie Kernel 2.6.24-1-a /\ | auszudrücken. -- Karl Kraus on a x86_64 _\_v | |
From: Artyom <art...@ya...> - 2009-12-05 21:17:45
|
> But I have another strange error when using lighttpd: > 2009-12-04 16:52:34: (mod_fastcgi.c.2900) backend is > overloaded; > ... > When I benchmarked it with ab (from apache-utils) I see > that 2, 3 > connections at once work without any problems, but when I > change > concurrency to about 5 it fails: > Failed requests: 2 > (Connect: 0, Receive: 0, Length: 2, > Exceptions: 0) > > Its always 2 failed requests, the other "succeed" with 500 > - Internal Server > Error. > Other: > > server.port = 8080 > server.bind = "markusbyte" > Ok, first of all what "server.*" configuration are you using What Server API do you use, what model threaded or prefork? How many threads processed do you define? What buffer parameter do you use? I would recommend: Make "server.buffer" parameter big as twice as exepected cuncurrent requests no. Also provide reasonable number for "server.threads" or "server.procs" according to the mode you use. The default workers number is 5 which may explain the issue. See: http://cppcms.sourceforge.net/wikipp/en/page/ref_config Server API, and Server Mod. You may want something like: server.mod = "thread" # -- multithreaded working model server.threads = 20 # 20 or much more cuncurrent workers # but not too much server.buffer = 1000 # the size of queue of incoming requests What happens that lighttpd creates more connections than the server can handle. Giving big buffer value allows CppCMS service accept new connections and put them to queue, thus preventing of lighttpd report 500 -- overloaded service. Best, Artyom |
From: Markus R. <us...@ma...> - 2009-12-06 19:08:57
|
Artyom wrote: > Ok, first of all what "server.*" configuration are you using > What Server API do you use, what model threaded or prefork? > How many threads processed do you define? Sorry, I forgot to mention that. I tested with prefork and thread with up to 50 processes/threads. > What buffer parameter do you use? It seems that I overlooked that in the tutorial? I did not know that this value exists. > I would recommend: > > Make "server.buffer" parameter big as twice as exepected > cuncurrent requests no. > > Also provide reasonable number for "server.threads" or "server.procs" > according to the mode you use. > > The default workers number is 5 which may explain the issue. No, the problem was the buffer. I changed it to 100 and now there is no such problem. Thank you very much for that hint! It works great now. It runs incredible faster then before. thanks Markus P.s. Unfortunately I still can't reach the primary page for the wiki, so I can't change content there. -- http://www.markus-raab.org | Takt ist etwas, das niemand bemerkt, wenn -o) | man es hat, das aber jeder bemerkt, wenn Kernel 2.6.24-1-a /\ | man es einmal nicht hat. Gina Lollobrigida on a x86_64 _\_v | |
From: Artyom <art...@ya...> - 2009-12-06 19:56:22
|
Hi, > It seems that I overlooked that in the tutorial? I did not > know that this > value exists. I think I didn't mentioned it in tutorial only in referece. It is quite fine tuning parameter. Probably a page on high performance system configuration should be written. > No, the problem was the buffer. I changed it to 100 and now > there is no such > problem. Thank you very much for that hint! It works great > now. It runs > incredible faster then before. These are just one of many points that are risen when you do benchmarking. > > P.s. Unfortunately I still can't reach the primary page for > the wiki, so I > can't change content there. > I have some problems with server recently, I hope that I would have a time to setup VPS for better hosting then home ADSL line, because downtime issues quite bothering me recently. Best, Artyom |