[컴][swe] 실력있는 프로그래머가 필요한 이유

테스트가 필요한 이유/ 시니어(senior)의 이유 / cs 를 잘알아야 하는 이유/ computer science

실력있는 프로그래머가 필요한 이유

  • Boeing’s 737 Max Software Outsourced to $9-an-Hour Engineers - Bloomberg
    • Max 의 소프트웨어는 보잉이 비용절감을 위해 경험이 많은 엔지니어들을 해고하고, 공급자들을 압박하는 시점에 개발됐다.

      The Max software -- plagued by issues that could keep the planes grounded months longer after U.S. regulators this week revealed a new flaw -- was developed at a time Boeing was laying off experienced engineers and pressing suppliers to cut costs.

    • 전 보잉 소프트웨어 엔지니어 Rabin : 이전의 한 매니저가 보잉의 상품이 안정돼서(mature) 이제 보잉은 시니어 엔지니어가 필요없다고 했다.

      Rabin, the former software engineer, recalled one manager saying at an all-hands meeting that Boeing didn’t need senior engineers because its products were mature. “I was shocked that in a room full of a couple hundred mostly senior engineers we were being told that we weren’t needed,” said Rabin, who was laid off in 2015.

  • “1억 줬다가 9,990만 원 반납하라” 황당 행정 ‘분통’ : https://www.youtube.com/watch?v=tzAFVpIfCCw&t=1049s
    • 해당 자영업자들의 세금자료를 불러와서 보상금을 계산하도록 프로그래밍을 했다.
    • 프로그램을 잘못만들어서 발생 : 영업이익 셀을 불러와야 하는데 다른 셀을 불러와서 잘못된 금액이 지원금으로 나갔다.

See Also

  1. 쿠…sal: [컴] Unit test best practices in C#

[컴] vscode debugger를 사용해서 client nuxtjs 의 debugging

nuxtjs debugging tip /

vscode debugger를 사용해서 client nuxtjs 의 debugging

nuxtjs 를 debugging 할 때

nuxt -H 0.0.0.0 를 이용해서 local server 를 띄워서 작업을 많이 했다.

이 경우 chrome developer tools 에 있는 debugger 를 많이 사용한다. 그런데 이 경우에 source code 에 보이는 variable 이름과 실제 실행되고 있는 코드의 변수명이 틀려서 variable 값을 console 에서 입력해서 확인하기가 어려웠다. 개인적으로 현재상황에선 firefox 의 debugger 가 console 에서 변수를 확인하는 작업은 좀 더 편하게 잘됐던 것 같다.

그리고 요새 아래와 같은 화면이 나오고 소스코드가 제대로 보이지 않았다. 원인찾기가 귀찮아서 일단 그냥 뒀다. 추측은 page 쪽으로 들어간 component 와 관련돼 보이긴 한다.

import { render, staticRenderFns } from "./MyView2.vue?vue&type=template&id=98b14e8e&"
import script from "./MyView2.vue?vue&type=script&lang=js&"
export * from "./MyView2.vue?vue&type=script&lang=js&"
import style0 from "./MyView2.vue?vue&type=style&index=0&lang=css&"


/* normalize component */
import normalizer from "!../../node_modules/vue-loader/lib/runtime/componentNormalizer.js"
var component = normalizer(
  script,
  render,
  staticRenderFns,
  false,
  null,
  null,
  null
  
)

/* hot reload */
if (module.hot) {
  var api = require("D:\\a\\prog\\nodejs\\vue\\myproj\\node_modules\\vue-hot-reload-api\\dist\\index.js")
  api.install(require('vue'))
  if (api.compatible) {
    module.hot.accept()
    if (!api.isRecorded('98b14e8e')) {
      api.createRecord('98b14e8e', component.options)
    } else {
      api.reload('98b14e8e', component.options)
    }
    module.hot.accept("./MyView2.vue?vue&type=template&id=98b14e8e&", function () {
      api.rerender('98b14e8e', {
        render: render,
        staticRenderFns: staticRenderFns
      })
    })
  }
}
component.options.__file = "pages/Test/MyView2.vue"
export default component.exports

여하튼 그래서 chrome 에서 직접 debugger 를 사용하는 것보다는 성능이 별로인 것 같아서 묻어두었던 vscode 를 debugger 를 사용하기로 했다.

사용법

사용법은 간단하다.

  1. 서버띄우기: nuxt -H 0.0.0.0
  2. debugger configuration 만들기 vscode nuxt project 를 열고, F5(Start Debugging)을 하면 된다. 처음실행하면, 아래처럼 configuration 이 하나 만들어진다.
  3. configuration 의 url 설정: 여기서 nuxt -H 0.0.0.0 로 띄운 서버의 ’포트’를 적어주자.
  4. debugger 실행: 다시 F5 를 눌러야 debugger가 실행이 될 것이다.

그러면 이제 chrome 브라우저가 하나뜬다.

이 브라우저에서 동작을 하고, vscode 에서 breakpoint 를 잡으면 된다. 참고로 vscode debugger가 띄운 chrome 을 써야 한다. (debug port 가 그 chrome 하고만 연결되어 있다.) 다른 크롬을 띄우면 당연히 vscode 의 breakpoint 에 걸리지 않는다.

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "pwa-chrome",
            "request": "launch",
            "name": "Launch Chrome against localhost",
            "url": "http://localhost:3000",
            "webRoot": "${workspaceFolder}"
        }
    ]
}

사용 후기

좀 더 vscode debugger 를 써보니, 크롬 디버거에서처럼 특정 line 에 break point 가 걸리지 않는 증상이 보인다. 그리고 code 에 있는 변수명과 달라서 console 창에서 variable 값을 보지 못하는 증상도 똑같이 보였다.

위처럼 hot reload 가 나오는 화면에 대한 breakpoint 도 걸리지 않았다. 다만 이시점에 code가 있는 부분에 새로운 symbol 이 추가되게, function 등을 추가하면, 다시 reload 하면서 이미 지정해 놓았던 breakpoint 가 걸리는 경우가 있었다. 새롭게 지정하는 breakpoint 는 여전히 안된다.( 이것은 npm run dev 등 hot reload 가 되는 서버를 사용할 때만 되는듯.)

하지만, vscode 를 debugger 로 쓰면서 debugger 화면, 소스 등이 확실히 편해지긴했다. 아직은 한가지만 쓸 수는 없을 듯 하다. 대체로 vscode 로 사용하다가 chrome debugger 가 필요하면 써야 할 것 같다.

See Also

  1. 쿠…sal: [컴] nuxtjs 에서 sourcemap 생성방법
  2. Debugging Nuxt.js with VS Code. I have been using Nuxt.js recently for… | by Les Harris | Vue.js Developers | Medium : nustjs 서버파트에 대한 디버깅 이야기도 있다.

[컴][안드로이드] library 에서 getSharedPreferences 동작하다가 NullPointerException

 안드로이드 이슈 / 갑자기

library 에서 getSharedPreferences 동작하다가 NullPointerException

아래처럼 크게 문제가 없는 library 등이 갑자기 getSharedPreferences 로 접근하다가 죽는 경우가 있다.

이유는 명확치 않으나, 아래 case 들을 보면 대체로 timing 이슈가 아닌가 생각된다.

나중에 혹시나 더 자세한 사항을 발견하게 되면 정리한다. 지금은 여기까지

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.UserManager.isUserUnlockingOrUnlocked(int)' on a null object reference
        at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:418)
        at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:404)
        at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:174)

case 1

아래처럼 getSharedPreferences를 사용하는데,

sharedPref = getApplicationContext().getSharedPreferences("FlutterSharedPreferences",Context.MODE_PRIVATE|Context.MODE_MULTI_PROCESS);
...
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.UserManager.isUserUnlockingOrUnlocked(int)' on a null object reference
        at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:418)
        at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:404)
        at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:174)
        at com.example.demo1.MorningReset.onStartCommand(MorningReset.java:25)

service 에서 SharedPreference 를 접근하면 문제가 된다고 한다.

그리고 Activity 에서 접근할 때는 문제가 없다고 한다.

case 2

카카오 sdk 에서도 비슷한 문제가 발생했는데, 이 글에서는

  • 기기 상관없이 os version 이 높은 (ANDROID 9, 10, 11 ) 에서 나타난다

고 한다.

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean android.os.UserManager.isUserUnlockingOrUnlocked(int)’ on a null object reference
at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:466)
at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:441)
at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:179)
at com.kakao.sdk.common.model.ApplicationContextInfo.(ApplicationContextInfo.kt:43)
at com.kakao.sdk.common.KakaoSdk.init(KakaoSdk.kt:87)
at com.kakao.sdk.common.KakaoSdk.init(KakaoSdk.kt:59)
at com.kakao.sdk.common.KakaoSdk.init$default(KakaoSdk.kt:57)
at com.kakao.sdk.common.KakaoSdk.init(Unknown Source:9)
at com.gradehealthchain.log.LogApp.onCreate(pk:165)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6222)
at android.app.ActivityThread.access$1200(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1785)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7050)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

case 3

firebase init 에서도 비슷한 이슈가 있었는데 꽤나 최근 답변이다.(2021-05-07)

