Linux technical support, Technical Blogs, Cheap dedicated server support, Cheap linux dedicated server support, Cheap windows dedicated server, Dedicated server support, Data center Operation, System Administration, Bash and perl scripts for server maintainance

TimesTen vs Memcached comparison

TimesTen is a memory optimized SQL relational database, that can run standalone or as a cache in front of an Oracle database. Developers use standard JDBC, ODBC or SQL to access TimesTen. TimesTen provides real-time, updatable caching for Oracle database, the data synchronization between Oracle and TimesTen is automatically handled.

The TimesTen database is persistent and supports full ACID transactions with recovery. TimesTen also offers real-time transactional replication between TimesTen databases for high availability and load sharing.

Memcached is a distributed memory object cache, it is commonly used to cache SQL resultsets, targeted at repetitive queries found in read intensive database web applications. The user application is responsible for managing and populating the cache, memcached does not provide data synchronization with the Oracle database.

For example this is the logic the application developer needs to implement:

* Wherever you go to do a database query, first check the memcache. If the memcache returns an undefined object, then go to the database, get what you’re looking for, and put it in the memcache
* To ensure the application does not see stale data, the application must update both the memcache and the database at the same time

memcached does not understand SQL. If a memcached node dies, all data are lost and it is up to the application to reload the data from the source.

Memcached + Database performance improvement

November 12th, 2008 by Billa in Uncategorized

Its a very high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

It works as follows :
# ./memcached -d -m 2048 -l 10.0.0.40 -p 11211
-m Memory RAM
-l lsting the IP
-p Port

