Skip to content

Queue async operations on a per-player basis [WIP] #2005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 44 commits into from

Conversation

sgdc3
Copy link
Member

@sgdc3 sgdc3 commented Feb 3, 2020

No description provided.

@sgdc3
Copy link
Member Author

sgdc3 commented Feb 3, 2020

Depends on #1992

Copy link
Member

@TuxCoding TuxCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of understand what you are doing here. You are trying to perform asynchronous tasks sequential on per player basis. I guess with the goal to reduce conflicts between them? Do you also thought about locks? This allows more flexibility like read/write differentiation, protecting only thread-unsafe operations meanwhile other parts could execute in concurrently and in parallel.

}

public void submit(K key, Runnable runnable) {
executors.computeIfAbsent(key, k -> new SequentialExecutor(scheduler, () -> executors.remove(key)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential memory leak

}

public void submit(Runnable task) {
queue.add(task);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem thread-safe. Considering two calls to the submit method. Then both tasks will be added, but scheduler.apply() will be invoked twice with two new tasks on the Bukkit scheduler resulting to two new threads.

T1 and T2 are the threads:
T1: 1 iteration of the while loop
-- 1 task remaining
T1: evaluate while(!queue.isEmpty()) -> true - enter while loop
T2: 1 iteration of the while loop
-- queue.poll wasn't executed yet by T1 and so queue is still not empty
-- T2 now removes the last task
T1: queue.poll() - NoSuchElementExeception

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I see, which pattern should we use instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The easiest solution would be to lock on the queue on isEmpty + poll operations.

@sgdc3
Copy link
Member Author

sgdc3 commented Feb 4, 2020

@games647 I think that both read/write operations needs to be sequential, I can't think about any situation where locks might be better. Can you make some examples?

dependabot-preview bot and others added 25 commits February 8, 2020 17:17
Bumps [postgresql](https://github.com/pgjdbc/pgjdbc) from 42.2.9 to 42.2.10.
- [Release notes](https://github.com/pgjdbc/pgjdbc/releases)
- [Changelog](https://github.com/pgjdbc/pgjdbc/blob/master/CHANGELOG.md)
- [Commits](pgjdbc/pgjdbc@REL42.2.9...REL42.2.10)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
* #1448 Create AuthMePlayer to get player data from API with

* #1448 Add tests for new API method & AuthMePlayer

* #1448 Create AuthMePlayer to get player data from API with
- Use Optional for all values that may be null

* #1448 Add comment that AuthMePlayer data does not update itself
Addresses #2014
Bumps [mockito-core](https://github.com/mockito/mockito) from 3.2.4 to 3.3.0.
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](mockito/mockito@v3.2.4...v3.3.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Bumps [maven-site-plugin](https://github.com/apache/maven-site-plugin) from 3.8.2 to 3.9.0.
- [Release notes](https://github.com/apache/maven-site-plugin/releases)
- [Commits](apache/maven-site-plugin@maven-site-plugin-3.8.2...maven-site-plugin-3.9.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Bumps [postgresql](https://github.com/pgjdbc/pgjdbc) from 42.2.10 to 42.2.11.
- [Release notes](https://github.com/pgjdbc/pgjdbc/releases)
- [Changelog](https://github.com/pgjdbc/pgjdbc/blob/master/CHANGELOG.md)
- [Commits](pgjdbc/pgjdbc@REL42.2.10...REL42.2.11)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Updated Turkish Lang
- "allowMissingThrowsTags" does nothing anymore, cf. checkstyle/checkstyle#7329
Bumps [googleauth](https://github.com/wstrange/GoogleAuth) from 1.4.0 to 1.5.0.
- [Release notes](https://github.com/wstrange/GoogleAuth/releases)
- [Changelog](https://github.com/wstrange/GoogleAuth/blob/master/NEWS)
- [Commits](wstrange/GoogleAuth@1.4.0...1.5.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Bumps [checker-qual](https://github.com/typetools/checker-framework) from 3.2.0 to 3.3.0.
- [Release notes](https://github.com/typetools/checker-framework/releases)
- [Changelog](https://github.com/typetools/checker-framework/blob/master/changelog.txt)
- [Commits](typetools/checker-framework@checker-framework-3.2.0...checker-framework-3.3.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.1.1 to 3.2.0.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](apache/maven-javadoc-plugin@maven-javadoc-plugin-3.1.1...maven-javadoc-plugin-3.2.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Bumps [mockito-core](https://github.com/mockito/mockito) from 3.3.0 to 3.3.3.
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](mockito/mockito@v3.3.0...v3.3.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Bumps [postgresql](https://github.com/pgjdbc/pgjdbc) from 42.2.11 to 42.2.12.
- [Release notes](https://github.com/pgjdbc/pgjdbc/releases)
- [Changelog](https://github.com/pgjdbc/pgjdbc/blob/master/CHANGELOG.md)
- [Commits](pgjdbc/pgjdbc@REL42.2.11...REL42.2.12)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.2.2 to 3.2.3.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](apache/maven-shade-plugin@maven-shade-plugin-3.2.2...maven-shade-plugin-3.2.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Bumps [argon2-jvm-nolibs](https://github.com/phxql/argon2-jvm) from 2.6 to 2.7.
- [Release notes](https://github.com/phxql/argon2-jvm/releases)
- [Changelog](https://github.com/phxql/argon2-jvm/blob/master/CHANGELOG.md)
- [Commits](phxql/argon2-jvm@v2.6...v2.7)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
* Update messages_ru.yml

* Update messages_ru.yml
ljacqu and others added 17 commits May 2, 2020 13:08
Bumps [HikariCP](https://github.com/brettwooldridge/HikariCP) from 3.4.2 to 3.4.4.
- [Release notes](https://github.com/brettwooldridge/HikariCP/releases)
- [Changelog](https://github.com/brettwooldridge/HikariCP/blob/dev/CHANGES)
- [Commits](brettwooldridge/HikariCP@HikariCP-3.4.2...HikariCP-3.4.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Bumps [sqlite-jdbc](https://github.com/xerial/sqlite-jdbc) from 3.30.1 to 3.31.1.
- [Release notes](https://github.com/xerial/sqlite-jdbc/releases)
- [Changelog](https://github.com/xerial/sqlite-jdbc/blob/master/CHANGELOG)
- [Commits](xerial/sqlite-jdbc@3.30.1...3.31.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Bumps [checker-qual](https://github.com/typetools/checker-framework) from 3.3.0 to 3.4.0.
- [Release notes](https://github.com/typetools/checker-framework/releases)
- [Changelog](https://github.com/typetools/checker-framework/blob/master/changelog.txt)
- [Commits](typetools/checker-framework@checker-framework-3.3.0...checker-framework-3.4.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Bumps [HikariCP](https://github.com/brettwooldridge/HikariCP) from 3.4.4 to 3.4.5.
- [Release notes](https://github.com/brettwooldridge/HikariCP/releases)
- [Changelog](https://github.com/brettwooldridge/HikariCP/blob/dev/CHANGES)
- [Commits](brettwooldridge/HikariCP@HikariCP-3.4.4...HikariCP-3.4.5)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Bumps [api](https://github.com/lucko/LuckPerms) from 5.0 to 5.1.
- [Release notes](https://github.com/lucko/LuckPerms/releases)
- [Commits](LuckPerms/LuckPerms@v5.0...v5.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
* Update messages_br.yml

* Update messages_br.yml
Should fix issues due to old Email API usages
Bumps [checker-qual](https://github.com/typetools/checker-framework) from 3.4.0 to 3.4.1.
- [Release notes](https://github.com/typetools/checker-framework/releases)
- [Changelog](https://github.com/typetools/checker-framework/blob/master/changelog.txt)
- [Commits](typetools/checker-framework@checker-framework-3.4.0...checker-framework-3.4.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.2.3 to 3.2.4.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](apache/maven-shade-plugin@maven-shade-plugin-3.2.3...maven-shade-plugin-3.2.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Bumps [postgresql](https://github.com/pgjdbc/pgjdbc) from 42.2.12 to 42.2.14.
- [Release notes](https://github.com/pgjdbc/pgjdbc/releases)
- [Changelog](https://github.com/pgjdbc/pgjdbc/blob/master/CHANGELOG.md)
- [Commits](pgjdbc/pgjdbc@REL42.2.12...REL42.2.14)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Bumps [sqlite-jdbc](https://github.com/xerial/sqlite-jdbc) from 3.31.1 to 3.32.3.
- [Release notes](https://github.com/xerial/sqlite-jdbc/releases)
- [Changelog](https://github.com/xerial/sqlite-jdbc/blob/master/CHANGELOG)
- [Commits](xerial/sqlite-jdbc@3.31.1...3.32.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Bumps [maven-site-plugin](https://github.com/apache/maven-site-plugin) from 3.9.0 to 3.9.1.
- [Release notes](https://github.com/apache/maven-site-plugin/releases)
- [Commits](apache/maven-site-plugin@maven-site-plugin-3.9.0...maven-site-plugin-3.9.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
sgdc3 added a commit that referenced this pull request Nov 22, 2020
@sgdc3 sgdc3 closed this Nov 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

10 participants