Wednesday, November 04, 2009

Hibernate flush only specific object types

So we have this issue where in certain cases we would only like to flush a certain class of objects and discard the rest. This is sort of a common use case if you are following the one session per request paradigm wherein if a job/request fails and the job status logging is also done via the database/hibernate then you would still want to persist the job log status however the application job data changes can be discarded. Found an excellent post here:

https://forum.hibernate.org/viewtopic.php?f=1&t=983747&sid=4988e082644059b66220836ef4c53806&start=15

So as it turns out there is no way to selectively flush objects. You can use the "evict non flushable objects" methodology (basically bu evicting the objects their changes are discarded) but often times you don't know what all objects were involved in the request.

A better design is to probably open two sessions with each request/job. One for meta data and the other for application business data. That allows better handling of request failures.

Sunday, October 04, 2009

Enable Mysql general query log in Mac OSX

To enable this for the current user follow the below steps

-- create or edit the existing cnf file
vim ~/.my.cnf

-- add the below variable to the file
[server]
log=/tmp/mysql_query.log

-- restart mysql
sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

To enable the general query log for all users add the "variable" to /etc/my.cnf instead.

Sunday, August 30, 2009

Adobe Flash freezes on full screen

Have been having this problem recently wherein doing a full screen on a flash video freezes the screen. My wife watches movies online occasionally on MegaVideo/Veoh and the problem persists in both as both use flash internally.

While the Flash player is in normal mode, right click on the player and choose "Settings" from the context menu. Remove the checkmark in the box next to "Enable Hardware Acceleration".




Reference links
http://support.mozilla.com/si/kb/Cannot+view+full+screen+Flash+videos
http://www.macromedia.com/support/documentation/en/flashplayer/help/help01.html

Friday, August 14, 2009

Adcenter keyword: Setting match type

Adcenter is different from other networks as it does not have a special attribute called “match type” on a keyword. Instead each keyword has three bid fields “exact bid (EB)”, “phrase bid (PB)” and “broad bid (BB)”. The keyword match types are determined on whether a bid is specified for that match type. For instance if a keyword has EB=1.5,PB=0.75,BB=0.0 then this keyword is used in exact and phrase matches. This is different in other networks where a keyword has a single “bid” attribute and an attribute to specify match type.

Friday, August 07, 2009

Monitoring Gearman over telnet port 4730

So the only way to monitor Gearman is via doing a telnet to port 4730. The current monitoring supported commands are fairly basic. I could not locate any documentation on the support commands so had to literally look at the code to figure out the supported commands (the below command documentation is copied from the comments in code). There are plans to include more set of commands in the next release.

Command: STATUS

The output format of this function is tab separated columns as follows, followed by a line consisting of a full stop and a newline (".\n") to indicate the end of output. below are the columns shown

- Function name : A string denoting the name of the function of the job
- Number in queue : A positive integer indicating the total number of jobs for this function in the queue. This includes currently running ones as well (next column)
- Number of jobs running : A positive integer showing how many jobs of this function are currently running
- Number of capable workers : A positive integer denoting the maximum possible count of workers that could be doing this job. Though they may not all be working on it due to other tasks holding them busy.

Command : Workers

This command show the details of various clients registered with the gearmand server. For each worker it shows the following info:

- Peer IP: Client remote host
- Client ID: Unique ID assigned to client
- Functions: List of functions this client has registered for.

Any other command text throws a error "ERR unknown_command Unknown+server+command"



sudhirv@sudhirv:~$ telnet localhost 4730
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

STATUS
.
WORKERS
11 127.0.0.1 - :
.
status
.
workers
11 127.0.0.1 - :
.
some crap
ERR unknown_command Unknown+server+command

#### will add more samples in action when I have this thing up and running ####

Installing Gearman on Ubuntu

Gearman is a open source job forking system. We have been evaluating its use in our project to share jobs across components. More info on the Gearman project can be found here: http://gearman.org/.

Here are the instructions on installing Gearman on Ubuntu



wget http://launchpad.net/gearmand/trunk/0.9/+download/gearmand-0.9.tar.gz
tar -xvzf gearmand-0.9.tar.gz

# two missing libraries that found at configure time
sudo apt-get install libevent-dev
sudo apt-get install uuid-dev

cd gearmand-0.9
./configure
make
sudo make install
sudo ldconfig

# start gearman
gearmand &

# check gearmand running
ps auxw | grep [g]earmand

# check germand listening for jobs on tcp port 4730
sudo lsof -i tcp:4730


# errors when starting gearman
Error: gearman: error while loading shared libraries: libgearman.so.1

Solution: `make install` may install libraries into `/usr/local/lib`. It's possible
that this directory isn't on your library search path, which will result in an error
like: "gearman: error while loading shared libraries: libgearman.so.1." To fix this,
either add `/usr/local/lib` to `LD_LIBRARY_PATH`, or modify `/etc/ld.so.conf` or
`/etc/ld.so.conf.d` to add `/usr/local/lib`, then run: sudo ldconfig

Extract process attributes

Handy one liner scripts to extract various process attributes. You can add additional attributes to the 'ps' command to get other attributes. Below are some samples

-- Process start hour
ps -eo pgid,lstart,cmd | grep "[p]name" | awk '{print $5}' | cut -d\. -f1

