Watch mode in current implementation is dangerous.

Even if developer will enabled it on local machine, it will slow if drupal bootstrap is long, 300+ ms.

If developer or several developers will forget to disable watch mode on production site, it may kill sever performance.

Ways to resolve this:
1. Add long polling.
2. Add permission to use watch mode for avoid watch mode for all users.

I can implement this, what you think about?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

popstas created an issue. See original summary.

popstas’s picture

Status: Active » Needs review
FileSize
4.32 KB

Here's the patch with long-polling watch mode.
Module now stores last modified of less files.

If files was modified less than 1 hour ago, ajax/less/watch now check modified files 250 times with 100 ms pauses, so drupal bootstrap executes 100 times less frequently.
100 checks for changed files passes for 500 ms.

If files was modified more than 1 hour ago, less.watch.js not included on page load,
and ajax/less/watch now checks for changed files once and then sleeps for 25 seconds.

corey.aufang’s picture

Looks interesting.

I'll take a look at and test it Monday.

popstas’s picture

I found that my solution begins consume lots of cpu if less has syntax error, I'll fix it tomorrow.

mikkopaltamaa’s picture

Reloading stylesheets twice a second is total overkill. Something like once per 15 s would be totally sufficient and would not waste resources that much. Popstas' idea of making it permission-based and gradually slowing if there are no changes would be a good idea as well.

I'm sure that hosting providers hate a feature that makes all browsers reload the stylesheets twice a second. If you accidentally put in on on a live website, 100 concurrent users will make 200 requests per second, causing similar effects like a DOS attack. Also, it seems to crash Firefox if you have multiple browser tabs open at the same time.

RgnYLDZ’s picture

I disagree with @mikkopaltamaa , IMO the refresh should be every 1s (or even .5s). It boost up the development process and avoids to debug every block code you wrote every time.

popstas’s picture

With long polling module send one request per 30s and waiting for less files modifications. If any file was changed, request immediately closing with list of files for reload.

So, less updates makes ever faster than sending requests twice at second.

popstas’s picture

Updated patch after several months of usage on about 5 sites.