1. 현상
    1. 기존 설치형톰캣 + Spring 3.2 기반의 프로젝트를 Spring boot 1.3.5와 임베디드 톰캣으로 변경하였는데 일정 주기마다 응답이 느려지는 현상이 발생(약, 2~3초)
    2. 다른 프로젝트도 Spring boot로 서비스 중이지만 동일현상이 발생하지 않았음
  2. 의심사항 리스트업
    1. 일정주기 -> ehcache 캐쉬 리로드 타임
    2. 로그백 캐쉬 리로드
    3. 기타 여러가지
  3. 디버깅
    1. 테스트용 URL을 만들어서 call 찍어봄
    2. Spring boot tomcat access로그를 남겨서 응답시간을 남겨봄
    3. 어플리케이션 로그를 DEBUG레벨로 남겨봄
  4. 디버깅을 통한 의심사항 확인
    1. 응답이 느려질 때 어플리케이션 로그에 아래와 같은 딜레이가 발생됨을 확인(3초 가량의 딜레이)
    2. 2016-07-03 12:22:04 [DEBUG] o.a.c.connector.CoyoteAdapter:180 - The variable [semicolon] has value [-1]
      2016-07-03 12:22:04 [DEBUG] o.a.c.connector.CoyoteAdapter:180 - The variable [enc] has value [utf-8]
      2016-07-03 12:22:07 [DEBUG] o.a.c.a.AuthenticatorBase:180 - Security checking request POST 요청URL 블라블라
    3. 해당 시점에 jvm gc를 확인해보니 young gc가 발생 -> GC시점에 느려짐?? -> FULL GC도 아닌데 왜 느려짐? -> 임베디드톰캣 설정이 문제인가??
      1. jstat -gcutil -h10 프로세스ID 1s
      2. 재 확인해보니 꼭 GC발생시점에 느려지지는 않음









파일업로드 Rest full 기능 샘플 소스



@RestController
@RequestMapping ("/file")
public class FileuploadController {

     @Autowired
     private ServletContext context;

     /**
      * 파일 멀티파트 업로드 Rest full
      *
      * @param inputFile
      * @return
      */
     @RequestMapping(value = "/upload", headers = ("content-type=multipart/*" ), method = RequestMethod.POST )
     public ResponseEntity<FileInfo> upload(@RequestParam ("file") MultipartFile inputFile) {

          FileInfo fileInfo = new FileInfo();
          HttpHeaders headers = new HttpHeaders();
           if (!inputFile .isEmpty()) {

               try {

                   String oriFileNm = inputFile.getOriginalFilename();
                   File destinationFile = new File(context.getRealPath("/WEB-INF/uploaded" ) + File.separator + oriFileNm);
                    inputFile.transferTo(destinationFile );
                    headers.add("File Uploaded Successfully - ", oriFileNm);

                    fileInfo.setFileName(destinationFile .getPath());
                    fileInfo.setFileSize(inputFile .getSize());
                    return new ResponseEntity<FileInfo>(fileInfo , headers, HttpStatus.OK );

              } catch (Exception e ) {
                    return new ResponseEntity<FileInfo>(HttpStatus.BAD_REQUEST);
              }
          } else {
               return new ResponseEntity<FileInfo>(HttpStatus.BAD_REQUEST);
          }
     }
}




/**
 * 파일정보 VO
 *
 * @author 엄승하
 */
@Data
public class FileInfo {

     private String fileName;
     private long fileSize ;

}





준비물
 
  1. Centos 다운로드(6.7ver 64bit)
  2. CentOS 다운로드 7 Ver
    1. https://mirror.kakao.com/centos/7.9.2009/isos/x86_64/
  3. Virtual box 다운로드(Windows용)
  4. putty(SSH 접속을 위해 사용)
  5. FilezZila(FTP)
 
 