How you implement it in your code once you find that THIS query utilizing more CPU process :
Example:
sub get_foo_object {
my $foo_id = int(shift);
my $obj = $::MemCache->get(”foo:$foo_id”);
return $obj if $obj;

$obj = $::db->selectrow_hashref(”SELECT …. FROM foo f, bar b “.
“WHERE … AND f.fooid=$foo_id”);
$::MemCache->set(”foo:$foo_id”, $obj);
return $obj;
Example code would be as follows:

function get_foo (int userid) {
result = db_select(”SELECT * FROM users WHERE userid = ?”, userid);
return result;
}

After conversion to memcached, the same call might look like the following :-

function get_foo (int userid) {
result = memcached_fetch(”userrow:” + userid);
if (!result) { result = db_select(”SELECT * FROM users WHERE userid = ?”, userid);     memcached_add(”userrow:” + userid, result);
}
return result;
}

SQL Procedure : -

 

– Altered to put data into memcached
CREATE OR REPLACE PROCEDURE select_emp (
    p_empno         IN  NUMBER
)
IS
    v_ename         emp.ename%TYPE;
    v_hiredate      emp.hiredate%TYPE;

    v_sal           emp.sal%TYPE;
    v_comm          emp.comm%TYPE;
    v_dname         dept.dname%TYPE;
    v_disp_date     VARCHAR2(10);
BEGIN
    SELECT ename, hiredate, sal, NVL(comm, 0), dname

        INTO v_ename, v_hiredate, v_sal, v_comm, v_dname
        FROM emp e, dept d
        WHERE empno = p_empno
          AND e.deptno = d.deptno;
    v_disp_date := TO_CHAR(v_hiredate, ‘MM/DD/YYYY’);

    — Add cache entry

    PERFORM memcache_set(’emp_ename_’ || p_empno, v_ename);
    PERFORM memcache_set(’emp_disp_date_’ || p_empno, v_disp_date);
    PERFORM memcache_set(’emp_sal_’ || p_empno, v_sal);
    PERFORM memcache_set(’emp_comm_’ || p_empno, v_comm);
    PERFORM memcache_set(’emp_dname_’ || p_empno, v_dname);

    — Perform output

    DBMS_OUTPUT.PUT_LINE(’Number    : ‘ || p_empno);
    DBMS_OUTPUT.PUT_LINE(’Name      : ‘ || v_ename);
    DBMS_OUTPUT.PUT_LINE(’Hire Date : ‘ || v_disp_date);
    DBMS_OUTPUT.PUT_LINE(’Salary    : ‘ || v_sal);
    DBMS_OUTPUT.PUT_LINE(’Commission: ‘ || v_comm);
    DBMS_OUTPUT.PUT_LINE(’Department: ‘ || v_dname);

EXCEPTION
    WHEN NO_DATA_FOUND THEN
        DBMS_OUTPUT.PUT_LINE(’Employee ‘ || p_empno || ‘ not found’);
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE(’The following is SQLERRM:’);
        DBMS_OUTPUT.PUT_LINE(SQLERRM);

        DBMS_OUTPUT.PUT_LINE(’The following is SQLCODE:’);
        DBMS_OUTPUT.PUT_LINE(SQLCODE);
END;
/

– Retrieve data from memcached (if exists), otherwise revert to select_emp
CREATE OR REPLACE PROCEDURE select_emp_cached (
    p_empno         IN  NUMBER

)
IS
    v_ename         emp.ename%TYPE;
    v_hiredate      emp.hiredate%TYPE;
    v_sal           emp.sal%TYPE;
    v_comm          emp.comm%TYPE;
    v_dname         dept.dname%TYPE;

    v_disp_date     VARCHAR2(10);
BEGIN
    SELECT memcache_get(’emp_ename_’ || p_empno),
           memcache_get(’emp_disp_date_’ || p_empno),
           memcache_get(’emp_sal_’ || p_empno),
           memcache_get(’emp_comm_’ || p_empno),

           memcache_get(’emp_dname_’ || p_empno)
           INTO v_ename, v_disp_date, v_sal, v_comm, v_dname
      FROM dual;
    IF v_ename IS NULL THEN
        DBMS_OUTPUT.PUT_LINE(’From select_emp!’);
        select_emp(p_empno);

    ELSE
        — Perform output
        DBMS_OUTPUT.PUT_LINE(’From select_emp_cached!’);
        DBMS_OUTPUT.PUT_LINE(’Number    : ‘ || p_empno);
        DBMS_OUTPUT.PUT_LINE(’Name      : ‘ || v_ename);
        DBMS_OUTPUT.PUT_LINE(’Hire Date : ‘ || v_disp_date);

        DBMS_OUTPUT.PUT_LINE(’Salary    : ‘ || v_sal);
        DBMS_OUTPUT.PUT_LINE(’Commission: ‘ || v_comm);
        DBMS_OUTPUT.PUT_LINE(’Department: ‘ || v_dname);
    END IF;
EXCEPTION
    WHEN NO_DATA_FOUND THEN

        DBMS_OUTPUT.PUT_LINE(’Employee ‘ || p_empno || ‘ not found’);
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE(’The following is SQLERRM:’);
        DBMS_OUTPUT.PUT_LINE(SQLERRM);
        DBMS_OUTPUT.PUT_LINE(’The following is SQLCODE:’);
        DBMS_OUTPUT.PUT_LINE(SQLCODE);

END;
/

Shouldn’t the database do this?

Regardless of what database you use (MS-SQL, Oracle, Postgres, MySQL-InnoDB, etc..), there’s a lot of overhead in implementing ACID properties in a RDBMS, especially when disks are involved, which means queries are going to block. For databases that aren’t ACID-compliant (like MySQL-MyISAM), that overhead doesn’t exist, but reading threads block on the writing threads.

memcached never blocks. See the “Is memcached fast?” question below.

MySQL query caching is less than ideal, for a number of reasons:

* MySQL’s query cache destroys the entire cache for a given table whenever that table is changed. On a high-traffic site with updates happening many times per second, this makes the the cache practically worthless. In fact, it’s often harmful to have it on, since there’s a overhead to maintain the cache.
* On 32-bit architectures, the entire server (including the query cache) is limited to a 4 GB virtual address space. memcached lets you run as many processes as you want, so you have no limit on memory cache size.
* MySQL has a query cache, not an object cache. If your objects require extra expensive construction after the data retrieval step, MySQL’s query cache can’t help you there.

If the data you need to cache is small and you do infrequent updates, MySQL’s query caching should work for you. If not, use memcached

Is memcached fast?

Very fast. It uses libevent to scale to any number of open connections (using epoll on Linux, if available at runtime), uses non-blocking network I/O, refcounts internal objects (so objects can be in multiple states to multiple clients), and uses its own slab allocator and hash table so virtual memory never gets externally fragmented and allocations are guaranteed O(1).

Example:

null

Commands
——–

There are three types of commands.

Storage commands (there are six: “set”, “add”, “replace”, “append”
“prepend” and “cas”) ask the server to store some data identified by a key. The
client sends a command line, and then a data block; after that the
client expects one line of response, which will indicate success or
faulure.

Retrieval commands (there are two: “get” and “gets”) ask the server to
retrieve data corresponding to a set of keys (one or more keys in one
request). The client sends a command line, which includes all the
requested keys; after that for each item the server finds it sends to
the client one response line with information about the item, and one
data block with the item’s data; this continues until the server
finished with the “END” response line.

All other commands don’t involve unstructured data. In all of them,
the client sends one command line, and expects (depending on the
command) either one line of response, or several lines of response
ending with “END” on the last line.

A command line always starts with the name of the command, followed by
parameters (if any) delimited by whitespace. Command names are
lower-case and are case-sensitive.

Storage commands
—————-

First, the client sends a command line which looks like this:

[noreply]\r\n
cas [noreply]\r\n

- is “set”, “add”, “replace”, “append” or “prepend”

“set” means “store this data”.

“add” means “store this data, but only if the server *doesn’t* already
hold data for this key”.

“replace” means “store this data, but only if the server *does*
already hold data for this key”.

“append” means “add this data to an existing key after existing data”.

“prepend” means “add this data to an existing key before existing data”.

The append and prepend commands do not accept flags or exptime.
They update existing data portions, and ignore new flag and exptime
settings.

“cas” is a check and set operation which means “store this data but
only if no one else has updated since I last fetched it.”

- is the key under which the client asks to store the data

- is an arbitrary 16-bit unsigned integer (written out in
decimal) that the server stores along with the data and sends back
when the item is retrieved. Clients may use this as a bit field to
store data-specific information; this field is opaque to the server.
Note that in memcached 1.2.1 and higher, flags may be 32-bits, instead
of 16, but you might want to restrict yourself to 16 bits for
compatibility with older versions.

- is expiration time. If it’s 0, the item never expires
(although it may be deleted from the cache to make place for other
items). If it’s non-zero (either Unix time or offset in seconds from
current time), it is guaranteed that clients will not be able to
retrieve this item after the expiration time arrives (measured by
server time).

- is the number of bytes in the data block to follow, *not*
including the delimiting \r\n. may be zero (in which case
it’s followed by an empty data block).

- is a unique 64-bit value of an existing entry.
Clients should use the value returned from the “gets” command
when issuing “cas” updates.

- “noreply” optional parameter instructs the server to not send the
reply. NOTE: if the request line is malformed, the server can’t
parse “noreply” option reliably. In this case it may send the error
to the client, and not reading it on the client side will break
things. Client should construct only valid requests.

After this line, the client sends the data block:

\r\n

- is a chunk of arbitrary 8-bit data of length
from the previous line.

After sending the command line and the data blockm the client awaits
the reply, which may be:

- “STORED\r\n”, to indicate success.

- “NOT_STORED\r\n” to indicate the data was not stored, but not
because of an error. This normally means that either that the
condition for an “add” or a “replace” command wasn’t met, or that the
item is in a delete queue (see the “delete” command below).

- “EXISTS\r\n” to indicate that the item you are trying to store with
a “cas” command has been modified since you last fetched it.

- “NOT_FOUND\r\n” to indicate that the item you are trying to store
with a “cas” command did not exist or has been deleted.

Retrieval command:
——————

The retrieval commands “get” and “gets” operates like this:

get *\r\n
gets *\r\n

- * means one or more key strings separated by whitespace.

After this command, the client expects zero or more items, each of
which is received as a text line followed by a data block. After all
the items have been transmitted, the server sends the string

“END\r\n”

to indicate the end of response.

Each item sent by the server looks like this:

VALUE []\r\n
\r\n

- is the key for the item being sent

- is the flags value set by the storage command

- is the length of the data block to follow, *not* including
its delimiting \r\n

- is a unique 64-bit integer that uniquely identifies
this specific item.

- is the data for this item.

If some of the keys appearing in a retrieval request are not sent back
by the server in the item list this means that the server does not
hold items with such keys (because they were never stored, or stored
but deleted to make space for more items, or expired, or explicitly
deleted by a client).

Deletion
——–

The command “delete” allows for explicit deletion of items:

delete [

- is the key of the item the client wishes the server to delete

-

The parameter

- “noreply” optional parameter instructs the server to not send the
reply. See the note in Storage commands regarding malformed
requests.

The response line to this command can be one of:

- “DELETED\r\n” to indicate success

- “NOT_FOUND\r\n” to indicate that the item with this key was not
found.

See the “flush_all” command below for immediate invalidation
of all existing items.

Increment/Decrement
——————-

Commands “incr” and “decr” are used to change data for some item
in-place, incrementing or decrementing it. The data for the item is
treated as decimal representation of a 64-bit unsigned integer. If the
current data value does not conform to such a representation, the
commands behave as if the value were 0. Also, the item must already
exist for incr/decr to work; these commands won’t pretend that a
non-existent key exists with value 0; instead, they will fail.

The client sends the command line:

incr [noreply]\r\n

or

decr [noreply]\r\n

- is the key of the item the client wishes to change

- is the amount by which the client wants to increase/decrease
the item. It is a decimal representation of a 64-bit unsigned integer.

- “noreply” optional parameter instructs the server to not send the
reply. See the note in Storage commands regarding malformed
requests.

The response will be one of:

- “NOT_FOUND\r\n” to indicate the item with this value was not found

- \r\n , where is the new value of the item’s data,
after the increment/decrement operation was carried out.

Note that underflow in the “decr” command is caught: if a client tries
to decrease the value below 0, the new value will be 0. Overflow in
the “incr” command will wrap around the 64 bit mark.

Note also that decrementing a number such that it loses length isn’t
guaranteed to decrement its returned length. The number MAY be
space-padded at the end, but this is purely an implementation
optimization, so you also shouldn’t rely on that.

Statistics
———-

The command “stats” is used to query the server about statistics it
maintains and other internal data. It has two forms. Without
arguments:

stats\r\n

it causes the server to output general-purpose statistics and
settings, documented below. In the other form it has some arguments:

stats \r\n

Depending on , various internal data is sent by the server. The
kinds of arguments and the data sent are not documented in this vesion
of the protocol, and are subject to change for the convenience of
memcache developers.

General-purpose statistics
————————–

Upon receiving the “stats” command without arguments, the server sents
a number of lines which look like this:

STAT \r\n

The server terminates this list with the line

END\r\n

In each line of statistics, is the name of this statistic, and
is the data. The following is the list of all names sent in
response to the “stats” command, together with the type of the value
sent for this name, and the meaning of the value.

In the type column below, “32u” means a 32-bit unsigned integer, “64u”
means a 64-bit unsigner integer. ‘32u:32u’ means two 32-but unsigned
integers separated by a colon.

Name Type Meaning
———————————-
pid 32u Process id of this server process
uptime 32u Number of seconds this server has been running
time 32u current UNIX time according to the server
version string Version string of this server
pointer_size 32 Default size of pointers on the host OS
(generally 32 or 64)
rusage_user 32u:32u Accumulated user time for this process
(seconds:microseconds)
rusage_system 32u:32u Accumulated system time for this process
(seconds:microseconds)
curr_items 32u Current number of items stored by the server
total_items 32u Total number of items stored by this server
ever since it started
bytes 64u Current number of bytes used by this server
to store items
curr_connections 32u Number of open connections
total_connections 32u Total number of connections opened since
the server started running
connection_structures 32u Number of connection structures allocated
by the server
cmd_get 64u Cumulative number of retrieval requests
cmd_set 64u Cumulative number of storage requests
get_hits 64u Number of keys that have been requested and
found present
get_misses 64u Number of items that have been requested
and not found
evictions 64u Number of valid items removed from cache
to free memory for new items
bytes_read 64u Total number of bytes read by this server
from network
bytes_written 64u Total number of bytes sent by this server to
network
limit_maxbytes 32u Number of bytes this server is allowed to
use for storage.
threads 32u Number of worker threads requested.
(see doc/threads.txt)

Item statistics
—————
CAVEAT: This section describes statistics which are subject to change in the
future.

The “stats” command with the argument of “items” returns information about
item storage per slab class. The data is returned in the format:

STAT items:: \r\n

The server terminates this list with the line

END\r\n

The slabclass aligns with class ids used by the “stats slabs” command. Where
“stats slabs” describes size and memory usage, “stats items” shows higher
level information.

The following item values are defined as of writing.

Name Meaning
——————————
number Number of items presently stored in this class. Expired
items are not automatically excluded.
age Age of the oldest item in the LRU.
evicted Number of times an item had to be evicted from the LRU
before it expired.
outofmemory Number of times the underlying slab class was unable to
store a new item. This means you are running with -M or
an eviction failed.

Note this will only display information about slabs which exist, so an empty
cache will return an empty set.

Item size statistics
——————–
CAVEAT: This section describes statistics which are subject to change in the
future.

The “stats” command with the argument of “sizes” returns information about the
general size and count of all items stored in the cache.
WARNING: This command WILL lock up your cache! It iterates over *every item*
and examines the size. While the operation is fast, if you have many items
you could prevent memcached from serving requests for several seconds.

The data is returned in the following format:

\r\n

The server terminates this list with the line

END\r\n

’size’ is an approximate size of the item, within 32 bytes.
‘count’ is the amount of items that exist within that 32-byte range.

This is essentially a display of all of your items if there was a slab class
for every 32 bytes. You can use this to determine if adjusting the slab growth
factor would save memory overhead. For example: generating more classes in the
lower range could allow items to fit more snugly into their slab classes, if
most of your items are less than 200 bytes in size.

Slab statistics
—————
CAVEAT: This section describes statistics which are subject to change in the
future.

The “stats” command with the argument of “slabs” returns information about
each of the slabs created by memcached during runtime. This includes per-slab
information along with some totals. The data is returned in the format:

STAT : \r\n
STAT \r\n

The server terminates this list with the line

END\r\n

Name Meaning
——————————
chunk_size The amount of space each chunk uses. One item will use
one chunk of the appropriate size.
chunks_per_page How many chunks exist within one page. A page by
default is one megabyte in size. Slabs are allocated per
page, then broken into chunks.
total_pages Total number of pages allocated to the slab class.
total_chunks Total number of chunks allocated to the slab class.
used_chunks How many chunks have been allocated to items.
free_chunks Chunks not yet allocated to items, or freed via delete.
free_chunks_end Number of free chunks at the end of the last allocated
page.
active_slabs Total number of slab classes allocated.
total_malloced Total amount of memory allocated to slab pages.

Other commands
————–

“flush_all” is a command with an optional numeric argument. It always
succeeds, and the server sends “OK\r\n” in response (unless “noreply”
is given as the last parameter). Its effect is to invalidate all
existing items immediately (by default) or after the expiration
specified. After invalidation none of the items will be returned in
response to a retrieval command (unless it’s stored again under the
same key *after* flush_all has invalidated the items). flush_all
doesn’t actually free all the memory taken up by existing items; that
will happen gradually as new items are stored. The most precise
definition of what flush_all does is the following: it causes all
items whose update time is earlier than the time at which flush_all
was set to be executed to be ignored for retrieval purposes.

The intent of flush_all with a delay, was that in a setting where you
have a pool of memcached servers, and you need to flush all content,
you have the option of not resetting all memcached servers at the
same time (which could e.g. cause a spike in database load with all
clients suddenly needing to recreate content that would otherwise
have been found in the memcached daemon).

The delay option allows you to have them reset in e.g. 10 second
intervals (by passing 0 to the first, 10 to the second, 20 to the
third, etc. etc.).

“version” is a command with no arguments:

version\r\n

In response, the server sends

“VERSION \r\n”, where is the version string for the
server.

“verbosity” is a command with a numeric argument. It always succeeds,
and the server sends “OK\r\n” in response (unless “noreply” is given
as the last parameter). Its effect is to set the verbosity level of
the logging output.

“quit” is a command with no arguments:

quit\r\n

Upon receiving this command, the server closes the
connection. However, the client may also simply close the connection
when it no longer needs it, without issuing this command.

Error strings
————-

Each command sent by a client may be answered with an error string
from the server. These error strings come in three types:

- “ERROR\r\n”

means the client sent a nonexistent command name.

- “CLIENT_ERROR \r\n”

means some sort of client error in the input line, i.e. the input
doesn’t conform to the protocol in some way. is a
human-readable error string.

- “SERVER_ERROR \r\n”

means some sort of server error prevents the server from carrying
out the command. is a human-readable error string. In cases
of severe server errors, which make it impossible to continue
serving the client (this shouldn’t normally happen), the server will
close the connection after sending the error line. This is the only
case in which the server closes a connection to a client.

In the descriptions of individual commands below, these error lines
are not again specifically mentioned, but clients must allow for their
possibility.

Install Python with apache + Configure mod_python

If you already have python which could be the case with most of you then you can proceed further with step 2.

1. Compile Python from source :
Download from Python web page
http://www.python.org/

UnTAR and enter the directory
tar -jxvf Python-2.5.2.tar.bz2
cd Python-2.5.2

Configure using an alternate install dir
(use ./configure -h for config options)
./configure –prefix=/opt/python/

Build and install the software
make | tee makelog
make test | tee maketestlog
make install | tee makeinstalllog
This will create a python binary. If you specified the prefix, it will put it in the bin/ directory under the prefix directory. However, this compiles the command line python version. To get it working with Apache, preform the following.

2.

Download mod_python
http://www.modpython.org/

Untar and enter into the directory
tar -zxvf mod_python-3.3.1.tgz
cd mod_python-3.3.1

Configure mod_python.
It needs to know where python binary to use, and the apache build tool apxs is located during the configure.

./configure \
–with-apxs=/usr/sbin/apxs \ # the apache build tool
–with-python=/opt/python25/bin/python2.5 \ # path to python binary
| tee output.config
make | tee output.make
make install | tee output.makeinstall

make install should place a binary module in /etc/httpd/modules
(or /usr/lib/httpd/modules)
The module will be called mod_python.so

Configure Apache
You will need to tell Apache to load the module by adding the following line in the Apache configuration file (httpd.conf)

LoadModule python_module modules/mod_python.so

AddHandler mod_python .py
PythonHandler mptest
PythonDebug On

Imaging Support
To be able to manipulate images with python, you need the PIL library. Download it from http://www.pythonware.com/products/pil/
After untaring and entering the directory, install by: python setup.py install
It will copy files into your default (`which python`) python install.
Ref : http://www.modpython.org

Enjoy,
Jayesh

How to create extra swap space on linux machine

You may sometime lack with the swap space due to high usage of memory on your machine and would need to increase the swap on your linux box.
There are two ways by which you can achieve this.
[ A ] If you do not have enough space on your hard disk (that depends if you have left your disk with extra space) then you need to create a swap file and put it as a swap file in the system thats the first way that you most like to go with cause obviously you might not have kept extra space on your hard disk. So you can use this option to add swap space.
Here is the details how you can go :
To add a swap file:

1. Determine the size of the new swap file and multiple by 1024 to determine the block size. For example, the block size of a 64 MB swap file is 65536.
2. At a shell prompt as root, type the following command with count being equal to the desired block size:

dd if=/dev/zero of=/swapfile bs=1024 count=65536

3. Setup the swap file with the command:

mkswap /swapfile

4. To enable the swap file immediately but not automatically at boot time:

swapon /swapfile

5. To enable it at boot time, edit /etc/fstab to include:

/swapfile swap swap defaults 0 0

The next time the system boots, it will enable the new swap file.
6. After adding the new swap file and enabling it, make sure it is enabled by viewing the output of the command cat /proc/swaps or free.

[ B ] If you have the disk space free on existing hard disk that you have not used to create partition then recommanded way to use this way to create swap space. :-)

To add a swap partition (assuming /dev/hdb2 is the swap partition you want to add):

1. The hard drive can not be in use (partitions can not be mounted, and swap space can not be enabled). The easiest way to achieve this it to boot your system in rescue mode. Refer to Chapter 8 for instructions on booting into rescue mode. When prompted to mount the filesystem, select Skip.

Alternately, if the drive does not contain any partitions in use, you can unmount them and turn off all the swap space on the hard drive with the swapoff command.
2. Create the swap partition using parted or fdisk. Using parted is easier than fdisk; thus, only parted will be explained. To create a swap partition with parted:

* At a shell prompt as root, type the command parted /dev/hdb, where /dev/hdb is the device name for the hard drive with free space.
* At the (parted) prompt, type print to view the existing partitions and the amount of free space. The start and end values are in megabytes. Determine how much free space is on the hard drive and how much you want to allocate for a new swap partition.
* At the (parted) prompt, type mkpartfs part-type linux-swap start end, where part-type is one of primary, extended, or logical, start is the starting point of the partition, and end is the end point of the partition.

Warning Warning
Changes take place immediately; be careful when you type.

* Exit parted by typing quit.
3. Now that you have the swap partition, use the command mkswap to setup the swap partition. At a shell prompt as root, type the following:

mkswap /dev/hdb2

4. To enable the swap partition immediately, type the following command:

swapon /dev/hdb2

5. To enable it at boot time, edit /etc/fstab to include:

/dev/hdb2 swap swap defaults 0 0

The next time the system boots, it will enable the new swap partition.
6. After adding the new swap partition and enabling it, make sure it is enabled by viewing the output of the command cat /proc/swaps or free.

Unable to find a javac compiler; com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK

If you are getting this error in catalina.out continually

Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK

1st obvious thing you need to check is
Check if the env variable is set or not for JAVA_HOME and PATH inclused the bin path of jad_***/bin
If you are set properly and though you get the same error then the issue is that the javac is not able to find the tools.jar so you need to find the correct tools.jar for the java version that you are using and place it under tomcat/common/lib/ folder like this.

cp /usr/java/jdk1.5.0_09/lib/tools.jar /appl/tomcat/common/lib/tools.jar

That will fix your issue.
Cheers,
Jayesh

Putty + tips and tweaks + used saved session to login to server directly

1. Open Putty and save the session by adding the server details in “Hostname” “Port no” and “Saved Session”
2. Find the folder in which putty.exe file exists
3. right click putty.exe file and create short cut.
4. Right click on created short cut putty file >> Properties >> Target >>
\path\name\to\putty.exe -load “mysession”

How to do that from image

Its done. Just click on that .exe file and you are set to go to your require server from now onwards. :-)

