TiddlyWiki / TiddlyWikiClassic

TiddlyWiki Classic (not to be confused with TiddlyWiki5: https://github.com/Jermolene/TiddlyWiki5)
https://classic.tiddlywiki.com/
492 stars 114 forks source link

Throttling updates to node.js backend when editing a Tiddler #268

Closed FlashSystems closed 3 years ago

FlashSystems commented 3 years ago

I'm a fairly fast typist and when writing a longer tiddler there are continuous PUT requests (every second) to the Node.js back-end. I had to reconfigure the flooding protection of my reverse proxy to get TiddlyWiki working.

Is there a way to throttle the TiddlyWeb-Saver? I tried to set $:/config/Drafts/TypingTimeout but this did not change the pace of the put requests. Saving every 10 Seconds or so should strike a good balance between the number of requests and loosing work if the browser tab/window gets closed.

Log

A short log that shows the PUT-Requests almost every second.

... [14/Oct/2020:19:39:40 +0200] "PUT /recipes/default/tiddlers/Draft%20of%20'New%20Tiddler' HTTP/2.0" 204 -
... [14/Oct/2020:19:39:41 +0200] "PUT /recipes/default/tiddlers/Draft%20of%20'New%20Tiddler' HTTP/2.0" 204 -
... [14/Oct/2020:19:39:42 +0200] "PUT /recipes/default/tiddlers/Draft%20of%20'New%20Tiddler' HTTP/2.0" 204 -
... [14/Oct/2020:19:39:43 +0200] "PUT /recipes/default/tiddlers/Draft%20of%20'New%20Tiddler' HTTP/2.0" 204 -
... [14/Oct/2020:19:39:44 +0200] "PUT /recipes/default/tiddlers/Draft%20of%20'New%20Tiddler' HTTP/2.0" 204 -
... [14/Oct/2020:19:39:45 +0200] "PUT /recipes/default/tiddlers/Draft%20of%20'New%20Tiddler' HTTP/2.0" 204 -
... [14/Oct/2020:19:39:47 +0200] "PUT /recipes/default/tiddlers/Draft%20of%20'New%20Tiddler' HTTP/2.0" 204 -
... [14/Oct/2020:19:39:48 +0200] "PUT /recipes/default/tiddlers/Draft%20of%20'New%20Tiddler' HTTP/2.0" 204 -
... [14/Oct/2020:19:39:49 +0200] "PUT /recipes/default/tiddlers/Draft%20of%20'New%20Tiddler' HTTP/2.0" 204 -
... [14/Oct/2020:19:39:50 +0200] "PUT /recipes/default/tiddlers/Draft%20of%20'New%20Tiddler' HTTP/2.0" 204 -
... [14/Oct/2020:19:39:51 +0200] "PUT /recipes/default/tiddlers/Draft%20of%20'New%20Tiddler' HTTP/2.0" 204 -
... [14/Oct/2020:19:39:52 +0200] "PUT /recipes/default/tiddlers/Draft%20of%20'New%20Tiddler' HTTP/2.0" 204 -
... [14/Oct/2020:19:39:54 +0200] "PUT /recipes/default/tiddlers/Draft%20of%20'New%20Tiddler' HTTP/2.0" 204 -
... [14/Oct/2020:19:39:55 +0200] "PUT /recipes/default/tiddlers/Draft%20of%20'New%20Tiddler' HTTP/2.0" 204 -
... [14/Oct/2020:19:39:56 +0200] "PUT /recipes/default/tiddlers/Draft%20of%20'New%20Tiddler' HTTP/2.0" 204 -
... [14/Oct/2020:19:39:57 +0200] "PUT /recipes/default/tiddlers/Draft%20of%20'New%20Tiddler' HTTP/2.0" 204 -
... [14/Oct/2020:19:39:58 +0200] "PUT /recipes/default/tiddlers/Draft%20of%20'New%20Tiddler' HTTP/2.0" 204 -

Versions

TiddlyWiki 5.1.22 on Node.JS 14.13.

pmario commented 3 years ago

$:/config/Drafts/TypingTimeout is only used for the TW page refresh. ... Saving back to the server is as fast as possible. There is no timeout atm.

pmario commented 3 years ago

I did have a look at the syncer.js code. IMO changing this behaviour can be tricky. TW internally can change several tiddlers at the same time. All of them are marked "dirty". They are written to a syncer task queue.

There are 2 possible actions. "save" and "delete". ... The "save" action has priority. eg: Only if "save tiddler" is OK a "delete draft tiddler" is allowed. Otherwise it is possible, to delete the draft, but save may have an error and we loose data.

If we want to delay 1 action, we basically have to delay them all, to avoid "race conditions". eg: Within 10 seconds it's possible "edit / save" a tiddler 20 times.

FlashSystems commented 3 years ago

Thank you for the pointer to syncer.js. Within the code I found the $:/config/SyncThrottleInterval configuration tiddler that does exactly what I wanted.

Now there is only one question left: This values is completely undocumented. Is there a reason for this? Is it safe to mess with it and change it from its default of 1 second to 5 or 10 seconds?

Jermolene commented 3 years ago

Hi @FlashSystems the $:/config/SyncThrottleInterval setting is currently undocumented, but it does indeed control the interval before a modified tiddler will be saved back to the server. Let us know how you get on with different settings for it.

FlashSystems commented 3 years ago

I tested my two TiddlyWiki installations with a SyncThrottleInterval of 5000 and 10000. Both intervals work perfectly. No issues so far. The synchronization status icon is correctly showing the current sync status. This allows me to make sure everything is synced before closing the browser window.

I think this feature works reliably enough to be mentioned in the docs. 👍

Thank you for your support.

Jermolene commented 3 years ago

Thanks @FlashSystems