A quick link pointer - differences b/w ruby mutex and monitors
Some quick tips:
Monitors are re-entrant - meaning you can nest calls to methods that synchronize access to some data
Mutex is not re-entrant
Monday, June 22, 2009
Tuesday, May 26, 2009
Ruby blocks - explicit vs implicit arguments
I wanted to pass an implicit block argument to a call to super. Looks like the most efficient way is to use
def on_ready
unless paused?
super { yield }
end
end
-----------------------
From http://www.ruby-forum.com/topic/71221
require 'benchmark'
def outer11(&bl)
inner1(&bl)
end
def outer12(&bl)
inner2(&bl)
end
def outer21
inner1 {yield}
end
def outer22
inner2 {yield}
end
def inner1(&bl)
bl.call
end
def inner2
yield
end
n = 100000
Benchmark.bmbm(10) do |rpt|
rpt.report("outer11") do
n.times {outer11{}}
end
rpt.report("outer12") do
n.times {outer12{}}
end
rpt.report("outer21") do
n.times {outer21{}}
end
rpt.report("outer22") do
n.times {outer22{}}
end
end
__END__
Output:
Rehearsal ---------------------------------------------
outer11 0.890000 0.010000 0.900000 ( 0.894500)
outer12 0.370000 0.000000 0.370000 ( 0.364880)
outer21 0.770000 0.000000 0.770000 ( 0.776638)
outer22 0.170000 0.000000 0.170000 ( 0.163393)
------------------------------------ total: 2.210000sec
user system total real
outer11 0.490000 0.000000 0.490000 ( 0.491969)
outer12 0.400000 0.000000 0.400000 ( 0.396264)
outer21 0.760000 0.000000 0.760000 ( 0.764508)
outer22 0.160000 0.000000 0.160000 ( 0.161982)
def on_ready
unless paused?
super { yield }
end
end
-----------------------
From http://www.ruby-forum.com/topic/71221
require 'benchmark'
def outer11(&bl)
inner1(&bl)
end
def outer12(&bl)
inner2(&bl)
end
def outer21
inner1 {yield}
end
def outer22
inner2 {yield}
end
def inner1(&bl)
bl.call
end
def inner2
yield
end
n = 100000
Benchmark.bmbm(10) do |rpt|
rpt.report("outer11") do
n.times {outer11{}}
end
rpt.report("outer12") do
n.times {outer12{}}
end
rpt.report("outer21") do
n.times {outer21{}}
end
rpt.report("outer22") do
n.times {outer22{}}
end
end
__END__
Output:
Rehearsal ---------------------------------------------
outer11 0.890000 0.010000 0.900000 ( 0.894500)
outer12 0.370000 0.000000 0.370000 ( 0.364880)
outer21 0.770000 0.000000 0.770000 ( 0.776638)
outer22 0.170000 0.000000 0.170000 ( 0.163393)
------------------------------------ total: 2.210000sec
user system total real
outer11 0.490000 0.000000 0.490000 ( 0.491969)
outer12 0.400000 0.000000 0.400000 ( 0.396264)
outer21 0.760000 0.000000 0.760000 ( 0.764508)
outer22 0.160000 0.000000 0.160000 ( 0.161982)
Sunday, March 22, 2009
CookierStore::CookieOverflow
/!\ FAILSAFE /!\ Sun Mar 22 23:51:44 -0700 2009
Status: 500 Internal Server Error
ActionController::Session::CookieStore::CookieOverflow
This error is typically due to the user trying to store > 4K of data in the session.
Another source of error is if you try to store $! in flash[:error]
begin
....
rescue
flash[:error] = $!
end
This tries to store the ruby exception object in the flash (which in turn is stored in the cookie) and you will start getting the cookie overflow errors.
The solution is simple
begin
....
rescue
flash[:error] = $!.to_s
end
-
Tuesday, November 4, 2008
ORA-12516: TNS:listener could not find available handler with matching protocol stack
We use Oracle Database 10g Express Edition Release 10.2.0.1.0 for our RoR development and were hitting the TNS:listener error all the time. This made concurrent development a real pain and we couldn't leave staging servers and sqldeveloper sessions up.
Google searches turned up really scant information - mainly advices to increase the PROECESSES limit. I am not a DBA, so wasn't sure what needed to be done.
In any case, the following solution worked like a charm and I hope others who have this issue find this post useful.
Google searches turned up really scant information - mainly advices to increase the PROECESSES limit. I am not a DBA, so wasn't sure what needed to be done.
In any case, the following solution worked like a charm and I hope others who have this issue find this post useful.
source /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.csh
setenv ORACLE_SID XE
And then execute the following steps to increase the number processes and sessions:
1) Connect to the database using the sys or system user:
sqlplus SYSTEM/<syspwd>@//<dbhost>/xe
2) To confirm the PROCESSES and SESSIONS values, run the following script:
sql> col name format A30
Sql> col value format A30
sql> select name, value from v$parameter where name in ('processes','sessions');
3) SQL> alter system set processes=300 scope=spfile;
4) SQL> alter system set sessions=300 scope=spfile;
5) Bounce the database to reflect the changes
6) To confirm new values run the script (2).
Subscribe to:
Posts (Atom)