One small step for JSON, one giant leap for Redkind #3771

Closed
Drapersniper wants to merge 4 commits from json-saves into V3/develop
Drapersniper commented 2020-04-19 16:10:42 +02:00 (Migrated from github.com)

Type

  • Bugfix
  • Enhancement
  • New feature

Description of the changes

Stop JSON driver from saving on change, and start saving periodically (1/s if there's been a change in the data)

### Type - [ ] Bugfix - [x] Enhancement - [ ] New feature ### Description of the changes Stop JSON driver from saving on change, and start saving periodically (1/s if there's been a change in the data)
tekulvw (Migrated from github.com) reviewed 2020-04-19 16:10:42 +02:00
mikeshardmind commented 2020-04-22 21:07:23 +02:00 (Migrated from github.com)

It's been explored before, and it's going to have all the same issues that were shown then.

  1. config no longer guarantees a data write when the function returns.

This particular part can actually be resolved with a pending write queue and asyncio condition waking all of those, thus putting the bottleneck on the write itself while still not returning any unwritten, but this will slow down any methods which write multiple config values

  1. data consistency issues

Application crashes can't be reliably caught. There's a BPO open for asyncio shutdown on windows specifically still, so we're delaying writes in a way which increases the window for data loss, or inconsistent data state. This would impact the bots that would benefit from this sort of change the most.

  1. Inconsistent config behavior between backends

Right now, if a config write returns, as long as the hard drive isn't dead, the data is on disk properly. If this change were to be added, this would have inconsistent meaning across backends. (on Postgres, a response from the server is enough to assume the data is stored resiliently)

If large bots are having performance issues, it may be time to really look into moving more of core to use SQLite (modlog is a good example of where this can be done without much complexity, but with a large gain for big bots), or a full SQLite driver (even if just used as a JSON store, the majority of the time is temp write, then replace + fsync for data resilience, this isn't needed with SQLite)

Exposing parts of this to config and to cog creators could work as well.

For example, adding an async context manager such as config_group.maybe_delay_writes() This has other complexities, but at least ensures that developers have control over where it is acceptable to delay or batch writes. Leaving it as a maybe means the actual behavior can be backend dependent, as there isn't always a need to delay, but if batching is a goal, then removing the maybe and having it act more like a transaction might be appropriate.

The large majority of bots aren't impacted by the issues with the JSON driver, only the largest ones which need an actual DB at this point are.

I think there are solutions that involve improving the backend options, as well as improving control over how writes are handled as developers but I don't think that this solution is better for the majority of bots than the current situation.

Edit: I forgot to mention, but also previously explored was splitting the files using a binning function. This worked to an extent, but could easily lead to an issue with too many file handles open on windows and osx, as well as with some configurations on linux, as well as taking longer for temp files to register as cleaned up by the operating system.

It's been explored before, and it's going to have all the same issues that were shown then. 1. config no longer guarantees a data write when the function returns. This particular part can actually be resolved with a pending write queue and asyncio condition waking all of those, thus putting the bottleneck on the write itself while still not returning any unwritten, but this will slow down any methods which write multiple config values 2. data consistency issues Application crashes can't be reliably caught. There's a [BPO](https://bugs.python.org/issue39232) open for asyncio shutdown on windows specifically still, so we're delaying writes in a way which increases the window for data loss, or inconsistent data state. This would impact the bots that would benefit from this sort of change the most. 3. Inconsistent config behavior between backends Right now, if a config write returns, as long as the hard drive isn't dead, the data is on disk properly. If this change were to be added, this would have inconsistent meaning across backends. (on Postgres, a response from the server is enough to assume the data is stored resiliently) If large bots are having performance issues, it may be time to really look into moving more of core to use SQLite (modlog is a good example of where this can be done without much complexity, but with a large gain for big bots), or a full SQLite driver (even if just used as a JSON store, the majority of the time is temp write, then replace + fsync for data resilience, this isn't needed with SQLite) Exposing parts of this to config and to cog creators could work as well. For example, adding an async context manager such as `config_group.maybe_delay_writes()` This has other complexities, but at least ensures that developers have control over where it is acceptable to delay or batch writes. Leaving it as a maybe means the actual behavior can be backend dependent, as there isn't always a need to delay, but if batching is a goal, then removing the maybe and having it act more like a transaction might be appropriate. The large majority of bots aren't impacted by the issues with the JSON driver, only the largest ones which need an actual DB at this point are. I think there are solutions that involve improving the backend options, as well as improving control over how writes are handled as developers but I don't think that this solution is better for the majority of bots than the current situation. Edit: I forgot to mention, but also previously explored was splitting the files using a binning function. This worked to an extent, but could easily lead to an issue with too many file handles open on windows and osx, as well as with some configurations on linux, as well as taking longer for temp files to register as cleaned up by the operating system.
Drapersniper commented 2020-06-26 13:05:18 +02:00 (Migrated from github.com)

Closing in favour of a better implementation.

Closing in favour of a better implementation.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!3771
No description provided.