-
Notifications
You must be signed in to change notification settings - Fork 277
Terminate AppServer when process is over soft memory cap #82
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,7 +63,8 @@ | |
| import tempfile | ||
| import yaml | ||
|
|
||
|
|
||
| #AppScale | ||
| import resource | ||
|
|
||
|
|
||
|
|
||
|
|
@@ -185,7 +186,6 @@ | |
| MAX_URL_LENGTH = 2047 | ||
|
|
||
|
|
||
|
|
||
| DEFAULT_ENV = { | ||
| 'GATEWAY_INTERFACE': 'CGI/1.1', | ||
| 'AUTH_DOMAIN': 'gmail.com', | ||
|
|
@@ -232,6 +232,16 @@ | |
| DEVEL_FAKE_IS_ADMIN_HEADER = 'HTTP_X_APPENGINE_FAKE_IS_ADMIN' | ||
| DEVEL_FAKE_IS_ADMIN_RAW_HEADER = 'X-AppEngine-Fake-Is-Admin' | ||
|
|
||
| #AppScale | ||
| # Soft cap on memory. If over dev_appserver will stop serving traffic and | ||
| # shut down. It will randomly choose to exit based on MAX_RANDOM_TARGET, | ||
| # hence the reason it is soft and not hard . Units are in KBs. | ||
| SOFT_CAP_MEM = 150000 | ||
|
|
||
| # Max number for randomly killing the dev_appserver when over the soft | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this comment. Should this instead be something like "The probability that we should terminate an AppServer that has exceeded its memory limit"?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed. |
||
| # memory cap. | ||
| MAX_RANDOM_TARGET = 25 | ||
|
|
||
| class Error(Exception): | ||
| """Base-class for exceptions in this module.""" | ||
|
|
||
|
|
@@ -3634,6 +3644,19 @@ def serve_forever(self): | |
| """Handle one request at a time until told to stop.""" | ||
| while not self._stopped: | ||
| self.handle_request() | ||
|
|
||
| # AppScale | ||
| # If this process is using too much memory kill it randomly | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making each component monitor their own memory usage seems unnecessary when we have a process monitoring system (god) already. Furthermore, you rely on god to revive this AppServer after its failed, so it seems as though the proper fix is to just write a god config file with memory thresholds set in it and leave it to god. Additionally, since god is built for this (and not our AppServer), it has termination conditions that are a lot smarter than this. The condition here is "kill this AppServer if it exceeds X memory one time, depending on a coin flip", which makes a lot less sense than what god would do, "kill this AppServer if it exceeds X memory 3/5 times in a row".
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noted. This will be addressed with the other task of fixing god. |
||
| if resource.getrusage(resource.RUSAGE_SELF).ru_maxrss > SOFT_CAP_MEM: | ||
| # Stagger the killing so all processes do not go down at the same | ||
| # time. The lower the MAX_RANDOM_TARGET the higher probability it | ||
| # will shut down when over the soft memory cap. | ||
| rand = random.randint(0,MAX_RANDOM_TARGET) | ||
| if rand == 0: | ||
| logging.error("Usage of memory exceeded soft cap of " + \ | ||
| str(SOFT_CAP_MEM) + ". Exiting.") | ||
| break | ||
|
|
||
| self.server_close() | ||
|
|
||
| def stop_serving_forever(self): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the "AppScale" tag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you know where we made the changes