Virtualbox에 CentOS 설치
  1. Virtualbox를 다운받아서 설치 : https://www.virtualbox.org/
  2. 환경설정
    • 파일->환경설정->입력->호스트 키 조합에서 F12입력


  3. Virutalbox에 CentOS설치
    • 종류는 Linux, 버전은 Red Hat 64-bit로 선택(64bit가 선택항목에 없다면, 바이오스에서 CPU 설정 부분에 있는 인텔 가상화 모드가 꺼져있어서 발생한거니 켜주세요)







    • 가상이미지 삽입하여 설치








    • biz라는 계정 생성 후 암호 설정(앞으로 모든 예제는 biz 계정을 예로 작성)


    • root 계정으로 네트워크 설정을 해주세요
      • 재 부팅시 자동으로 ifup되도록 설정
        • vi /etc/sysconfig/network-scripts/ifcfg-eth0 후 ONBOOT=no를 yes로 수정
 
 
 

외부 SSH 접속을 위한 Virtualbox  설정
 
 

 
 




  1. Putty로 접속성공


  2. SFTP로 접속 성공
 
 
 

 

  1. SVN


  1. SVN 커넥터(Repositories 추가시 설치 창이 뜸)



  1. 인코딩셋 셋팅(웹 개발관련)


4. 에디터에 라인 번호 표시



  1. 톰캣서버 설정






2016-05-31 기준
설치한 플러그린 리스트




import java.io.IOException;
import java.net.URI;

import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.AuthCache;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

/**
 * Jenkins JOB 실행하는 프로그램
 *  - httpclient 4.3.x 이상 필요
 *  - 참고 : https://wiki.jenkins- ci.org/display/JENKINS/Authenticating+scripted+clients
 *
 * @author 엄승하
 */
public class TestCallJenkinsJob {

     public String scrape(String urlString, String username, String password ) throws ClientProtocolException, IOException {

          URI uri = URI.create( urlString);
          HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri .getScheme());
          CredentialsProvider credsProvider = new BasicCredentialsProvider();
           credsProvider.setCredentials(new AuthScope(uri.getHost(), uri .getPort()), new UsernamePasswordCredentials(username , password));

           // Create AuthCache instance
          AuthCache authCache = new BasicAuthCache();

           // Generate BASIC scheme object and add it to the local auth cache
          BasicScheme basicAuth = new BasicScheme();
           authCache.put(host , basicAuth);
          CloseableHttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider( credsProvider).build();
          HttpGet httpGet = new HttpGet(uri);

           // Add AuthCache to the execution context
          HttpClientContext localContext = HttpClientContext.create();
           localContext.setAuthCache(authCache );

          HttpResponse response = httpClient .execute(host, httpGet, localContext );

           return EntityUtils.toString(response.getEntity());

     }

     public static void main(String[] args) {

          String jobUrl = "JOB URL(토큰정보 포함)" ;
          String userNm = "계정ID" ;
          String pwd = "계정 암호" ;

           try {

              String rslt = new TestCallJenkinsJob().scrape(jobUrl , userNm, pwd);
              System. out.println("rslt: " + rslt);

          } catch (IOException e ) {
               e.printStackTrace();
          }
     }

}


/**
 * 문제 : https://codility.com/c/run/training8FKHPA -U9P
 *  - 양의 정수를 입력받아서 2진표현법으로 변환시 표시되는 0의 최대 자릿수 구하기
 *  - 예) 10진수 1041 -> 2진수 -> 10000010001 -> 답은 5
 *
 * @author 
 */
public class Solution {

     public int solution(int n) {

           int maxLength = 0;
           int currentLength = 0;

           while (n > 0) {
               if (n % 2 == 1) { //10진수를 2진수로 변환하는 방법은, 10진수를 2로 나눈 나머지(1또는 0)의 연속숫자이다.
                    currentLength = 0;
              } else {
                    currentLength = currentLength + 1;
              }

               if (currentLength > maxLength) {
                    maxLength = currentLength ;
              }

               n = n / 2;
          }

           return maxLength ;
     }

     public static void main(String[] args) {

           int target = 1041;
           int result = new Solution().solution( target);

          System. out.println("Test " + target + " result is " + result);
     }

}


개발자로 몇 년간 일하면서 많은 정보들이 여러군데 쌓이게 되었습니다.

해당 정보들을 틈틈히 Tsistory로 정리해보려고 합니다.


초대장을 주신 유쾌한삼이(http://iori826.tistory.com)님께 감사드립니다.

+ Recent posts