May 13, 2020
Estimated Post Reading Time ~

Dispatcher + Interview Questions

The dispatcher is Adobe Experience Manager's caching and/or load balancing tool. The dispatcher also helps to protect your AEM server from attack.

The Dispatcher helps realize an environment i.e both fast and dynamic. It works as a part of a static HTML server, with the aim of :
Storing as much of the site content as is possible, in the form of a static website.
Accessing the layout as little as possible. more

Interview Questions
Note:
For more on Dispatcher watch this video

1. What is dispatcher?
The dispatcher is an Adobe Experience Manager's caching and/or load balancing tool. The dispatcher also helps to protect your AEM server from attack.

The Dispatcher helps realize an environment i.e both fast and dynamic. It works as a part of a static HTML server, with the aim of :
  • Storing as much of the site content as is possible, in the form of a static website.
  • Accessing the layout as little as possible.
For caching, the Dispatcher module uses the Web server's ability to serve static content. The Dispatcher places the cached documents in the document root of the Web server.

2. How does the Dispatcher perform caching?
The Dispatcher uses the web server's ability to serve static content. The Dispatcher stores cached documents in the web server’s document root. The Dispatcher has two primary methods for updating the cached content when changes are made to the website.
  • Content Updates remove the pages that have changed, as well as files that are directly associated with them.
  • Auto-Invalidation automatically invalidates those parts of the cache that may be out of date after an update. For example, it effectively flags relevant pages as being out of date, without deleting anything.Example of cache section:
/cache
{
/docroot "/opt/dispatcher/cache"
/statfile "/tmp/dispatcher-website.stat"
/allowAuthorized "0"
/rules
{
# List of files that are cached
}
/invalidate
{
# List of files that are auto-invalidated
}
}


3. How does dispatcher perform load balancing? What are the benefits of load balancing?
Load Balancing distributes user requests (load) across different clustered CQ instances. The following list describes the advantages of load balancing:
  • Increased processing power: In practice, this means that the Dispatcher shares document requests between several instances of AEM. Because each instance has fewer documents to process, you have faster response times. The Dispatcher keeps internal statistics for each document category, so it can estimate the load and distribute the queries efficiently.
  • Increased fail-safe coverage: If the Dispatcher does not receive responses from an instance, it will automatically relay requests to one of the other instance(s). Thus, if an instance becomes unavailable, the only effect is a slowdown of the site, proportionate to the computational power lost.
4. What is statfile?
The /statfile property identifies the file to use as the statfile. The dispatcher uses this file to register the time of the most recent content update. The statfile can be any file on the webserver.

The statfile has no content. When content is updated, Dispatcher updates the timestamp. The default statfile is named .stat and is stored in the docroot. Dispatcher blocks access to the statfile. 

Example:
/cache
{
/docroot "/opt/dispatcher/cache"
/statfile "/tmp/dispatcher-website.stat"
/allowAuthorized "0"
/rules
{
# List of files that are cached
}
/invalidate
{
# List of files that are auto-invalidated
}
}


5. What is the dispatcher.any file?
By default, the Dispatcher configuration is stored in the dispatcher.any text file, though you can change the name and location of this file during installation.

The configuration file contains a series of single-valued or multi-valued properties that control the behavior of Dispatcher:
  • Property names are prefixed with a forward-slash ("/").
  • Multi-valued properties enclose child items using braces ("{ }").
6. What are the requests not cached by the dispatcher?
By default, the following requests are not cached by the dispatcher
  • Request that does not return http code 200
  • Requests with suffixes
  • Requests with request parameter(i.e ?)
  • Programmatically: send an http header
  • response.setHeader("Dispatcher", "no-cache")
7. How to restrict external access to resources in Dispatcher?
The Dispatcher filter can be used to allow or deny external access to specific areas of AEM. To protect our instance we should configure the Dispatcher to restrict external access as far as possible. First, we should deny access to all files and then allow/deny access to specific areas. 
Example:
/filter {
/0001 { /glob "*" /type "deny" }
/0002 { /type "allow" /url "/libs/cq/workflow/content/console*" }
/0003 { /type "deny" /url "/libs/cq/workflow/content/console/archive*" }
}

8. How does the Dispatcher return documents?
We can define whether the Dispatcher caches a document by using the Dispatcher configuration file, dispatcher.any. The Dispatcher checks the request against the list of cacheable documents. If the document is not on this list, the Dispatcher requests the document from the AEM instance. The Dispatcher always requests the document directly from the AEM instance in the following cases:
  • If the HTTP method is not GET. Other common methods are POST for form data and HEAD for the HTTP header.
  • If the request URI contains a question mark "?". This usually indicates a dynamic page, such as a search result, which does not need to be cached.
  • The file extension is missing. The web server needs the extension to determine the document type (the MIME-type).
  • The authentication header is set (this can be configured).