UX: /usr/sbin/userdel: ERROR: Failed to read /etc/group file due to invaild entry or read error.

Recheck the /etc/group file.
Make sure you do not have press enter at the end (an extra line blank line) of the line or in between.

Thanks

Monitor file system changes - incron

You might be familier with the usage of cron, the default tool for scheduling tasks on Linux machine. But you might have created or need some time on application server that you need to check if some file is created or not while running some application and to moniter that file attributes or the file itself. In that case this s/w can help you a lot with just simple commands. :-) While traditional cron jobs are executed at set times, inotify cron, or incron, is a cron clone that watches the filesystem for specified changes and executes the relevant commands. You can set incron to monitor a particular file or directory for changes and schedule jobs for when those changes occur.

Fedora users can use yum to install incron with the yum install incron command. Once installed, you need to start the incron daemon before you can schedule jobs. The command, service incrond start, executed as root, will start the incron daemon on and the chkconfig incrond on command will configure it to be started at boot time.

incrontab, much like crontab, is the table manipulator used to schedule jobs. Each line in incrontab contains a filename, a comma-separated list of filesystem events to watch, and the command to be executed. You can schedule jobs based on file or directory changes. Use the incrontab -t command for a list of all the filesystem events that incron can monitor. Listed below is a list of these events along with explanation.

