Harishvk27’s Weblog

December 4, 2008

collecting url list from web…

Filed under: random - collection — harishvk27 @ 2:31 pm

i wanted to collect random urls from net… and this post talks about my current dirty way of doing so.

(1) Visited http://www.adddirectoryeasy.com/ and collected the source pages and executes following command;

(2) grep “a href=” web-sites.txt | grep “target=\”_blink\”" | awk ‘{ print $2 }’ | grep -v src | cut -d’=’ -f2 | cut -d’”‘ -f2 | uniq | wc -l > websites.txt

November 5, 2008

Fixing Memory Leak in Apache mod_proxy.

Filed under: Apache — harishvk27 @ 5:44 am

Good to work on ‘C’. Recently i had to spend some time on Apache looking out for specific memory leak.

Thanks to Paul for good article http://journal.paul.querna.org/articles/2005/02/23/apr-memory-pools-rock/

The memory leak can be observed when requests are sent on keep-alive connection without closing the connection. As long as the connection is open, in apache we tend to allocate some memory from connection pool for processing each request. So when you have more requests per connection you tend to see apache consuming more memory. If we release the connection and we see that apache frees the memory and don’t see this leaks impact.

For more on this please follow the following link;

http://www.gossamer-threads.com/lists/apache/dev/358549

Serialization

Filed under: system infrastructure — harishvk27 @ 5:17 am

Did some serialization/deserialization evaluation of google protocol buffers and boost serialization.

Found that both lacked the efficiency required by me, and wrote my own version found that we were better then ( more then 10 times) in comparision to boost and google protocol buffers were not comparable.

But boost has the best implementation on net ( with our specific evaluation params), since we don’t wanted all the features of boost, and understanding ever evolving boost was more time consuming and when we wrote our implementation which all most matched the boost serialization implementation and meets our requirements efficiently, we settled for proprietary implementation.

We wrote in C++ and currently don’t support C or Java. I hope we need a way to support this package on ‘C’ and don’t see a need for Java.

It was fun implementing with C++ and templates and overriding.

boost interprocess named_mutex

Filed under: boost — harishvk27 @ 4:54 am

Hello All,

Just wrote a simple boost named mutex and condition based IPC test tool. Boost has done life so simple, with these kind of interfaces to basic programming.

-thanks

Harish

<code>

#include <boost/interprocess/sync/named_condition.hpp>
#include <boost/interprocess/sync/named_mutex.hpp>

namespace ipc = boost::interprocess;

int main(int argc, char **argv)
{
std::string lMutexNamed(“harish_mutex”),lCondNamed(“harish_cond”);

std::string lCondNamed2(“harish_cond2″),lMutexNamed2(“harish_mutex2″);
ipc::named_mutex::remove(lMutexNamed.c_str());
ipc::named_mutex appTraceCtrlMutex(boost::interprocess::create_only,lMutexNamed.c_str());
ipc::named_condition::remove(lCondNamed.c_str());
ipc::named_condition appTraceCtrlCondition(boost::interprocess::create_only,lCondNamed.c_str());
ipc::named_condition::remove(lCondNamed2.c_str());
ipc::named_condition appTraceCtrlCondition2(boost::interprocess::create_only,lCondNamed2.c_str());
ipc::named_condition::remove(lMutexNamed2.c_str());
ipc::named_mutex appTraceCtrlMutex2(boost::interprocess::create_only,lMutexNamed2.c_str());

int i=10;
while(i) {
{
ipc::scoped_lock<ipc::named_mutex> lock(appTraceCtrlMutex);
printf(“Acquired lock:[%s]\n”,lMutexNamed.c_str());
//sleep on condition
appTraceCtrlCondition.wait(lock);
printf(“Notification recv from t1\n”);
}
{
ipc::scoped_lock<ipc::named_mutex> lock(appTraceCtrlMutex2);
appTraceCtrlCondition2.notify_one();
printf(“Notification sent to t2\n”);
}
i–;

}

printf(“Done with creation of named mutex/condition \n”);
}

t2.cpp

#include <boost/interprocess/sync/named_condition.hpp>
#include <boost/interprocess/sync/named_mutex.hpp>

namespace ipc = boost::interprocess;

int main(int argc, char **argv)
{
std::string lMutexNamed(“harish_mutex”),lCondNamed(“harish_cond”),lCondNamed2(“harish_cond2″),lMutexNamed2(“harish_mutex2″);
try {
ipc::named_mutex appTraceCtrlMutex(boost::interprocess::open_only,lMutexNamed.c_str());
ipc::named_condition appTraceCtrlCondition(boost::interprocess::open_only,lCondNamed.c_str());
ipc::named_mutex appTraceCtrlMutex2(boost::interprocess::open_only,lMutexNamed2.c_str());
ipc::named_condition appTraceCtrlCondition2(boost::interprocess::open_only,lCondNamed2.c_str());
int i=10;
while(i) {
{
ipc::scoped_lock<ipc::named_mutex> lock(appTraceCtrlMutex);
// wake-up the guy sleeping on condition
appTraceCtrlCondition.notify_one();
printf(“Sent notification to t1\n”);
}
{
ipc::scoped_lock<ipc::named_mutex> lock(appTraceCtrlMutex2);
appTraceCtrlCondition2.wait(lock);
printf(“Notification recv from t1\n”);
}

i–;
}
}
catch(boost::interprocess::interprocess_exception &ex){
printf(“handleTraceClient harish_mutex\n”);
}
printf(“Done with creation of named mutex/condition \n”);
}

</code>

July 12, 2008

Method Overloading Doesn’t Work in C++ when called from base class constructor

Filed under: C++ — harishvk27 @ 4:46 am

#include “stdio.h”

class A {

public:

A() {

this->myPrint();

}

virtual void myPrint() {

printf(“A:%s()\n”,__FUNCTION__);

}

};

class B: public A {

public:

B() {

}

void myPrint() {

printf(“B:%s()\n”,__FUNCTION__);

}

};

main()

{

B b1; // prints A:myPrint

b1.myPrint(); // prints B:myPrint

}

The reason is when A:A() executes, the object is still of type A. It only becomes the obect of type B, when code in B:B() is entered.

Blog at WordPress.com.