Skip to content
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

Document some bad practices that should be avoided: Fixes #541 #558

Merged
merged 9 commits into from Oct 5, 2017

Conversation

ST-DDT
Copy link
Member

@ST-DDT ST-DDT commented Dec 19, 2016

Documents the following issues new developers might make.

@ST-DDT ST-DDT added the input wanted We would like to hear your opinion label Dec 19, 2016
@ST-DDT ST-DDT self-assigned this Dec 19, 2016
@Spongy
Copy link

Spongy commented Dec 19, 2016

@Mumfrey
Copy link
Member

Mumfrey commented Dec 19, 2016

Accessing game objects outside the main thread

This isn't "bad practice", it needs to be absolutely front and centre not tucked away in a bad practices section. It should be included as a fundamental point when discussing both the scheduler (it probably already is) and event listeners.

Copy link
Member

@Inscrutable Inscrutable left a comment

Choose a reason for hiding this comment

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

Quibbles. In addition, you may need to axe the last section on Game Objects.

Bad Practices
=============

These should practices should be avoided. As they lead to memory leaks (``OutOfMemoryError``), lags or inconsistencies.
Copy link
Member

Choose a reason for hiding this comment

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

Make this one sentence (...avoided, as ...).
They can lead to memory leaks - unless you're 100% certain they will?
Lag does not need to be a plural.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

* ``Collections``
* ``Maps``

should **NEVER** be stored or be cached in plugins.
Copy link
Member

Choose a reason for hiding this comment

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

The second be is redundant.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

* The references prevent proper garbage collection
* The instances might no longer be valid

This can easily be avoided by using the corresponding snapshots or saving the UUID of given the instances and request a
Copy link
Member

Choose a reason for hiding this comment

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

To keep tense consistent, use "requesting" instead of "request".

Copy link
Member Author

Choose a reason for hiding this comment

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

Done


Executing some IO operations such as loading a config/data file or checking for updates/connecting to a website takes
much time and greatly affects the TPS on the server. Such tasks should be either done in their own threads or using the
inbuilt scheduller's async feature.
Copy link
Member

Choose a reason for hiding this comment

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

Typo. It's scheduler

Copy link
Member Author

Choose a reason for hiding this comment

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

My most favorite mistake...Fixed.

~~~~~~~~~~~~~~~~~~~~~

Executing some IO operations such as loading a config/data file or checking for updates/connecting to a website takes
much time and greatly affects the TPS on the server. Such tasks should be either done in their own threads or using the
Copy link
Member

Choose a reason for hiding this comment

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

Move either ie. "Such tasks should be done either in their own thread or ..."
I'd also like to see a comma after "threads".

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@ST-DDT
Copy link
Member Author

ST-DDT commented Dec 20, 2016

@Inscrutable Thanks for reviewing all my PRs.

@ST-DDT
Copy link
Member Author

ST-DDT commented Dec 20, 2016

@Mumfrey I made the warning stronger and also added it to the scheduler docs.

Is this sufficient or shall I change it some more?

IMO its a good advice to have that warning in the best practise section as well or shall I remove it from there to reduce redundancies? (I recommend using async for lengthy tasks a few lines above so it might be useful to also outline the limitations there)

@stephan-gh stephan-gh changed the base branch from master to stable February 4, 2017 09:58
@MarkL4YG
Copy link
Contributor

MarkL4YG commented Feb 6, 2017

Reading the plugins config on a different thread?
I do think that's a bit overpowered since reading configs should be done after initialization and reloading during operation itself is already considered bad practice - The plugin should simply disallow it entirely or warn the administrator about that.
I also think there's no point in detaching from the main thread during initialization since the server shouldn't be operating while plugins (may) still initialize.

@Inscrutable Inscrutable added the needs review The submission is ready and needs to be reviewed label Jul 29, 2017
@Inscrutable
Copy link
Member

I'm hoping someone (else) can review this dusty PR so we can merge it or bury it.

@ST-DDT
Copy link
Member Author

ST-DDT commented Sep 23, 2017

@MarkL4YG I added a comment concerning the IO during the server startup. Do you consider this enough?
If yes, then I'm going to merge this.

@Inscrutable Objections?

@MarkL4YG
Copy link
Contributor

@ST-DDT Yes, I think that'll do.

Be aware that in the preview the page is still named "Best practices" while the subsection headline "Bad practices" is not really showy compared to the other titles.

@ST-DDT
Copy link
Member Author

ST-DDT commented Sep 23, 2017

Should I move it to its own page? Or is there a way to increase the increase the showiness?

@MarkL4YG
Copy link
Contributor

Maybe order it the way "Setting up your project" is ordered and call the page "Practices" or sth like that.

Copy link
Member

@Inscrutable Inscrutable left a comment

Choose a reason for hiding this comment

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

Mostly just more quibbles.

Bad Practices
=============

These should practices should be avoided, as they can lead to memory leaks (``OutOfMemoryError``), lag or
Copy link
Member

Choose a reason for hiding this comment

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

too many "should"s.


Executing some IO operations such as loading a config/data file or checking for updates/connecting to a website takes
much time and greatly affects the TPS on the server. Such tasks should be done either in their own threads, or using the
inbuilt scheduler's async feature. It is perfecty fine to load required files/config on the main thread during server
Copy link
Member

Choose a reason for hiding this comment

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

"perfectly". It might also be better to phrase this starting with "However, ", and omit the "though" at the end.


For more details refer to the :doc:`scheduler` docs.

If this is done wrong, you will see clients timing out or the server's watchdog might kill the server.
Copy link
Member

Choose a reason for hiding this comment

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

I suggest "If this is done incorrectly, you may see clients time out, or the watchdog may even kill the server."


Accessing game objects outside of the main thread can lead to crashes, inconsistencies and various other problems and
should be avoided. If you have a lengthy operation on a different thread use the :doc:`scheduler` to execute the apply
part on the main thread. If you want to use an game object in a different thread use a snapshot of the instance or a
Copy link
Member

Choose a reason for hiding this comment

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

"a game object"

Copy link
Contributor

Choose a reason for hiding this comment

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

"to execute the apply part" -> something like "to make changes to such game objects" (it's not clear what the "apply part" means here)

@ST-DDT
Copy link
Member Author

ST-DDT commented Sep 26, 2017

@Inscrutable @dualspiral @MarkL4YG Fixed and split into two pages for better overview.

Practices
=========

These section describes some best practices that should be followed and some bad practices that should be avoided.
Copy link
Member

Choose a reason for hiding this comment

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

"This section"

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@ST-DDT
Copy link
Member Author

ST-DDT commented Oct 4, 2017

More changes needed or is it good now?

@Inscrutable Inscrutable removed input wanted We would like to hear your opinion needs review The submission is ready and needs to be reviewed labels Oct 5, 2017
@Inscrutable Inscrutable merged commit 4313b03 into stable Oct 5, 2017
@ST-DDT ST-DDT deleted the BestPractises branch November 12, 2017 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants