[mysql] skip-name-resolve

mysql은 connection시 IP를 hostname으로 변환하는 과정을 거치면서 부하를 발생시키는데 이를 막기 위해서는 다음과 같이 설정해 주면 된다.

/etc/my.cnf

[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
skip-name-resolve

그리고 restart

[Mysql] Thread Cache 최적화

만약 DB 서버가 빈번하게 connection 요청이 온다면 threads_created 값이 증가하지 않을 때까지 충분히 크게 설정해야 한다. CPU 로드가 줄어든다고 한다.

thread-created값을 확인하는 명령어는 다음과 같다.

mysql> show status like ‘threads_created’;
+—————–+——-+
| Variable_name | Value |
+—————–+——-+
| Threads_created | 1 |
+—————–+——-+
1 row in set (0.00 sec)

다음 명령어는 thread들의 cache 크기를 보여주는 명령어이다.

mysql> show variables like ‘thread_cache_size’;

+——————-+——-+
| Variable_name | Value |
+——————-+——-+
| thread_cache_size | 8 |
+——————-+——-+
1 row in set (0.00 sec)

최적화 하는 방법은 간단하다. threads_connected에 관계된 수치들을 지켜보면서
임계 workload를 견뎌낼 수 있는 정도까지 thread_cache_size를 충분히 늘려주면 된다.

다음은 thread에 관계된 상태를 조회하는 명령어이다.

mysql> show status like ‘thread_%’;
+——————-+——-+
| Variable_name | Value |
+——————-+——-+
| Threads_cached | 0 |
| Threads_connected | 1 |
| Threads_created | 1 |
| Threads_running | 1 |
+——————-+——-+
4 rows in set (0.00 sec)

자료 출처는 다음과 같다.

http://www.fosiul.com/index.php/2009/08/how-to-optimized-thread-cache-variables-for-mysql-server/comment-page-1/#respond

Viral marketing(바이러스 마케팅)

social network를 이용해서 바이러스와 유사한
자가 복제와 같은 메커니즘으로 brand 인지도를 높이거나
제품 판매와 같은 목적을 도달하기 위한 방법을 말한다.
구전이나 인터넷의 네트워크에 의해 전달된다. viral marketing은 video clips, Flash Game, 광고 게임, ebook, brandable software, image, text message 등이 포함된다.

마치 내가 카카오톡이나 마이피플, 라인을 내 친구에게 소개하는 것이나
리바이스가 Facebook을 이용하여 마케팅을 펼치는 것도 하나의 실례이다.

[App Engine] JDO에서 지원하지 않는 것

구글 App engine에서 지원하지 않는  JDO 특징들에 대해 정리해본다.

1. 소유하지 않은 relationship은 미래 버전에 지원할 예정일 것이다. 무슨 의미일까?
2. many to many relationship
3. 부모 타입의 query가 수행중일 경우 child entity의 field를 filter에서 사용하지 못한다.키를 사용해서 부모의 관계 field를 직접적으로 테스트 할 수 있다.
4. 다형적인 쿼리들을 사용하지 못한다. class의 하위 클래스의 인스턴트를 가져오는 쿼리를 수행하지 못한다.  datastore에서 각각의 클래스는 다른 종류의 entity로 분리되어 있다.
5. Identitytype.APPLICATION만이 @PersistenceCapable 어노테이션만을 지원한다.
6. 부모와 자식이 같은 클래스를 가지는 경우에 대해 one to many relationsihp을 소유하는 것을 막는 버그가 존재한다. parent와 child의 key를 명백하게 분리하여 저장한다.

[Spring] Custom Transactional Annotation in AOP

가끔 프로그래밍을 하다보면 다음과 같이 앞뒤로 (Before, After) Code duplication 이 발생한다. 이를 AOP를 이용하여 깔끔하게 코드 중복을 정리할 수 있는데 원리(rule)는  @Transactional Annotation과 비슷하다.

Before Job: begin Transaction

Processed : execute queries

After Job : end Transaction

Spring에서도 Interceptor를 위한 AOP를 구현해보자

Interceptor에 대해 이해가 잘 가지 않는다면 다음 wiki를 참고하길 바란다.

http://en.wikipedia.org/wiki/Interceptor_pattern

Step 1. xml bean configuration

<beans xmlns=”http://www.springframework.org/schema/beans&#8221;
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xmlns:p=”http://www.springframework.org/schema/p&#8221;
xmlns:mvc=”http://www.springframework.org/schema/mvc&#8221; xmlns:context=”http://www.springframework.org/schema/context&#8221;
xmlns:tx=”http://www.springframework.org/schema/tx&#8221; xmlns:aop=”http://www.springframework.org/schema/aop&#8221;
xsi:schemaLocation=”
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
default-autowire=”byName”>
<aop:aspectj-autoproxy />
<context:component-scan base-package=”org.simple.aop”> 

Step2. Annotation 생성

@Target({java.lang.annotation.ElementType.METHOD, java.lang.annotation.ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface TransactionApply {

}

Step3. Aspect Bean 만들기

package org.simple.aop;

@Aspect
@Component
public class SimpleAspect {

@Around(“execution(public * *(..)) && @annotation(txApply)“)
public Object transactionAround(ProceedingJoinPoint joinPoint, TransactionApply txApply) throws Throwable {

Object retVal = null;
// TODO : Begin Transaction
try {

retVal = joinPoint.proceed();

} catch (Throwable t) {

// TODO : Transaction Roll Back

throw t;

}

//TODO : end Transaction
return retVal;

}

}

package org.simple.aop;
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface TransactionApply {
}

Step4. Apply Custom Annotation

@Service(“SimpleBO”)

public class SimpleBOImpl implements SimpleBO {

@TransactionApply
@Override
public Object updatePolicy(Object param) {

// TODO : select, update, delete in joinPoint.proceed

}

}

Tip : 만약 bean creation 시 다음과 같은 오류가 발생한다면 cglib의 version을 2.2 이상으로 올리는 것을 추천한다.

Caused by: java.lang.NoSuchMethodError: net.sf.cglib.proxy.Enhancer.setInterceptDuringConstruction(Z)V

위 issue의 원인은 cglib 2.0.2 version에서 setInterceptDuringConstruction이라는 Method가 없기 때문이다.

<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-full</artifactId>
<version>2.0.2</version>
</dependency>

2.2 이상으로 설정하면 오류가 사라지며 bean 생성이 정상적으로 이루어짐을 확인할 수 있다.

<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>

Attention : this exam requires cglib version higher than 2.2, aspectj dependency