Flush Linux DNS Cache

Filed Under (Linux) by Brian Keith on 28-10-2010

Tagged Under : , , , , , ,

Flush nscd dns cache

Nscd caches libc-issued requests to the Name Service. If retrieving NSS data is fairly expensive, nscd is able to speed up consecutive access to the same data dramatically and increase overall system performance. Just restart nscd:
$ sudo /etc/init.d/nscd restart
# service nscd restart

Flush dnsmasq dns cache

dnsmasq is a lightweight DNS, TFTP and DHCP server. Dnsmasq accepts DNS queries and either answers them from its cache or forwards them to a DNS server. Restart dnsmasq to flush the cache:
$ sudo /etc/init.d/dnsmasq restart

Flush caching BIND server dns cache

A caching BIND server obtains information from another DNS server (a Zone Master) in response to a host query and then caches the data locally. To clear its cache just restart bind:
# /etc/init.d/named restart

Magento Memory Leak

Filed Under (Magento) by Brian Keith on 27-10-2010

Tagged Under : , ,

In /lib/Varien/Db/Select.php change the constructor of class Varien_Db_Select extends Zend_Db_Select
from this:

public function __construct(Zend_Db_Adapter_Abstract $adapter)
self::$_joinTypes[] = self::STRAIGHT_JOIN_ON;
self::$_partsInit = array(self::STRAIGHT_JOIN => false) + self::$_partsInit;

to this:

public function __construct(Zend_Db_Adapter_Abstract $adapter)
if (!in_array(self::STRAIGHT_JOIN_ON, self::$_joinTypes))
self::$_joinTypes[] = self::STRAIGHT_JOIN_ON;
self::$_partsInit = array(self::STRAIGHT_JOIN => false) + self::$_partsInit;

If you don’t have

if (!in_array(self::STRAIGHT_JOIN_ON, self::$_joinTypes))

then self::$_joinTypes[] keeps getting larger
$_joinTypes = array(

it just keeps adding ‘straight join’ to the array which uses a lot of memory if your importing a lot of products. The array also gets copied and parsed which uses more memory and cpu. The parsing is what I think really slows down a script.

The other memory leaks are real leaks where magento doesn’t clean up objects. It’s too complicated for me to figure those out so I compiled php 5.3 which has gc_collect_cycles() (garbage collection). Calling that cleans up the objects left in memory. But just changing the constructor made a huge difference in speed for me.

Nawcom’s 10.6.3 Legacy Kernel for Intel/AMD

Filed Under (Virtualization) by Brian Keith on 24-10-2010

Tagged Under : , ,

Nawcom’s 10.6.3 Legacy Kernel for Intel/AMD

If you owns an AMD machine and cannot boot up your Snow Leopard VM by using VirtualBox’s EFI (i.e. your VM can boot by using the EmpireEFI), this article is for you. For Intel CPU users (I am using Intel CPU too), I think this article will also provide you with valuable information.

According to Wikipedia, kernel is the central component of most computer operating systems. It is a bridge between applications and the actual data processing done at the hardware level. The kernel’s responsibilities include managing the system’s resources (the communication between hardware and software components).

For Snow Leopard, the default kernel is named as “mach_kernel” and placed under the root directory of the system partition. Apple has hard-coded some CPUID checks in the mach_kernel. It simply hangs if the detected CPU is a not “supported” CPU (i.e. the CPUs that Apple had been using in their original hardware).

Hopefully, the above issue can be resolved by using “hacked” kernels. The one that I know and have tested is from nawcom. Nawcom’s kernel is named as “legacy kernel” and the version for Mac OS X 10.6.3 can be downloaded here. You can also refer to nawcom’s post for more information and features about this kernel.

Installing the Legacy Kernel

I recommend taking a Snapshot of your VM before trying to install the Legacy Kernel,

  • Boot up your SL VM using the EmpireEFI disc.
  • Download nawcom’s kernel and double-click the downloaded package file.

    Simply click “Continue”.
  • Read the “Read Me”. It mentions that the vanilla kernel will be named mach_kernel.old.

    Click “Continue”.
  • In the “Select a Destination” screen, simply select your system partition and click “Continue”.

  • In the next screen, simply take the default value and click “Install” to kick off the installation.

  • Upon successful installation, the following screen will be displayed. Simply click “Close”.

  • Now, open a terminal and issue the following commands:

    cd /
    ls -al

    Check that the file “legacy_kernel” is there.

    • Note that there is a file named “mach_kernel” (which is the original kernel).
      I am not sure why it is not renamed as mach_kernel.old as stated in the Read Me of the installation package. Perhaps this is caused by the fact that I have started up my VM by using the mach_kernel.
  • Now, to configure Mac OS X to load by using the legacy kernel, we need modify com.apple.Boot.plist by using the following command:

    sudo -s
    cd /Library/Preferences/SystemConfiguration/
    nano com.apple.Boot.plist

    After invoking the editor, add the key-string pair value “Kernel – legacy_kernel”. The modified content is shown for your reference:

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <!DOCTYPE plist PUBLIC “-//Apple Computer//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>
    <plist version=”1.0″>
    <key>Kernel Flags</key>

    Press “Ctrl-X” to save the changes and quit the editor.

  • Now, restart your VM.
    If the legacy kernel is being loaded, you should see to it as shown below:


If you use AMD CPUs, I hope this can help you (at least there are people reporting that this kernel works for AMD Phenom II X4).

I have tried the above installation on my machine which is using iCore5-750 CPU. After installing the legacy kernel, I have to specify a “1″ as the CPU Count in the VM settings. Otherwise, the VM will hang during boot up.

For more information about the problem that people have encountered in setting up SL on an AMD machine, you can refer to the posts “Windows + VirtualBox = MAC OS” in the InsanelyMac Forum. Do expect lengthly discussion and lots of posts there, perhaps post #583 is a good starting point for you to start with. LeXa2 has provided valuable information on this topic in his posts!

Magento PHP 5.3 error

Filed Under (Blog) by Brian Keith on 23-10-2010

Tagged Under : , ,

For those who have noticed this error

Fatal error: Method Varien_Object::__tostring() cannot take arguments in /magento/lib/Varien/Object.php

when trying to install Magento on PHP 5.3, do not fear, here is the fix:

File: /lib/Varien/Object.php (Line 484)

Change from

1 public function ___toString(array $arrAttributes = array(), $valueSeparator=’,')

To this

1 public function __invoke(array $arrAttributes = array(), $valueSeparator=’,')

File /app/code/core/Mage/Core/Controller/Request/Http.php (Line 274)

Change from

1 $host = split(‘:’, $_SERVER['HTTP_HOST']);

To this

1 $host = explode(‘:’, $_SERVER['HTTP_HOST']);

There are several other files with the same problem but you get the idea.

Pasted from <http://www.learnmagento.org/magento-tutorials/fatal-error-method-varien_object__tostring-cannot-take-arguments/>