Swiftpack.co - Package - lluuaapp/vapor-memory-leak

About this repo

Our Vapor 3 app is leaking memory like crazy when deployed. We tweeted about this, and a few people offered to look into our problem.

So we extracted a two sample request handlers into this demo Vapor app and bundled it with a Ruby script to easily trigger memory leaks.

Higher Memory.

As shown on the screenshot above, each time the run_test.rb script is run, a few MBs are leaking. We tested this with Debug and Release configurations.

Our suspicion is that something with the Thread management in SwiftNIO or Vapor is off, but we aren't quite sure.

Higher Memory.

Getting this demo project to run


You will need Vapor 3 and MySQL locally installed on your Mac.

Create Test Database

Copy these commands into the mysql command line tool:

CREATE USER 'vapor'@'localhost' IDENTIFIED BY  'password';
CREATE DATABASE IF NOT EXISTS  `vapor-memory-test`;
GRANT ALL PRIVILEGES ON  `vapor-memory-test` . * TO  'vapor'@'localhost';

Install Ruby Gems

sudo gem install mysql2
sudo gem install httpclient

Running the Vapor app

Generate and Run Xcode project

Generate an Xcode project from the sources by entering this line into the Terminal:

vapor xcode -y

Build and run the Vapor app once in Xcode.

Running the Tests

Reset database and initialise it with test data


Run the tests once or multiple times

# or 10 times
for ((i=1;i<=10;i++)); do ./Scripts/run_test.rb; done
# 10 multithreaded
for ((i=1;i<=10;i++)); do ./Scripts/run_test.rb & ; done; wait

Watch the memory consumption grow each time the script is run.


Stars: 3

Used By

Total: 0