IN_ACCESS: Watched file is accessed
IN_MODIFY: Watched file is modified
IN_ATTRIB: Metadata changed (permissions, extended attributes, timestamps, etc.) IN_CLOSE_WRITE: Closed a writable file
IN_CLOSE_NOWRITE: Closed a non-writable file IN_OPEN: Opened a file
IN_MOVED_FROM: File moved out of directory being watched
IN_MOVED_TO: File moved into directory being watched
IN_CREATE: New file/directory created in the watched directory
IN_DELETE: File/directory deleted from directory being watched
IN_DELETE_SELF: Watched file/directory was deleted
IN_CLOSE: Watch both IN_CLOSE_WRITE and IN_CLOSE_NOWRITE
IN_MOVE: Watch both IN_MOVED_FROM and IN_MOVED_TO
IN_ALL_EVENTS: Watch all listed events
IN_DONT_FOLLOW: Don’t follow sym link
IN_ONLYDIR: Watch path only if it’s a directory
IN_MOVE_SELF: Watched file/directory was deleted

If you want the system to play an audio file whenever a new file/directory is created in your home directory, use this incrontab entry:
/home/linuxlala IN_CREATE paplay /usr/share/sounds/pop.wav.
The command
/home/linuxlala IN_CREATE rm -rf $@/$#
works similarly but its purpose is far more evil. With this entry in the incrontab file, any directory or file created in the user’s home directory would be immediately deleted. The special symbols, or wildcards ($@/$#), convey the complete path of the newly created file to the rm -rf command.

These wildcards are useful when you have to pass the filename to a script or to the command that is to be executed. For example, if you want to run a script that will replace all curse words in the file on all files created in the /home/linuxlala/Documents directory, your incrontab entry would be:
/home/linuxlala/Documents IN_CLOSE_WRITE /home/linuxlala/replace_curse_words.sh $@/$#
Notice we’ve used IN_CLOSE_WRITE and not IN_CREATE for this rule. This is because only files will evoke IN_CLOSE_WRITE while even directories can evoke the IN_CREATE event.

Apart from the $@ and the $# wildcards, which respectively tell you the path of the watched file and the event-related filename, there are some other wildcards as well, such as $% and $&, which can be used to determine the textual or the numerical event flags.

Each time you update your incrontab file, run the incrontab -d command to reload the user table. If you don’t do this, incron will continue to follow the previously defined rules.

You can download it from here.

Some bash commands I used often

July 29th, 2008 by Billa in Linux server, Imp threads

1. Find a file with of the june month date and delete it.

ls -lat |grep “Jun [0-9]” |awk “{print $9}” | xargs rm -fv

2. If you are searching for a word in too many files then might be due to too many files you will get the
error warning that you can’t search that due to too much file in that case you can optimize your
search with some commnds like this.

grep “IGEdev42″ `find ./ ! -name “_[0-9][0-9]” -type f -name “.xml”`

3. When you stop and start apache then in error logs you may get that some semaphore is still there
for the apache instance and you need to remove it from system so you need to fire following command
once you stop the apache instance. After firing this command you can start apache.

for i in `ipcs | grep apache| awk “{print $2}”`; do ipcrm -s $i; ipcrm -S $i; ipcrm -m $i; done

Checking your bandwidth

Imagine this: Company A has a storage server named ginger and it is being NFS-mounted by a client node named beckham. Company A has decided they really want to get more bandwidth out of ginger because they have lots of nodes they want to have NFS mount ginger’s shared filesystem.

The most common and cheapest way to do this is to bond two Gigabit ethernet NICs together. This is cheapest because usually you have an extra on-board NIC and an extra port on your switch somewhere.

So they do this. But now the question is: How much bandwidth do they really have?

Gigabit Ethernet has a theoretical limit of 128MBps. Where does that number come from? Well,

1Gb = 1024Mb; 1024Mb/8 = 128MB; “b” = “bits,” “B” = “bytes”

But what is it that we actually see, and what is a good way to measure it? One tool I suggest is iperf. You can grab iperf like this:

# wget http://dast.nlanr.net/Projects/Iperf2.0/iperf-2.0.2.tar.gz

You’ll need to install it on a shared filesystem that both ginger and beckham can see. or compile and install on both nodes. I’ll compile it in the home directory of the bob user that is viewable on both nodes:

tar zxvf iperf*gz
cd iperf-2.0.2
./configure -prefix=/home/bob/perf
make
make install

On ginger, run:

# /home/bob/perf/bin/iperf -s -f M

This machine will act as the server and print out performance speeds in MBps.

On the beckham node, run:

# /home/bob/perf/bin/iperf -c ginger -P 4 -f M -w 256k -t 60

You’ll see output in both screens telling you what the speed is. On a normal server with a Gigabit Ethernet adapter, you will probably see about 112MBps. This is normal as bandwidth is lost in the TCP stack and physical cables. By connecting two servers back-to-back, each with two bonded Ethernet cards, I got about 220MBps.

In reality, what you see with NFS on bonded networks is around 150-160MBps. Still, this gives you a good indication that your bandwidth is going to be about what you’d expect. If you see something much less, then you should check for a problem.

I recently ran into a case in which the bonding driver was used to bond two NICs that used different drivers. The performance was extremely poor, leading to about 20MBps in bandwidth, less than they would have gotten had they not bonded the Ethernet cards together!

Next Article »