Skip to content

Instantly share code, notes, and snippets.

View NickDiMucci's full-sized avatar

Nicholas DiMucci NickDiMucci

View GitHub Profile

My largest Sidekiq application had a memory leak and I was able to find and fix it in just few hours spent on analyzing Ruby's heap. In this post I'll show my profiling setup.

As you might know Ruby 2.1 introduced a few great changes to ObjectSpace, so now it's much easier to find a line of code that is allocating too many objects. Here is great post explaining how it's working.

I was too lazy to set up some seeding and run it locally, so I checked that test suite passes when profiling is enabled and pushed debugging to production. Production environment also suited me better since my jobs data can't be fully random generated.

So, in order to profile your worker, add this to your Sidekiq configuration:

if ENV["PROFILE"]
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import pandas as p
# Data source https://www.kaggle.com/lazyjustin/pubgplayerstats/data
colnames = ['player_name','tracker_id','solo_KillDeathRatio','solo_WinRatio','solo_TimeSurvived','solo_RoundsPlayed','solo_Wins','solo_WinTop10Ratio','solo_Top10s','solo_Top10Ratio','solo_Losses','solo_Rating','solo_BestRating','solo_DamagePg','solo_HeadshotKillsPg','solo_HealsPg','solo_KillsPg','solo_MoveDistancePg','solo_RevivesPg','solo_RoadKillsPg','solo_TeamKillsPg','solo_TimeSurvivedPg','solo_Top10sPg','solo_Kills','solo_Assists','solo_Suicides','solo_TeamKills','solo_HeadshotKills','solo_HeadshotKillRatio','solo_VehicleDestroys','solo_RoadKills','solo_DailyKills','solo_WeeklyKills','solo_RoundMostKills','solo_MaxKillStreaks','solo_WeaponAcquired','solo_Days','solo_LongestTimeSurvived','solo_MostSurvivalTime','solo_AvgSurvivalTime','solo_WinPoints','solo_WalkDistance','solo_RideDistance','solo_MoveDistance','solo_AvgWalkDistance','solo_AvgRid
@NickDiMucci
NickDiMucci / PlayerMovementDwS.cs
Created March 2, 2018 14:40
The player movement and collision detection code for Demons with Shotguns.
namespace com.mindshaft.overtime.controller {
public class BasicEntityController : IEntityController {
private float gravity = 40f;
private float targetSpeed = 0f;
private IMovementModel model;
[Inject]
public IEntityCollisionDetection CollisionDetection { get; set; }
@NickDiMucci
NickDiMucci / minMaxPos
Created May 1, 2015 23:42
Pseudo-code for obtaining the minimum and maximum positions of objects in a 2D space.
List xPositions;
List yPositions;
foreach target {
xPositions.Add(target.x);
yPositions.Add(target.y);
}
maxX = Max(xPositions);
maxY = Max(yPositions);
minX = Min(xPositions);
minY = Min(yPositions);
@NickDiMucci
NickDiMucci / BitmapToTexture2D.cs
Last active June 18, 2017 09:01
Get a Texture2D from a Bitmap image.
public static Texture2D BitmapToTexture2D(GraphicsDevice GraphicsDevice, System.Drawing.Bitmap image)
{
// Buffer size is size of color array multiplied by 4 because
// each pixel has four color bytes
int bufferSize = image.Height * image.Width * 4;
// Create new memory stream and save image to stream so
// we don't have to save and read file
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(bufferSize);
image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
@NickDiMucci
NickDiMucci / RaycastCollisionDetection.cs
Created November 18, 2014 01:15
Raycast collision detection in Unity from a box collider, with diagonal raycasts from the corners to guard against corner collisions.
using com.mindshaft.overtime.collision;
using UnityEngine;
namespace com.mindshaft.overtime.physics {
public class RaycastCollisionDetection : IEntityCollisionDetection {
private BoxCollider _collider;
private Rect _collisionRect;
private LayerMask _collisionMask;
private LayerMask _playerMask;
using strange.extensions.mediation.impl;
[Mediates(typeof($VIEW$))]
public class $MEDIATOR$ : Mediator
{
[Inject]
public $VIEW$ view { get; set; }
public override void OnRegister()
{
@NickDiMucci
NickDiMucci / 107
Created October 19, 2014 14:06
Resource script 107 to hide input tab from Unity standalone player. To be used with ResourceHacker.
107 DIALOGEX 0, 0, 290, 56
STYLE DS_FIXEDSYS | DS_MODALFRAME | DS_CONTROL | WS_CHILD | WS_SYSMENU
CAPTION ""
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
FONT 8, "MS Shell Dlg", FW_NORMAL, FALSE, 1
{
CONTROL "Screen resolution", -1, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 7, 9, 56, 8
CONTROL "", 1010, COMBOBOX, CBS_DROPDOWNLIST | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP, 73, 7, 84, 90
CONTROL "Windowed", 1009, BUTTON, BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 169, 7, 49, 10
CONTROL "Graphics quality", -1, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 7, 26, 52, 8
@NickDiMucci
NickDiMucci / 9
Created October 19, 2014 14:04
Resource 9 script to hide input tab from Unity standalone player. To be used with Resource Hacker.
9 DIALOGEX 0, 0, 309, 200
STYLE DS_FIXEDSYS | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "ScreenSel"
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
FONT 8, "MS Shell Dlg", FW_NORMAL, FALSE, 1
{
CONTROL "Play!", 1, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 193, 178, 50, 14
CONTROL "Quit", 2, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 252, 178, 50, 14
CONTROL "", -1, BUTTON, BS_GROUPBOX | WS_CHILD | WS_VISIBLE, 7, 3, 295, 108
CONTROL "", 1001, STATIC, SS_BITMAP | SS_CENTERIMAGE | WS_CHILD | WS_VISIBLE, 9, 9, 291, 100
@NickDiMucci
NickDiMucci / unityBuildWindows.bat
Created August 25, 2014 14:30
Script to automate build the Windows player of a Unity project, and committing build to a git repo.
@echo off
set PROJECT=-projectPath
set PROJECT_PATH="C:\path\to\your\Unity\project"
set WIN_PATH="C:\path\to\your\game.exe"
@REM Common options
set BATCH=-batchmode
set QUIT=-quit