댓글에 Activity 로 firebase init 을 옮겼다고 한다. 그리고 firebaseApp 전에 isolate 을 초기화 시켰다.

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.UserManager.isUserUnlockingOrUnlocked(int)' on a null object reference
        at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:457)
        at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:443)
        at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:178)
        at com.google.firebase.FirebaseApp.<init>(com.google.firebase:firebase-common@@16.0.2:528)
        at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.2:355)
        at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.2:324)
        at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.2:310)
        at com.test.process.App.onCreate(App.java:32)

case 4

05-05 21:58:27.253 21830 21882 E FA      : java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.UserManager.isUserUnlockingOrUnlocked(int)' on a null object reference
05-05 21:58:27.253 21830 21882 E FA      : at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:485)
05-05 21:58:27.253 21830 21882 E FA      : at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:462)
05-05 21:58:27.253 21830 21882 E FA      : at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:184)

[컴][테스트] 부하테스트 vs 스트레스 테스트

load test / load / hard load/ performance test

Load test vs Stress test

부하테스트(load test) 는

  • 현재 시스템의 임계치(upper limit)를 찾아내는 것
    • 만약 파일 에디터라면, 거대한 파일을 처리해 본다.
  • service level agreement(SLA) 를 산정하고,
  • 어떻게 시스템이 heavy load 를 처리할 수 있는지 체크하는 것

스트레스 테스트는

  • failure 가 났을때 어떻게 복구되는지 확인한다.
    • 간단하게 서버가 작업중에 서버를 죽인다. 이 경우 어떻게 서버가 살아나는지, 저장하던 데이터는 어떻게 되는지, 죽어있는 동안에 못받은 데이터는 어떻게 하는지등

부하테스트 툴

ref. 2 에 오픈소스 부하테스트 툴이 나와있다.

  1. JMeter : apache jmeter: https://jmeter.apache.org/download_jmeter.cgi
    • 가장 유명한 툴 원하는 대부분의 테스트가 가능하다.
  2. Taurus : https://github.com/Blazemeter/taurus
    • YAML 로 테스트 스크립트르 만들수 있게 해준다. JMeter 등의 테스트툴을 이용하기 쉽게 해준다. 상위 layer 를 하나 만들어주는 느낌으로 이해하면 된다.
  3. Locust :https://github.com/locustio/locust
    • event driven tool , JMeter 는 thread 기반
    • 파이썬으로 스크립를 작성할 수 있다고 함.

Reference

  1. Load Testing vs Stress Testing vs Performance Testing: Difference Discussed, 2022-02-19
  2. 15 Top Load Testing Tools for 2021 (Open Source Guide), 2021-03-23

[컴] GeoLite2, ip 주소 위치정보 데이터베이스

geo location / 위치정보 / ip lookup table / ip 지역 정보 / ip 위치

GeoLite2

  • GeoLite2 database들은 IP geolocation db들이다.
  • MaxMind의 GeoIP2 DB 보다는 덜 정확하다.
  • GeoLite2 Country, City, and ASN databases 는 매주 화요일에 update 된다.

정확도

IP geolocation 은 본질적으로 부정확하다. 이 위치정보로는 특정 주소나 가구(household) 를 구분할 수 없다.

Accuracy Radius 를 위도, 경도에 대한 geolocation 정확도의 지표로 사용해라.

아래 표를 보면, 위도(latitude), 경도(longitude) 를 얻으려면 GeoLite2 City 를 이용해야 한다.

license

GeoLite2 는 상업적으로 재배포해도 된다.

download

geolite2 를 download 하려면 login 을 해야 한다. 계정은 다음 link 에서 생성할 수 있다.

다른 download links:

MaxMind 에서 2가지 포맷을 지원한다. 1개는 MMDB, 한개는 CSV

.mmdb

References

  1. GeoLite2 Country, City, and ASN databases

[컴] Java Reactor, Threading model

리액터 , rxjava, rxjs

Java Reactor, The threading model

reactor 명령어들은 일반적으로 concurrent agnostic (concurrent 대해서 몰라도 잘 사용할 수 있는)이다. 특정한 thrading model 을 가지고 있진 않다. 단순히 Thread 에서 실행된다. 그 쓰레드에서 그들의 onNext method 가 호출된다.

scheduler 를 통해 user 가 thread 를 통제할 수 있다.

map 연산자는 source thread 에서 실행된다. map 이 수행되기 전에 publishOn 에 넣는 것은 source thread 를 변경하게 된다.

누군가에 의해 만들어진 stream 을 이용하는 경우는 subscribeOn 으로 할 수 있다. source thread 를 변경할 수 있다.

subscribeOn(Schedulers.boundedElastic()) .subscribe(body -> System.out.println() ) 을 사용하면 subscribe call 을 main thread 에서 수행되지만, lamda 는 (System.out.println 이 있는 code block) 새초운 thread 에서 수행된다.

Rederences

  1. Flight of the Flux 3 - Hopping Threads and Schedulers