<commit_before>"""
This is where the work is done. 
"""

import config
import notify
from log import Log
from messageQueue import Queue

import json
import requests
import time


class Microscaler:
    containers = [
        {
            "id": "/microscaling/analyzer",
            "name": "analyzer-microscaling.marathon.slave.mesos"
        },
        {
            "id": "/microscaling/batch",
            "name": "batch-microscaling.marathon.slave.mesos"
        }
    ]

    cool_off_period = 10 # time to wait between scale requests
    last_scale_up_time = time.time()
    last_scale_down_time = time.time()
    scale_factor = 5

    def __init__(self):
        self.log = Log()
        self.msgQueue = Queue(account_name = config.AZURE_STORAGE_ACCOUNT_NAME, account_key=config.AZURE_STORAGE_ACCOUNT_KEY, queue_name=config.AZURE_STORAGE_QUEUE_NAME)

    def scaleUp(self, container):
        """Scale health indicates that we need to scale up, calculate the new
        number of instances and issue the scale request."""

        self.last_scale_up_time = time.time()
    
        # Get current instance count
        url = "http://leader.mesos:8080/v2/apps" + container["id"]
        resp = requests.get(url)
        app_data = json.loads(resp.text)
        instances = app_data["app"]["instances"]
    
        # Increment count
        length = self.msgQueue.getLength()
        new_instances = instances + 1 + int(length / 10)

        self.scale(container["id"], new_instances)
<commit_msg>we only want to scale batch up by a single instance at a time<commit_after>"""
This is where the work is done. 
"""

import config
import notify
from log import Log
from messageQueue import Queue

import json
import requests
import time


class Microscaler:
    containers = [
        {
            "id": "/microscaling/analyzer",
            "name": "analyzer-microscaling.marathon.slave.mesos"
        },
        {
            "id": "/microscaling/batch",
            "name": "batch-microscaling.marathon.slave.mesos"
        }
    ]

    cool_off_period = 10 # time to wait between scale requests
    last_scale_up_time = time.time()
    last_scale_down_time = time.time()
    scale_factor = 5

    def __init__(self):
        self.log = Log()
        self.msgQueue = Queue(account_name = config.AZURE_STORAGE_ACCOUNT_NAME, account_key=config.AZURE_STORAGE_ACCOUNT_KEY, queue_name=config.AZURE_STORAGE_QUEUE_NAME)

    def scaleUp(self, container):
        """Scale health indicates that we need to scale up, calculate the new
        number of instances and issue the scale request."""

        self.last_scale_up_time = time.time()
    
        # Get current instance count
        url = "http://leader.mesos:8080/v2/apps" + container["id"]
        resp = requests.get(url)
        app_data = json.loads(resp.text)
        instances = app_data["app"]["instances"]
    
        # Increment count
        if container["id"] == "/microscaling/analyzer":
            length = self.msgQueue.getLength()
            new_instances = instances + 1 + int(length / 10)
        else:
            new_instances = instances + 1

        self.scale(container["id"], new_instances)

{'fraction_non_alphanumeric': 0.10138539042821158, 'fraction_numerical': 0.007241813602015114, 'mean_word_length': 2.5457589285714284, 'pattern_counts': {'":': 9, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6505643', 'n_tokens_mistral': 992, 'n_tokens_neox': 944, 'n_words': 238}