0
votes

I made a discord bot I'm trying to host on appengine, it runs well however when left idly for more than 30 minutes, appengine shuts the instance down due to -what i believe the issue is- automatic scaling in which app engine shuts down instances that are inactive in traffic to cut costs. According to the java docs, you need to set your app's appengine-web.xml file in target/project-1.0/WEB-INF/appengine-web.xml to manual-scaling which also controls the amount of instances that instantiate. But this doesn't seem to have fixed the issue. I'm barely using any traffic and I checked my instance's statistics, its simply shutting down due to inactivity.

The way I detach from my console is running my java app via java -jar project-1.0.jar &. The & detaches and makes it run by itself (which is the case).

30 minutes after activating the app and closing the console, the app shuts down as a result of automatic-scaling.

this is my appengine-web.xml:

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
    <application>wizardry-discord-bot</application><!-- unused for Cloud SDK based tooling -->
    <version>1</version><!-- unused for Cloud SDK based tooling -->
    <threadsafe>true</threadsafe>
    <runtime>java8</runtime>
  <manual-scaling>
    <instances>1</instances>
  </manual-scaling>
</appengine-web-app>

Since this didn't work, The docs were unclear so I added this as well to my app.yaml in src/main/appengine/app.yaml as did many samples I've read. Again, docs unclear but they said I can specify manual-scaling here as well. I'm lost at this point as to what is what and which is where.

enter image description here

# [START_EXCLUDE]
# Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# [END_EXCLUDE]

# [START runtime]
runtime: custom
env: flex

handlers:
- url: /.*
  script: this field is required, but ignored

runtime_config:  # Optional
  jdk: openjdk8
  server: jetty9

manual_scaling:
  instances: 1
# [END runtime]

So am i doing something wrong here? I'm new to google cloud in general. Kind of lost.

EDIT: Further more: The docs say to run mvn appengine:deploy to actually run your code instead of compiling and java -jar'ing it. https://cloud.google.com/java/getting-started/hello-world However, when I do run the command: https://hastebin.com/magizutuho.sql

1
You seem to be mixing up standard and flex env configs. And the error suggests you flex deployment might have not worked. So check in the developer console what exactly is your app running and the actual scaling parameters on the App Engine -> Versions page. - Dan Cornilescu
@DanCornilescu The Versions page says I'm on Standard. EDIT: Would like to add that I want Standard. - Cheese
How about the scaling parameters? (may need to adjust column visibility). You can also see the actual config being presently deployed. - Dan Cornilescu
Since you want standard env you can ignore the 2nd config as well as the hello world guide and the deployment error - they don't apply. Please note that most (but not all) documentation is structured around the environment it applies to. - Dan Cornilescu
@DanCornilescu Scaling parameters have already been defined in appengine-web.xml. <manual-scaling>. I'm following the docs but I'm experiencing issues. For example, doc says: hastebin.com/wekedesuci.pas but i thought i was supposed to specify it in target/... And even then (did on both) i get this error: hastebin.com/emogekagoz.sql I'm just lost... I'm manually git pulling on appengine, packaging there, then java -jaring there. Idk what to do at this point... - Cheese

1 Answers

0
votes

To keep one instance always alive you can apply this in your app.yaml file:

automatic_scaling:
   min_instances: 1
   max_instances: 1

However, I'm wondering if that might be a problem with the Discord library. I'm using the one for node.js and from time to time the client disconnects without trying to reconnect.

A workaround I'm using is to ping the bot (HTTP GET request in my case) every 30 minutes, destroy the client and login again. The drawback is a downtime of a few seconds, but that's totally fine for my use case.