Skip to content

Instantly share code, notes, and snippets.

View FooBarWidget's full-sized avatar

Hongli Lai FooBarWidget

View GitHub Profile

Resource control features allow you limit resource usage and to keep misbehaving applications in line.

If you run several applications on your server, but one application is more important than the other, would it not be great if you can give the most important one more resources? Or if your application or one of its libraries contain bugs that could cause it go to on a rampage, would it not be great if they can be kept in line until you've fixed the problem?

Phusion Passenger Enterprise allows you to limit the maximum number of processes, limit the memory usage and limit the maximum request time on a per-application basis or even per-URL basis. Sleep more and worry less with Phusion Passenger Enterprise.

Deployment error resistance helps preventing visitors from experiencing problems in case your deployments fail.

We all make mistakes. A new application version could contain a bug that prevents it from starting. An error message in the browser could scare away visitors. Would it not be great if visitors can be shielded from this problem?

Enter deployment error resistance. Use it in combination with rolling restarts. If your app fails to start, Phusion Passenger Enterprise will log the problem, redirect the request to an existing process, flag your application so that no existing processes are shutdown and no new processes are spawned. You can perform emergency fixing while your visitors continue to get served.

Now you can sleep more and worry less, with Phusion Passenger Enterprise.

Our live IRB and debugging console provide easy ways to introspect, to debug and to modify your application during runtime.

Ever wondered what your application is doing? Maybe the state is not obvious from the log files or the status screens, and you want to inspect the program state directly. Phusion Passenger Enterprise can help you, so let's see how it works.

So here you have a hello world application, which just prints a message with a counter value. On every request, the counter is increment by 1. And here you see it in action.

We use the passenger-status tool to find the PID our application, which we then pass to the passenger-irb command. And there we go. Let's introspect and change the value of the $processed global variable. And it works, it's this simple.

$ crash-watch --dump 5120
Current thread (1) backtrace:
#0 0x00007fff89d2de42 in __semwait_signal ()
No symbol table info available.
#1 0x00007fff8329fdea in nanosleep ()
No symbol table info available.
#2 0x00007fff8329fbb5 in usleep ()
No symbol table info available.
#3 0x00000001001d889a in freeze_process (self=2307) at passenger_native_support.c:468
No locals.
app = proc do |env|
# This is a Ruby C extension method that we've written to simulate a freeze.
# It sleeps indefinitely, and unlike Kernel#sleep it does not unlock the Ruby
# 1.9 interpreter's GIL, so it really freezes everything.
PhusionPassenger::NativeSupport.freeze_process
[200,
{ "Content-Type" => "text/html" },
["hello world\n"]
]
diff --git a/ext/common/ApplicationPool2/Pool.h b/ext/common/ApplicationPool2/Pool.h
index e5cd3a8..82ca754 100644
--- a/ext/common/ApplicationPool2/Pool.h
+++ b/ext/common/ApplicationPool2/Pool.h
@@ -482,6 +482,14 @@ public:
typedef shared_ptr<ProcessAnalyticsLogEntry> ProcessAnalyticsLogEntryPtr;
void collectAnalytics(ev::timer &timer, int revents) {
+ try {
+ realCollectAnalytics(timer);
  • Use 4-space tabs for indentation.

  • Wrap at approximately 80 characters. This is a recommendation, not a hard guideline. You can exceed it if you think it makes things more readable, but try to minimize it.

  • Use camelCasing for function names, variables, class/struct members and parameters:

     void frobnicate();
     void deleteFile(const char *filename, bool syncHardDisk);
     int fooBar;
    
@FooBarWidget
FooBarWidget / gist:4133511
Created November 23, 2012 01:00
Ruby deployment overview, 2010

(Originally from http://stackoverflow.com/questions/4113299/ruby-on-rails-server-options/4113570#4113570)

The word "deployment" can have two meanings depending on the context. You are also confusing the roles of Apache/Nginx with the roles of other components.

Apache vs Nginx

They're both web servers. They can serve static files but - with the right modules - can also serve dynamic web apps e.g. those written in PHP. Apache is more popular and has more features, Nginx is smaller and faster and has less features.

Neither Apache nor Nginx can serve Rails apps out-of-the-box. To do that you need to use Apache/Nginx in combination with some kind of add-on, described later.

Apache and Nginx can also act as reverse proxies, meaning that they can take an incoming HTTP request and forward it to another server which also speaks HTTP. When that server responds with an HTTP response, Apache/Nginx will forward the response back to the client. You will learn later why this is relevant.

alias ls='ls -GFh'
alias dir='ls -l'
alias df='df -h'
alias du='du -h'
alias ri='ri -f ansi'
alias irb='irb --simple-prompt'
alias top='top -o cpu'
alias less='less -R'
export EDITOR=pico
export PAGER=less-r
@FooBarWidget
FooBarWidget / test.c
Last active December 11, 2015 01:29
Compile and run with: gcc -Wall test.c -o test && ./test
/*
Compile and run with: gcc -Wall test.c -o test && ./test
*/
#include <sys/param.h>
#include <unistd.h>
#include <stdio.h>
int
main() {
printf("NGROUPS_MAX = %d\n", NGROUPS_MAX);