The Dispatcher stores cached files on the webserver as if they were part of a static website. If a user requests a cached document, the Dispatcher checks whether the document exists in the web server's file system. If so, the Dispatcher returns the documents. If not, the Dispatcher requests the document from the AEM instance.

9. How to implement permission sensitive caching?
https://docs.adobe.com/docs/en/dispatcher/permissions-cache.html

10. Can I cache only files with specific extensions?
Yes. For example, if you want to cache only GIF files, specify *.gif in the cache section of the dispatcher.any configuration file.

11. How does the Dispatcher determine if a document is up-to-date?
  • If the document is not subject to auto-invalidation. The dispatcher will consider it as up-to-date.
  • If the document is subject to auto-invalidation. Dispatcher checks whether it is the latest version or not. If not Dispatcher will request the current version from AEM.
12. Can I implement multiple Dispatchers in a setup?
Yes. In such cases, ensure that both the Dispatchers can access the CQ website directly. A Dispatcher cannot handle requests coming from another Dispatcher.

13. Can a Dispatcher and an AEM Publish instance reside on the same physical machine?
Yes, if the machine is sufficiently powerful. However, it is recommended that you set up the Dispatcher and the AEM Publish instance on different machines.

14. Can I use sticky connections and caching in tandem?
For most pages that use sticky connections, you should turn off caching. Otherwise, the same instance of the page is displayed to all users, regardless of the session content.

For some applications, it can be possible to use both sticky connections and caching. For example, if you display a form that writes data to a session, you can use sticky connections and cache in tandem.

15. Can we run the AEM website without Dispatcher?
Yes, we can. But it is a very bad idea.

16. Can I have Dispatcher for AEM author instance?
Yes, We can have Dispatcher for AEM author instance.

17. How do I delete files from the cache?
We can delete files from the CQ cache by using an HTTP request. When the HTTP request is received, Dispatcher deletes the files from the cache. Dispatcher caches the files again only when it receives a client request for the page. Deleting cached files in this manner is appropriate for web sites that are not likely to receive simultaneous requests for the same page.

The HTTP request has the following syntax:
POST /dispatcher/invalidate.cache HTTP/1.1
CQ-Action: Activate
CQ-Handle: path-pattern
Content-Length: 0

Dispatcher deletes the cached files and folders that have names that match the value of the CQ-Handle header. For example, a CQ-Handle of /content/geomtrixx-outdoors/en matches the following items:
  • All files (of any file extension) named en in the geometrixx-outdoors directory
  • Dispatcher only flushes files or directories that match en.* in the geometrixx-outdoors directory. The directory en itself will only be deleted if the "CQ-Action" is "Delete" or "Deactivate".
18. How to prevent one particular component to be cached, while you are caching the whole page into dispatcher?
We have to configure the component(which we don't want to be cached) into Sling Dynamic Include (SDI) configuration.

Sling Dynamic Include (SDI) is an OSGi service that is able to automatically replace configured components with the include tags. we can enter a list of components (using their resource types) into SDI configuration, choose the include tag type (SSI, ESI, or AJAX) and SDI will do the rest. It's totally transparent, we can use it with any components, and developers don't have to write any code related to the includes. Every configuration change is seen immediately in the page content. we can enable it only on production machines or on the publish instances, etc.

19. What are the documents cached by the dispatcher?
We configure caching behavior inside /cache property. Inside /rules property, we can mention the list of cacheable documents.
/cache
   {
  # Cache configuration
   /rules
   {
     # List of cachable documents
    }
   /invalidate
   {
    # List of auto-invalidated documents
    }
  }

20. What are the subjects of the documents to auto invalidation for dispatcher?
We configure caching behavior inside /cache property. Inside /invalidate property, we can mention the list of documents that are subject to auto-invalidation.
/cache
   {
  # Cache configuration
   /rules
   {
     # List of cachable documents
    }
   /invalidate
   {
    # List of auto-invalidated documents
    }
  }


21. What is /renders property?
The /renders property defines the URL to which Dispatcher sends requests to render a document. The following example /renders section distributes render requests equally among two AEM instances:
/renders
  {
   /myFirstRenderer
   {
    /hostname "myCompany.com"
     /port "4503"
   }
  /mySecondRenderer
    {
    /hostname "127.0.0.1" #runs on the same computer as Dispatcher
    /port "4503"
    }
   }


22. How to setup Dispatcher in AEM?
http://www.aemcq5tutorials.com/tutorials/set-up-dispatcher-in-aem/


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.