file:read-binary performance
Wednesday, 25 November 2015 · 3 messages
JC
Jérôme Chauveau25 Nov 2015 10:57 #
Hi,
My restxq app is very slow to deliver raw files (css, images, js). For example, the restxq method takes around 600ms to load a png file in my browser when it takes only 2ms in a "direct" or "static" way.
---------------------------------------
declare
%rest:path("/editions/static/{$project}/{$file=.+}")
function max.file:file(
$project as xs:string,
$file as xs:string
) as item()+ {
let $path := file:parent(file:base-dir()) || 'editions/' || $project
|| '/ui/' || $file
return (
web:response-header(map { 'media-type': web:content-type($path) }),
file:read-binary($path)
)
};
---------------------------------------Why such a difference?
How can I improve it?
I am using BaseX 8.3 (war version).
Regards,
Jérôme
--
Jérôme Chauveau - CERTIC-DSI - Campus I
Université de Caen Normandie
CG
Christian Grün25 Nov 2015 11:07 #
Hi Jérôme,
I just created a new WebApp with your function inside, and I retrieved a 300 kb jpg file. In the browser console view, I could see that it took 18 ms to request it (on localhost), so I guess there must be another reason for this delay.
Feel free to provide us with more hints,
Christian
Quoted text · Jérôme Chauveau · 38 lines
On Wed, Nov 25, 2015 at 10:57 AM, Jérôme Chauveau <jerome.chauveau at unicaen.fr> wrote: > Hi, > > My restxq app is very slow to deliver raw files (css, images, js). > For example, the restxq method takes around 600ms to load a png file in my > browser when it takes only 2ms in a "direct" or "static" way. > > --------------------------------------- > declare > %rest:path("/editions/static/{$project}/{$file=.+}") > function max.file:file( > $project as xs:string, > $file as xs:string > ) as item()+ { > let $path := file:parent(file:base-dir()) || 'editions/' || $project || > '/ui/' || $file > return ( > web:response-header(map { 'media-type': web:content-type($path) }), > file:read-binary($path) > ) > }; > --------------------------------------- > > Why such a difference? > How can I improve it? > > I am using BaseX 8.3 (war version). > > Regards, > > Jérôme > > > -- > Jérôme Chauveau - CERTIC-DSI - Campus I > Université de Caen Normandie >
JC
Jérôme Chauveau25 Nov 2015 11:55 #
Hi Christian,
thank you for your answer.
Shame on me... I did not get the aim of .ignore files!
My app' slowness came from my resources (js, css, images) folder (a quite big one) which did not contain a .ignore file.
The difference is really impressive.
Regards,
Jérôme
Quoted text · Christian Grün · 51 lines
Le 25/11/2015 11:07, Christian Grün a écrit : > Hi Jérôme, > > I just created a new WebApp with your function inside, and I retrieved > a 300 kb jpg file. In the browser console view, I could see that it > took 18 ms to request it (on localhost), so I guess there must be > another reason for this delay. > > Feel free to provide us with more hints, > Christian > > > > On Wed, Nov 25, 2015 at 10:57 AM, Jérôme Chauveau > <jerome.chauveau at unicaen.fr> wrote: >> Hi, >> >> My restxq app is very slow to deliver raw files (css, images, js). >> For example, the restxq method takes around 600ms to load a png file in my >> browser when it takes only 2ms in a "direct" or "static" way. >> >> --------------------------------------- >> declare >> %rest:path("/editions/static/{$project}/{$file=.+}") >> function max.file:file( >> $project as xs:string, >> $file as xs:string >> ) as item()+ { >> let $path := file:parent(file:base-dir()) || 'editions/' || $project || >> '/ui/' || $file >> return ( >> web:response-header(map { 'media-type': web:content-type($path) }), >> file:read-binary($path) >> ) >> }; >> --------------------------------------- >> >> Why such a difference? >> How can I improve it? >> >> I am using BaseX 8.3 (war version). >> >> Regards, >> >> Jérôme >> >> >> -- >> Jérôme Chauveau - CERTIC-DSI - Campus I >> Université de Caen Normandie >>
--
Jérôme Chauveau - CERTIC-DSI - Campus I
Université de Caen Normandie
Written for BaseX 8.3. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery