Skip to content

Instantly share code, notes, and snippets.

@jamiegs
jamiegs / gist:5391961
Created April 15, 2013 22:53
A java implementation of c#'s IsNullOrWhitespace
public static boolean isNullOrWhitespace(String s) {
if (s == null)
return true;
for (int i = 0; i < s.length(); i++) {
if (!Character.isWhitespace(s.charAt(i))) {
return false;
}
}
return true;
}
@jamiegs
jamiegs / gist:5408193
Created April 17, 2013 22:13
Nancy Tests
/// <summary>
/// Tests that a 200 is returned when visiting a page that doesn't exist.
/// </summary>
[TestMethod]
public void ReturnsOkStatusCodeWhenExists()
{
var bs = new TestBootStrapper();
var browser = new Browser(bs);
var result = browser.Get("/users/", with => with.HttpRequest());
@jamiegs
jamiegs / gist:5438871
Created April 22, 2013 21:52
Error from mongos
At the same time it failed there was a message in the mongos log.
2013-04-22 21:00:08,833 ip-0A2057A3 [WARN ] [Hudl.Config.ClusterConfigFileUtility] Timed out acquiring the configuration lock for key logger.Enyim.Caching.Memcached.PooledSocket during a GetConfiguration() call
--Mongos Host Error--
Hudl mongos service failed during startup:
Type = System.NullReferenceException
@jamiegs
jamiegs / gist:5446675
Created April 23, 2013 19:32
Out of memory exception
2013-04-23 19:08:46,965 ip-0A6EE738 [FATAL] [QueueServices] [request_id=NULL] Unhandled exception
Type=System.OutOfMemoryException
Message=Exception of type 'System.OutOfMemoryException' was thrown.
Data:
Signature=6ec8ce22
Stack Trace:
at System.Runtime.Remoting.Messaging.Message.GenerateMethodSignature(MethodBase mb)
at System.Runtime.Remoting.Messaging.Message.get_MethodSignature()
at System.Runtime.Remoting.Messaging.MCMDictionary.GetMessageValue(Int32 i)
at System.Runtime.Remoting.Messaging.MessageDictionaryEnumerator.get_Value()
@jamiegs
jamiegs / gist:6615746
Last active December 23, 2015 09:39
Disable Mongo Chaining
cfg = rs.config()
cfg.settings = { }
cfg.settings.chainingAllowed = false
rs.reconfig(cfg)
@jamiegs
jamiegs / SumoFlowLog.py
Last active October 28, 2015 17:28
VPC to Sumologic Lambda Function
__author__ = 'Jesse'
import urllib2
import base64
import zlib
import json
import StringIO
import gzip
def lambda_handler(event, context):
data = event.get('awslogs').get('data')
@jamiegs
jamiegs / BundleConfig.ps1
Created July 1, 2016 19:16 — forked from mefellows/BundleConfig.ps1
Sysprepped Windows AMI using Packer
$EC2SettingsFile="C:\\Program Files\\Amazon\\Ec2ConfigService\\Settings\\BundleConfig.xml"
$xml = [xml](get-content $EC2SettingsFile)
$xmlElement = $xml.get_DocumentElement()
foreach ($element in $xmlElement.Property)
{
if ($element.Name -eq "AutoSysprep")
{
$element.Value="Yes"
}
@jamiegs
jamiegs / adaptive-ecs-scaling.md
Last active November 5, 2019 00:17
Description of ECS scaling solution developed for Hudl.

Adaptive Container Scaling

Problems with AWS's recommended scaling method

  • Based on a fixed percentage of memory and CPU reservation.
  • Scaling on both cpu and memory metrics can cause the metrics to fight with each other where it'll scale out then back in and repeat.
  • If you're scaling threshold is at 80% memory, current reservation utilization is at 79% and you deploy a container that requires 25% memory, It will fail to launch.
  • ASGs are not container aware.

Solution

@jamiegs
jamiegs / Warmup-Healthecks.md
Last active December 7, 2021 02:56
Warm up and health checks.md

Backgound

Previously our warmup and health checks were too coupled. Our load balancers make an http call to /healthcheck on a regular interval. This is to see if it should send traffic to the application or not. It will also kill the container if it's unhealthy after so long.

This was a problem because say mongo is down for an extended time it would take down the entire microservice. The microservice would continously try to launch containers, which would then fail healthchecks during warmup, and get killed again.

Most the application might still be in a good state though but because one dependancy is down, the whole thing is down.

So, we're splitting them out into multiple health checks.

@jamiegs
jamiegs / map-w3wp-to-webapp.ps1
Created December 8, 2023 00:55
Maps the w3p#n to the name of the app pool.
$count = (Get-Process | Where-Object { $_.Name -eq 'w3wp' }).count -1
$var = 1
$result = ''
$id = (Get-Counter "\Process(w3wp)\ID Process").CounterSamples.CookedValue
$app = [regex]::match((Get-CimInstance Win32_Process -Filter "ProcessId = $id").CommandLine, '"([^"]+)"').Groups[1].Value
$result += "w3wp = $id, $app`n"
while ($var -le $count) {
$id = (Get-Counter "\Process(w3wp#$var)\ID Process").CounterSamples.CookedValue