Coder Social home page Coder Social logo

ruby_persistence's Introduction

This repository allows you to spawn a ruby application server and gives you a view on how global variables and constants are handled.

Depending on the server you are running and the spawning mode of the server (thread based like in puma or process-based as in thin) the variables might be shared.
This leads to problems when you are mutating shared variables or are trying to do sequential work and eventually run into locking problems.

Keep in mind that class variables and class instance variables should exactly behave like global variables in terms of sharing.

RUN
===

The server starts and sets a $config and MY_CONFIG var.

Both are then read later ... the $config var is incremented.

When you open another connection to the sever, all data is displayed again and you can check if the information has been retained or resetted.

FINDINGS
========

- Although thin is said to be single-threaded the mutated values of $config are retained `rackup sinatra.ru -s thin`
- Puma as a multi-threaded server behaves as expected and the mutated values of $config are retained `rackup sinatra.ru -s puma`
- It does not matter whether a sinatra app is used `rackup sinatra.ru -s thin` or a plain lambda `rackup plain.ru -s thin`

LESSON
======
Never mutate global variables or constants once the application server is started

QUESTION
========

If you ever need changing configuration available between requests that CHANGE between requests: Use dependency injection with instance vars

REFERENCES
=========

A good sum up of puma vs. thin is given here: https://www.quora.com/Ruby-programming-language-How-does-puma-compare-to-thin#!n=12

ruby_persistence's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.