전체 글
-
Alembic 사용법 (python data migrations)프로그래밍/Python 2024. 5. 5. 11:46
Alembic 이란?Python에서 사용하는 Database Migration Tool주로 Alembic + Sqlarchemy로 사용하여 통합 관리 하게 됩니다.Alembic을 사용하는 이유?보통 개발 할 때 여러 대의 DB를 생성하여 사용합니다.아래 Flow와 같이 Dev와 Prod DB를 일치 시켜야 운영이 가능 할 때 사람이 일일히 수동으로 하는 것이 아니라 Alembic으로 통합하여 다른 사람이라도 똑같은 컨디션의 환경을 제공해주기 위한 툴입니다.spring 진영의 flyway와 비슷 합니다. 차이점이라면 flyway는 변경 정보를 각 테이블에 모두 기록하는 반면, alembic은 마지막에 마이그레이션 된 버전의 해시값만을 기록합니다.alembic DB migrations을 버전의 해시값으로 버..
-
python pyenv로 가상화 환경 만들기프로그래밍/Python 2024. 5. 4. 19:20
pyenv란?먼저 프로젝트 진행 시에 다양한 프로젝트를 개발 하는 경우가 많다. 그럴 때 마다 상황에 맞는 python 버전을 가지고 대응해야 하는데, 하나의 python 버전만 가지고는 많은 프로젝트를 한 컴퓨터에서 진행하기란 어간 쉬운 일이 아니다. 한 프로젝트는 python 3.11 한 프로젝트는 python 3.5버전을 가졌다면, 내장 함수 부터 호환 되는 라이브러리 들이 다 엉켜 있다. 이럴 때 가상화 환경을 사용하여 여러 환경에 대응되는 패키지를 관리하게 되는데 이때 pyenv를 사용하면 좋다pyenv는 system > global > local > pyenv shell로 layer를 가진다. Layer기반으로 범위가 낮아짐으로 system python은 최상위 버전을 아래로 갈 수 록 낮아지..
-
python 패키지 관리를 위한 poetry 패키지 매니저 활용법프로그래밍/Python 2024. 5. 4. 13:10
Poetry란?python에서 사용하는 패키지 매니저임python 개발시 협업을 진행하기 위해 패키지를 맞춰야 하는데 유용함python 패키지 setup하는 용도로도 사용함python lint, flake8에서도 유용한 작용을 함자바와 maven gradle과 같은 기능이라고 보면 됨또한 개발과 배포용에서 굳이 배포 하지 않아도 되는 flake8 같은 패키지는 개발과 배포용으로 구분하여 패키지 관리도 진행 가능하다.Poetry 버전 확인—version으로 버전 확인 후 없으면 설치 하면 된다.# 버전 확인 poetry --version # Poetry (version 1.8.2) # 설치 pip install poetry Poetry로 python 패키지 생성poetry init # or poetry n..
-
[Spark] Postgre의 데이터 JDBC 커넥터 활용하여 병렬 처리 해보기(feat, partitionColumn,lowerBound, upperBound, numPartitions)데이터 엔지니어링/Spark 2023. 2. 12. 14:10
Spark에서 직접 PostgreSql 연결하는 법 Spark는 java기반 오픈 소스 툴이기 때문에 JDBC(Java Database Connectivity)를 이용하여 데이터베이스에 접근 할 수 있습니다. 아래 코드가 JDBC를 이용하여 select를 할 수 있는 상태를 만들어 놓은 것이다. jdbcDF라는 객체를 아래와 같이 만들고 쿼리를 날리면 데이터를 조회 할 수 있습니다. jdbcDF = spark.read \ .format("jdbc") \ .option("url", "jdbc:postgresql:dbname") \ .option("dbtable", "public.tablename") \ .option("user", "username") \ .option("password", "passwor..
-
[Airflow] User_defined_macros를 이용하여 jinja template의 사용자 정의 변수 활용하기데이터 엔지니어링/AirFlow 2023. 2. 12. 13:22
안녕하세요 까치입니다. 오랜만에 Airflow 포스팅을 하게 되었습니다. DAG의 모든 task에서 공통 변수를 활용하는 경우가 많은데 이때 어떻게 해야할지 공부하게 되어 포스팅 하게 되었습니다. 먼저 user_defined_macros라는 속성에 변수를 등록하면 그 당시에 활용하는 DAG안에 공통 변수를 설정 할 수 있습니다. 아래 코드는 완성 코드 입니다. MACROS_VAR에 공통 변수로 활용할 값을 설정하고, DAG안에 user_defined_macros라는 속성에 넣었습니다. from datetime import datetime, timedelta from airflow import DAG from airflow.operators.bash import BashOperator default_arg..
-
[DB] 샤딩(sharding )이란?DB/Modeling 2023. 1. 31. 21:43
샤딩이란? 샤딩이 나온 배경을 먼저 알아보자면, 현대에는 서비스가 증가 속도 및 데이터 증가 속도가 빠르기 때문이다. 서비스와 데이터가 증가함에 따라 과거에 사용하던 모놀리식 방법으로는 급격히 늘어나는 트래픽을 감당하기 어려워 졌다. 그래서 데이터베이스도 여러대의 컴퓨터에서 처리하고 응답을 해주는 것으로 처리 속도를 높였는데, 이것이 바로 샤딩이다. 즉, 샤딩이란 여러 머신에 저장하는 프로세스를 말한다. 데이터를 샤드라고 하는 더 작은 청크로 분할하고 여러 데이터베이스 서버에 저장한다. 샤딩의 장점 응답 시간 - 컴퓨팅이 여러 대이기 때문에 처리 속도가 향상된다. HA의 용이성 - 컴퓨터의 replica를 진행하여 HA구성하기 용이하다. 자원의 효율적인 사용 - 리소스가 작거나 클 때 데이터 베이스를 붙..
-
[DB] 데이터 모델링 - Partitioning(파티셔닝)이란?DB/Modeling 2023. 1. 30. 21:29
파티셔닝이 나온 배경은? 데이터는 시간이 지날수록 증가하는 속성을 가진다. 애플리케이션이 런칭돼고 사이즈가 증가하면서 DB자체가 VLDB(Very Large DB)로 돼게된다. 즉, 데이터의 량이 많아져 한 DB에 데이터를 모으게 돼면, 쿼리문 실행 시 속도가 느려질 뿐만 아니라, 보관 비용도 엄청나게 커지게 된다. 이런 문제를 해결하기 위해서 테이블 단위로 데이터를 나뉘는 방식을 고안하게 되었는데, 이것이 파티셔닝이다. 파티셔닝이란? 데이터 사이즈가 큰 테이블을 두 개 이상의 작은 테이블로 나누는 것을 파티셔닝이라고 한다. 보통 쿼리가 스캔할 데이터의 범위를 좁혀서 응답시간을 빠르게 하기 위한 목적으로 사용한다. 파티셔닝 이점 가용성 - 데이터를 나눠놨기 때문에 하나의 DB가 죽더라도 빠르게 살려 데이..
-
[Kubernetes] Kubernetes Pod란? pod관련 명령어 실습해보기CI-CD/Kubernetes 2023. 1. 21. 16:36
Pod란? Kubernetes는 Container 오케스트레이션 툴인데, Pod는 kubernetes의 Node안에 올라가는 컨테이너 묶음의 단위이다. 위 그림은 Kubernetes 하나의 노드를 나타내는데 여기서 10.10.10.1~4 까지가 각각 Pod이며, 그 안에 컨테이너가 하나 이상 존재 하고, Volume을 이용하여 Storage도 받을 수 있다. Pod 특징 여러개의 컨테이너 묶음 단위이며, 노드에 컨테이너를 실행하는 가장 기본 단위이다. Pod가 생성 되면 유일한 IP주소를 가진다. 이 ip주소는 외부 노출용 주소가 아닌 Cluster에서 사용하며, 동일한 Pod object라도 다시 생성되면 유일한 IP주소는 바뀌고 다시 할당 된다. Pod안에 컨테이너 간 통신은 localhost로 통신..