Skip to content

Commit d622855

Browse files
committed
fixed #336 - slow performance on windows
1 parent f3c16b7 commit d622855

File tree

5 files changed

+21
-35
lines changed

5 files changed

+21
-35
lines changed

marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/flow-lib.xqy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,6 @@ declare function flow:validate-entities()
862862
let $_ :=
863863
for $entity in flow:get-entities()/hub:entity
864864
for $flow in $entity/hub:flows/hub:flow
865-
let $_ := xdmp:log(("flow!", $flow))
866865
let $data-format := $flow/hub:data-format
867866
(: validate collector :)
868867
let $_ :=

marklogic-data-hub/src/main/resources/ml-modules/services/flow.xqy

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ declare function delete(
9898
$params as map:map
9999
) as document-node()?
100100
{
101-
let $_ := flow:invalidate-flow-caches()
102-
return
103-
document { () }
101+
debug:dump-env("INVALIDATE FLOW CACHES"),
102+
103+
perf:log('/v1/resources/flow:delete', function() {
104+
let $_ := flow:invalidate-flow-caches()
105+
return
106+
document { () }
107+
})
104108
};

quick-start/src/main/java/com/marklogic/quickstart/service/FileSystemEventListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
@Component
1010
public interface FileSystemEventListener {
1111

12-
void onWatchEvent(HubConfig hubConfig, Path path);
12+
void onWatchEvent(HubConfig hubConfig);
1313
}

quick-start/src/main/java/com/marklogic/quickstart/service/FileSystemWatcherService.java

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ public void removeListener(FileSystemEventListener listener) {
6464
listeners.remove(listener);
6565
}
6666

67-
private void notifyListeners(HubConfig hubConfig, Path path) {
67+
private void notifyListeners(HubConfig hubConfig) {
6868
// notify global listeners
6969
synchronized (listeners) {
7070
for (FileSystemEventListener listener : listeners) {
7171
try {
72-
listener.onWatchEvent(hubConfig, path);
72+
listener.onWatchEvent(hubConfig);
7373
}
7474
catch (Exception e) {
7575
logger.error("Exception occured on listener", e);
@@ -146,50 +146,28 @@ public synchronized void destroy() throws Exception {
146146
private class DirectoryWatcherThread extends Thread {
147147

148148
private HubConfig hubConfig;
149-
private final int DELAY = 500;
149+
private final int DELAY = 1000;
150150

151-
// Use a SET to prevent duplicates from being added when multiple events on the
152-
// same file arrive in quick succession.
153-
HashSet<Path> filesToReload = new HashSet<>();
154151
Timer processDelayTimer = null;
155152

156153
DirectoryWatcherThread(String name, HubConfig hubConfig) {
157154
super(name);
158155
this.hubConfig = hubConfig;
159156
}
160157

161-
private synchronized void addFileToProcess(Path path) {
162-
boolean alreadyAdded = !filesToReload.add(path);
163-
logger.info("Queuing file for processing: "
164-
+ path.toString() + (alreadyAdded?"(already queued)":""));
158+
private synchronized void queueReload() {
165159
if (processDelayTimer != null) {
166160
processDelayTimer.cancel();
167161
}
168162
processDelayTimer = new Timer();
169163
processDelayTimer.schedule(new TimerTask() {
170164
@Override
171165
public void run() {
172-
processFiles();
166+
notifyListeners(hubConfig);
173167
}
174168
}, DELAY);
175169
}
176170

177-
private synchronized void processFiles() {
178-
// Iterate over the set of file to be processed
179-
for (Iterator<Path> it = filesToReload.iterator(); it.hasNext();) {
180-
Path path = it.next();
181-
182-
// Sometimes you just have to do what you have to do...
183-
logger.info("Processing file: " + path.toString());
184-
185-
// notify listeners
186-
notifyListeners(hubConfig, path);
187-
188-
// Remove this file from the set.
189-
it.remove();
190-
}
191-
}
192-
193171
@Override
194172
public void run() {
195173
for (;;) {
@@ -220,8 +198,8 @@ public void run() {
220198
Path child = dir.resolve(context);
221199

222200
// print out event
223-
logger.info("Event received: {} for: {}", event.kind().name(), child);
224-
addFileToProcess(child);
201+
logger.debug("Event received: {} for: {}", event.kind().name(), child);
202+
queueReload();
225203

226204
// if directory is created, then register it and its sub-directories
227205
// we are always listening recursively

quick-start/src/main/java/com/marklogic/quickstart/web/ProjectsController.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,13 @@ public void onValidate(JsonNode validation) {
352352
template.convertAndSend("/topic/validate-status", validation);
353353
}
354354

355+
/**
356+
* Called when the filesystem watcher detects a file change. We then install the user modules
357+
* @param hubConfig - must pass the hub config because this runs in a separate thread and doesn't
358+
* have access to the current spring boot context
359+
*/
355360
@Override
356-
public void onWatchEvent(HubConfig hubConfig, Path path) {
361+
public void onWatchEvent(HubConfig hubConfig) {
357362
installUserModules(hubConfig, false);
358363
}
359364

0 commit comments

Comments
 (0)