-- Process start minute
ps -eo pgid,lstart,cmd | grep "[p]name" | awk '{print $5}' | cut -d\. -f2

--process start day
ps -eo pgid,lstart,cmd | grep "[p]name" | awk '{print $4}'

command to kill a process group

If pid is negative but not -1, the signal is sent to all processes whose process group ID is equal to the absolute value of pid. The negative pid is specified in this way:

kill -s KILL -- -nn

where nn is the process group ID and may have a range of 2 to 7 digits (nn to nnnnnnn).

kill -s KILL -- -9812753

The format must include the – – – before the nn in order to specify the process group ID

Saturday, June 06, 2009

Ubuntu 9.04 resets resolution @ restart

Spent quite some time today trying to make this work. Installed Ubuntu 9.04 this AM and as expected it was not able to correctly detect the monitor resolution. Installed the latest NVidia drivers (180.44) from Synaptic package and was able to set the right resolution using "nvidia-settings" app. Before saving the configuration made sure that preview of "/etc/X11/xorg.conf" was showing as to what I had set. Restarted the system and the resolution was getting set back to "800x600". Applying a resolution using 'nvidia-settings" was still working in the session however @ logout/restart it would revert back to "800x600". Here's what all I tried and the final step that worked for me:

1) The first question I had was whether nvidia drivers were being loaded at restart or not. One of the Ubuntu knowledge base suggested adding "nvidia" to "/etc/modules" such that it gets loaded at boot time but that didn't work.

.... After many failed google searches I shifted my focus to looking at system logs for any clues......

2) checked this log file after system startup "/var/log/gdm/:0.log" and it was complaining about error loading "type2" and "freetype" modules. I wasn't sure if this was causing the "xorg.comf" to fail so I manually disabled the load of these modules in the "xorg.conf" file under the section module like below. Did a restart but still the same situation however the log "/var/log/gdm/:0.log" was not showing the error this time.

Section "Module"
Load "dbe"
Load "extmod"
# Load "type1"
# Load "freetype"
Load "glx"
EndSection

2) Check log file "/var/log/Xorg.0.log". This log contains details on "xorg.conf" loading. Watchout for any errors in this log. In my case this log looked fine except the last line in the log file that said "[nvidia]: setting resolution 800x600". This baffled me. While the earlier lines in the log file correctly stated loading the correct resolution from 'xorg.conf', this last log line almost seemed like some another process was invoking at startup that was turning the resolution back to '800x600'. Googled around but no clue.

... Took a walk at a park nearby as my brains was about to explode.

3) Lot of sites/forums had samples of "xorg.conf" files from users whose system was working fine. Tried various of those but still no luck.

4) One of the forums post suggested this method. "System --> Preferences --> Display". Choosing that option prompts a question "It appears that your graphics driver does not support the necessary extensions to use this tool. Do you want to use your graphics driver vendor's tool instead?". if you click "yes" it takes you to the "nvidia-settings" tool. If you choose the "No" option, it allows choosing a resolution via the "Display Preferences" window. I select "No" and choose the desired resolution of "1280x1024" from the list and hit "Apply". As usual it worked in the session and voila!!!! it also worked after a restart. The resolution stayed @ "1280x1024".

Obviously there were a lot of other steps that I tried in vain but these seemed worth a note as they provide some clue as to what the issue might be. Hope this post helps.

my google searched keywords: Xorg.log nvidia 800x600, Ubuntu 9.04 resets resolution restart, ubuntu 9.04 stuck at 800x600, ubuntu 9.04 low graphics mode, ubuntu 9.04 loose settings on restart, ubuntu 9.04 lost screen resolution after restart

Mac OSX Burn ISO Image

Here are the steps.

1) Open Finder
2) Browse "Application/Utilities"
3) Open/double click Disk utility
4) Click "Burn" icon on top. This will ask you to choose a ISO image
5) Once selected it will ask to insert a CD and voila.

Off course its easy but when you've been using Linux and Windows utilities for years, these steps can be a little perplexing and hard to remember.

******************* screenshots **********************



Wednesday, January 28, 2009

Perl Mysql DBI get deleted row count

Trying to capture the number of deleted rows when executing a delete statement was returning a "0E0". See below for the script details. What I found was that it was DBI's way of saying zero rows were deleted. The thing to know about DBI is that do() needs to return distinct values to distinguish the occurrence of an error from the case that no rows were affected, so it uses “undef” and “0E0”. The value “undef” indicates an error; it evaluates to false in a Boolean context. The string “0E0” indicates that no rows were affected; it evaluates to true in Boolean contexts but is treated as zero in numeric contexts. If do() returned 0 to indicate no rows were affected, that evaluates to false in a Booelan context and would be difficult from an error. You can do the following to display the row count correctly

Error:

my $deleted = $conn->do("delete from employee where year between 1901 and 1910");
print "deleted $deleted rows.\n";

The above would print "deleted 0E0 rows"


Solution:

 
my $deleted = $conn->do("delete from employee where year between 1901 and 1910");
printf "deleted %d rows.\n", $deleted;

(OR)

my $deleted += $conn->do("delete from employee where year between 1901 and 1910");
print "deleted $deleted rows.\n";