changcheng / wro4j

Automatically exported from code.google.com/p/wro4j
0 stars 0 forks source link

ResourceWatcher checks the same file from multiple groups (included into each other) multiple times (not optimally) #521

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
e.g. I have my '*common*' group which is the only that is requested
and for convenience I've split it into multiple subgroups.
The first one ('*third-party*') has the following tree (will follow only jquery 
here):

<code language="xml">
  <group name="common">
    <group-ref>third-party</group-ref>
    <group-ref>general</group-ref>
    <group-ref>application</group-ref>
  </group>

  <group name="third-party">
    <group-ref>jquery</group-ref>
    <group-ref>aui</group-ref>
  </group>

  <group name="jquery">
    <js>/gui-common/jquery-1.4.2.min.js</js>

    <group-ref>jquery-query</group-ref>
    <group-ref>jquery-ui</group-ref>
  </group>

  <group name="jquery-query">
    <js>/gui-common/jquery.query-2.1.7.js</js>
  </group>

  <group name="jquery-ui">
    <css>/gui-common/jquery-ui-1.8.2.custom.css</css>

    <js>/gui-common/jquery-ui-1.8.2.custom.min.js</js>
  </group>
</code>

From logs I see that file: {{{jquery-1.4.2.min.js}}} is checked for several 
times in one "ResourceWatcher started" run for each group:

{{{
21:33:57,335 DEBUG ResourceWatcherRunnable:89 - Checking if group common is 
changed..
21:33:57,335 DEBUG ResourceWatcherRunnable:120 - Checking if resource 
ro.isdc.wro.model.resource.Resource@6224539d[JS,/gui-common/jquery-1.4.2.min.js,
true] is changed..
...
21:33:57,366 DEBUG ResourceWatcherRunnable:89 - Checking if group jquery is 
changed..
21:33:57,366 DEBUG ResourceWatcherRunnable:120 - Checking if resource 
ro.isdc.wro.model.resource.Resource@6224539d[JS,/gui-common/jquery-1.4.2.min.js,
true] is 
21:33:57,327  INFO ResourceWatcherRunnable:66 - ResourceWatcher started...
...
21:33:57,371 DEBUG ResourceWatcherRunnable:89 - Checking if group third-party 
is changed..
21:33:57,372 DEBUG ResourceWatcherRunnable:120 - Checking if resource 
ro.isdc.wro.model.resource.Resource@6224539d[JS,/gui-common/jquery-1.4.2.min.js,
true] is changed..
}}}

This can probably be improved to check the same file only once per 
ResourceWatcher run.

Currently the whole run/task takes for me not much:

{{{
21:48:19,637 DEBUG ResourceWatcherRunnable:84 - resource watcher info: 
StopWatch '': running time (millis) = 59
-----------------------------------------
ms     %     Task name
-----------------------------------------
00059  100%  detect changes
}}}

but as you wrote in issue #459 for 100 resources (probably on some slower 
systems) the whole run can take more then 1 second, so maybe if this is changed 
it can improve latency.
I can check performance again after it is changed if you find this is not 
optimal behavior and can be easily improved.

Original issue reported on code.google.com by lystoc...@gmail.com on 12 Aug 2012 at 6:56

GoogleCodeExporter commented 9 years ago
Actually the resource isn't checked twice, it is only logged twice. The 
implementation holds a map between the processed uri's and corresponding hash 
(digest). If the resource was checked, the cached hash is used. So it is 
optimal from this point of view. You can check the implementation. I'll create 
a wiki page which describes how the ResourceWatcher works in detail.

Feel free to reopen this issue if you have other suggestions.

Original comment by alex.obj...@gmail.com on 12 Aug 2012 at 7:01

GoogleCodeExporter commented 9 years ago
Can the log message be different in this case then. I just wanted to count how 
many files I have checked by watcher by looking up "Checking if resource" 
message.

Original comment by lystoc...@gmail.com on 12 Aug 2012 at 9:37

GoogleCodeExporter commented 9 years ago
Ok, the log message will be improved by logging the check only when it is 
actually performed.

Original comment by alex.obj...@gmail.com on 13 Aug 2012 at 7:23