Skip to Content
author's profile photo Former Member
Former Member

How can media queries be cached more effectively with Varnish ?

  • We are using hybris 5.2.0 in cluster mode, we are using Varnish to cache content delivered over HTTP.

  • After applying the hybris security patch, we have noticed in our production system that most queries sent to the database are queries for media recorded in the server access log. The media url is now like this : GET /media /?context=bWFzdGVyfDIzMFd4MjMwSHw5OTY5fGdlL... We have roughly 100 media queries per second, at peak times that number is much higher.

  • It looks like the media query caching is pretty ineffective, and it seems that Varnish cannot easly cache those URLs. Is the he context parameter of the media URLs make them variables ? This mean that my media url should appear without the context token? Can "pretty url" solve the problem ?

Any idea or configuration to fix this ? Thanks for advance

Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 09, 2014 at 10:09 AM

    Hi,

    The context parameter value is a constant for a particular media. It is Base64 encoded string containing information about tenant, media folder, size, mime, location in storage and hash of location, thus it cannot change. In latest version of hybris platform this URL looks little bit different - it contains file name also visible in the URL to satisfy SEO - so it looks similar to that

    http://domain.com/medias/file.jpg?context=bWFzdGVyfDI

    I'm not sure what is your problem exactly, but from what I understood your Varnish cache system is trying to cache those URLs as mad. Maybe you have upgraded from previous version of hybris in which URLs have looked completely different and Varnish must cache them from the scratch?

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 09, 2014 at 11:12 PM

    Hi,

    • When medias urls are generated and do not point to a physical file, there is a media web application running on hybris that will interpret the URL and find the real file.That's the reason why hybris medias need be served by Tomcat.

    • Recommendation INFRA :Serve static web content from Apache, using the PrettyURL feature provided by hybris 5.x.This option allows to use medias urls that point to a physical file. With prettyURL disabled --> There could be a performance penalty. With prettyURL enabled, an example URL looks like this:/medias/sys_master/(folder)/h78/hd0/8796125986846.jpg.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 10, 2014 at 04:37 PM

    "prettyURL" is indeed the way to go if you want to serve medias via webserver. If your varnish config needs proper urls, this is the way to go for you.

    Unfortunately prettyURL is now called "legacy", so there is the chance it will be removed, killing website performance big time.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Indeed - prettyURL is marked as "legacy", but you always have in your hand MediaURLStrategy interface which you can implement as you want so you can craft your very own URL. Currently our media storage is really elastic.

  • author's profile photo Former Member
    Former Member
    Posted on Dec 10, 2014 at 07:46 PM

    Serving content out of apache is indeed the way forward, using Tomcat for that in a production environment is asking for trouble. Follow your INFRA team advice.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.