쿠버네티스를 통해 배포를 하고 있는데, 로컬에서 빌드해서 배포하다보니 디바이스에 이미지가 계속 쌓이면서 공간을 잡아먹는다. (..) 아래 명령어를 가끔씩 쳐주면서 정리중.
$ docker image prune
'프로그래밍' 카테고리의 다른 글
docker 이미지 전체 삭제하기 (0) | 2020.07.03 |
---|
쿠버네티스를 통해 배포를 하고 있는데, 로컬에서 빌드해서 배포하다보니 디바이스에 이미지가 계속 쌓이면서 공간을 잡아먹는다. (..) 아래 명령어를 가끔씩 쳐주면서 정리중.
$ docker image prune
docker 이미지 전체 삭제하기 (0) | 2020.07.03 |
---|
[ECLIPSE/JAVA] 이클립스 컴파일 에러, Java compiler level does not match the version of the installed Java project facet (0) | 2016.12.29 |
---|---|
“Cannot switch on a value of type String for source level below ..” error in Eclipse (0) | 2016.12.29 |
An error occured while filtering resources (0) | 2016.12.19 |
Springframework에서 MySQL 커네션을 잃어버리는 문제 해결 (0) | 2016.12.15 |
STS로 프로젝트 생성 후, resources 폴더에 새로운 폴더를 생성할 때, 패키지로 보이는 문제 해결 방법 (0) | 2016.08.24 |
getClient IP (0) | 2016.07.28 |
I faced the same issue when I tried to deploy using the Ant tool.
The solution that worked for me was:
[ECLIPSE/JAVA] 이클립스 컴파일 에러, Java compiler level does not match the version of the installed Java project facet (0) | 2016.12.29 |
---|---|
“Cannot switch on a value of type String for source level below ..” error in Eclipse (0) | 2016.12.29 |
An error occured while filtering resources (0) | 2016.12.19 |
Springframework에서 MySQL 커네션을 잃어버리는 문제 해결 (0) | 2016.12.15 |
STS로 프로젝트 생성 후, resources 폴더에 새로운 폴더를 생성할 때, 패키지로 보이는 문제 해결 방법 (0) | 2016.08.24 |
getClient IP (0) | 2016.07.28 |
Maven Resource Filtering 사용 시에 An error occured while filtering resources 오류가 발생하는 경우가 있습니다.
이때, 프로젝트 메뉴에서 'Maven > Update Project...' 또는 Alt + F5 를 눌러서 업데이트를 수행하고 나면 에러가 사라집니다.
[ECLIPSE/JAVA] 이클립스 컴파일 에러, Java compiler level does not match the version of the installed Java project facet (0) | 2016.12.29 |
---|---|
“Cannot switch on a value of type String for source level below ..” error in Eclipse (0) | 2016.12.29 |
An error occured while filtering resources (0) | 2016.12.19 |
Springframework에서 MySQL 커네션을 잃어버리는 문제 해결 (0) | 2016.12.15 |
STS로 프로젝트 생성 후, resources 폴더에 새로운 폴더를 생성할 때, 패키지로 보이는 문제 해결 방법 (0) | 2016.08.24 |
getClient IP (0) | 2016.07.28 |
Springframework에서 MySQL을 사용할 때 특정 시점이 지나면 자동으로 커넥션을 잃어버리는 문제가 있다. 이 문제는 Springframework에서 아무런 오랜시간 동안 데이터요청이 없으면 커넥션과 풀링을 해지하는 기능을 가지고 있기 때문인데 이 문제를 해결하기 위한 방법을 소개한다.
이번 프로젝트에서 Springframework + Hiberante + MySQL을 사용하여 프로젝트 개발을 진행하는 도중에 스케줄러가 돌면서 특정 시점이 되어서 아래와 같은 JDBCConnectionException 을 자꾸만 발생하였다. apache의 common-dbcp를 사용해서 dataSource를 하다가 tomcat-jdbc로 교체하여 JNDI(Java Naming and Directory Interface) dataSource로 사용하면서 발생했다. JNDI 방법을 사용하는 것은 이번이 처음이였기 때문에 더구나 지금까지 대부분 Oracle을 사용하다가 Spring framework + MySQL을 처음 다루기에 전에 보지 못한 예외들이 발생하는거라 생각했다. 여러가지 자료를 찾아보다 이 문제는 MySQL이 기본적으로 8시간동안 요청이 없으면 커넥션을 해지하고 풀링을 해지 하기 때문이라는 것을 알게 되었다. 프로젝트에서는 Spring framework의 @Scheduled
를 이용해서 Tomcat 서버에서 스케줄을하는데 웹 요청이 들어오지 않고 JNDI를 이용해서 스케줄에서 Hibernate와 MySQL을 사용해서 생기는 문제로 여겨졌다.
org.springframework.dao.DataAccessResourceFailureException: could not execute query; nested exception is org.hibernate.exception.JDBCConnectionException: could not execute query
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:629)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:912)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:904)
at net.hibrain.apps.push.model.PushProviderDaoImpl.findWillPushDevices(PushProviderDaoImpl.java:50)
at net.hibrain.apps.push.model.PushProviderDaoImpl.insertAllPushDeviceJSON(PushProviderDaoImpl.java:131)
at net.hibrain.apps.push.service.PushProviderServiceImpl.start(PushProviderServiceImpl.java:111)
at net.hibrain.apps.push.service.PushProviderServiceImpl.start(PushProviderServiceImpl.java:61)
at net.hibrain.apps.push.schedule.PushScheduleServiceImpl.startSyncronous(PushScheduleServiceImpl.java:34)
at sun.reflect.GeneratedMethodAccessor47.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:64)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.hibernate.exception.JDBCConnectionException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:97)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2231)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
at org.hibernate.loader.Loader.list(Loader.java:2120)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:921)
at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:1)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
... 22 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 35,986,917 milliseconds ago. The last packet sent successfully to the server was 22 milliseconds ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3102)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2991)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3532)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2293)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1808)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2228)
... 32 more
show global variables like 'wait%';
MySQL은 기본적으로 8시간동안 요청이 없으면 커넥션을 해지한다. 방법은 리소스를 설정하는 MySQL url에다가 autoReconnection=true
로 변경하면 된다. 또는 valdationQuery="select 1"
`을 전처리로 실행하게하면 된다.
<Resource name="jdbc/test_database" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" validationQuery="select 1"
username="ID" password="PASSWORD" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost: 3306/test_database?autoReconnection=true"/>
또는 스프링 프레임워크에서 hibernateProperties
를 설정하는 곳에서 설정하면 된다. 다음은 그 설정 예이다. 이 설정 방법은 다음 블로그에서 참조했다. (http://mimul.com/pebble/default/2008/06/24/1214258760000.html)
<bean id="hibernateProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="hibernate3.hbm2ddl.auto">update</prop>
<prop key="hibernate3.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate3.c3p0.minPoolSize">15</prop>
<prop key="hibernate3.c3p0.maxPoolSize">50</prop>
<prop key="hibernate3.c3p0.timeout">600</prop>
<prop key="hibernate3.c3p0.max_statement">50</prop>
<prop key="hibernate3.c3p0.testConnectionOnCheckin">true</prop>
<prop key="hibernate3.c3p0.testConnectionOnCheckout">false</prop>
<prop key="hibernate3.c3p0.maxStatementsPerConnection">5</prop>
<prop key="hibernate3.c3p0.maxIdleTime">300</prop>
<prop key="hibernate3.c3p0.maxConnectionAge">14400</prop>
<prop key="hibernate3.c3p0.acquireRetryAttempts">10</prop>
<prop key="hibernate3.c3p0.preferredTestQuery">SELECT 1;</prop>
<prop key="hibernate3.c3p0.idleConnectionTestPeriod">300</prop>
<prop key="hibernate3.provider">org.hibernate.connection.C3P0ConnectionProvider</prop>
</props>
</property>
</bean>
이 방법 외에도 /etc/my.cnf
에서도 설정하는 방법도 있고 유지하는 방법 여러가지 있으니 프로젝트에 맞는 방법을 선택하여 사용하면 될것 같다.
“Cannot switch on a value of type String for source level below ..” error in Eclipse (0) | 2016.12.29 |
---|---|
An error occured while filtering resources (0) | 2016.12.19 |
Springframework에서 MySQL 커네션을 잃어버리는 문제 해결 (0) | 2016.12.15 |
STS로 프로젝트 생성 후, resources 폴더에 새로운 폴더를 생성할 때, 패키지로 보이는 문제 해결 방법 (0) | 2016.08.24 |
getClient IP (0) | 2016.07.28 |
Implementing HTTP byte-range requests in Spring MVC 파일 이어받기 서버측 구현 (0) | 2015.10.15 |
이클립스에서 STS를 설치하고, Spring 프로젝트를 생성하고나서
src/main/resources 폴더에 새로운 폴더를 추가하면, 당연히 폴더 아이콘으로 보여야하는데, 패키지로 보이는
경우가 있습니다.
아니! 나는 폴더를 생성했는데, 시방 무슨 패키지가 생성되었어?!?! 라고 생각하시면서, 내가 잘못했나?
다시 해볼까? 하시면서 몇번을 만들어도 똑같을 겁니다.
사실 이건 정상적인 상황으로 실제 프로젝트에는 문제가 없지만, 좀 찜찜하고 눈에 거슬리기도 합니다.
이럴때는 다음과 같이 설정하시면 됩니다.
1. 프로젝트 우클릭 -> Properties
2. Java Build Path -> Source 선택
3. 하단에 있는 /src/main/resources의 Excluded를 선택하고 Edit
4. Exclusion patterns의 Add를 선택하고 ** 를 입력
5. Finish
그럼 다음과 같이 폴더 형식으로 보입니다.
해결 완료!
An error occured while filtering resources (0) | 2016.12.19 |
---|---|
Springframework에서 MySQL 커네션을 잃어버리는 문제 해결 (0) | 2016.12.15 |
STS로 프로젝트 생성 후, resources 폴더에 새로운 폴더를 생성할 때, 패키지로 보이는 문제 해결 방법 (0) | 2016.08.24 |
getClient IP (0) | 2016.07.28 |
Implementing HTTP byte-range requests in Spring MVC 파일 이어받기 서버측 구현 (0) | 2015.10.15 |
[jstl]숫자뒤에 .0 붙이기 int to double (0) | 2015.09.30 |
public static String getClientIpAddr(HttpServletRequest request) {
String ip = request.getHeader("X-Forwarded-For");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
Springframework에서 MySQL 커네션을 잃어버리는 문제 해결 (0) | 2016.12.15 |
---|---|
STS로 프로젝트 생성 후, resources 폴더에 새로운 폴더를 생성할 때, 패키지로 보이는 문제 해결 방법 (0) | 2016.08.24 |
getClient IP (0) | 2016.07.28 |
Implementing HTTP byte-range requests in Spring MVC 파일 이어받기 서버측 구현 (0) | 2015.10.15 |
[jstl]숫자뒤에 .0 붙이기 int to double (0) | 2015.09.30 |
[jstl] 숫자 천단위마다 콤마 찍어 구분 (0) | 2015.09.30 |
MySQL Database의 경우 Oracle 이나 MS SQL Server에 비해서 대용량의 자료를 처리하는 경우가 적기에 튜닝에 필요성이 적은 것 같습니다. 그러나 웹이라는 환경은 많은 사용자가 동시에 접속을 할 수 있기에 항상 모니터링과 최적화는 기본이라고 생각합니다.
본 강좌에서는 기본적인 모니터링 방법과 Connection과 Memory 부분에 대한 튜닝 방법을 소개하도록 하겠습니다.
가. 모니터링 및 초기화 명령어
나. Connection 튜닝
1. status
2. system variables
그외에 status 또는 system variables 값은 참고의 Mysql 메뉴얼을 참조해 주십시요.
mysql> show variables like '%max_connection%'; |
다. Memory 튜닝
1. status
2. system variables
mysql> show status like '%key%'; |
라. 적용
system variables은 my.cnf 또는 my.ini 파일을 수정 후 MySQL Server 를 재시작 해 주십시요.
[www@smson www]$ vi /etc/my.cnf # The MySQL server |
출처 : http://www.albumbang.com/board/board_view.jsp?board_name=free&no=139
MySQL 기본적인 모니터링 방법과 Connection과 Memory 튜닝 방법 (0) | 2016.06.29 |
---|---|
Running a syntax check on /etc/my.cnf (0) | 2016.06.29 |
mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead [duplicate] (0) | 2016.05.11 |
MYSQL에서 랜덤으로 데이터 읽어오기 (0) | 2015.10.01 |