負荷ベンチマークツール wrk てシンプルで良いなあ

👉 WordPress で cf-cache-status: BYPASS のままで HIT にならない

シンプルで使いやすい感じ。


❯ wrk -v
wrk 4.2.0 [kqueue] Copyright (C) 2012 Will Glozer
Usage: wrk <options> <url>
  Options:
    -c, --connections <N>  Connections to keep open
    -d, --duration    <T>  Duration of test
    -t, --threads     <N>  Number of threads to use

    -s, --script      <S>  Load Lua script file
    -H, --header      <H>  Add header to request
        --latency          Print latency statistics
        --timeout     <T>  Socket/request timeout
    -v, --version          Print version details

  Numeric arguments may include a SI unit (1k, 1M, 1G)
  Time arguments may include a time unit (2s, 2m, 2h)


❯ wrk https://android.benigumo.com
Running 10s test @ https://android.benigumo.com
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   237.81ms  226.51ms   1.77s    88.62%
    Req/Sec    27.29     15.51    70.00     61.59%
  480 requests in 10.05s, 47.63MB read
  Socket errors: connect 0, read 0, write 0, timeout 2
Requests/sec:     47.77
Transfer/sec:      4.74MB

Lua とか合わせて使えるらしいので便利だろうと思えます。

👉 wg/wrk: Modern HTTP benchmarking tool


WordPress で cf-cache-status: BYPASS のままで HIT にならない

私の場合だけども、cloudflare で。


❯ curl -sI https://android.benigumo.com/ | grep 'cf-cache'
cf-cache-status: BYPASS

どうやっても「HIT」にならない。

レスポンスヘッダーに set-cookie があると cloudflare のキャッシュが効かなくなるらしい。

Additionally, the following headers have given me grief with CF in the past, they should not be present:

Set-Cookie

👉 CF-CACHE-STATUS showing BYPASS - Website, Application, Performance - Cloudflare Community

確認すると、謎の cookie セットがある。


❯ curl -sI https://android.benigumo.com/
HTTP/2 200
date: Sun, 02 Feb 2025 06:42:13 GMT
content-type: text/html; charset=UTF-8
vary: Accept-Encoding
vary: accept, content-type
set-cookie: 6666cd76f96956469e7be39d750cc7d9=1738478533; expires=Sun, 02-Feb-2025 07:42:13 GMT; Max-Age=3600; path=/

web リソース内を grep して、

あやしそうなプラグインを特定後、無効化しながら確認する。

私の場合は、中華産プラグインでした。

削除後。


❯ curl -sI https://android.benigumo.com/ | grep 'cf-cache'
cf-cache-status: HIT

1秒あたり15リクエストしか返せなかったのが、

キャシュが効いて71リクエストを返せるようになりました!


❯ wrk https://android.benigumo.com
Running 10s test @ https://android.benigumo.com
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   201.93ms  252.04ms   1.57s    88.06%
    Req/Sec    38.47     20.07    90.00     63.01%
  713 requests in 10.03s, 68.66MB read
  Socket errors: connect 0, read 0, write 0, timeout 1
Requests/sec:     71.06
Transfer/sec:      6.84MB

Cloudfrare プラグインは有料化への誘導なだけなので、

記事の更新や追加時のキャッシュのパージは手動で行います。


【Kotlin】Android アプリ 課金実装時の ProductDetails や Purchase の内容

公式ドキュメントの解読には骨が折れる。

詳細どんなものが含まれているのか。

Timber ですが、純正 Log でもいけるので置き換えてどうぞ。

👉 JakeWharton/timber: A logger with a small, extensible API which provides utility on top of Android's normal Log class.


android.intent.action.MY_PACKAGE_REPLACED をBorodcastReceiver で反応させるテスト

Debug でなく Run ボタンでいけてたような気がするが
セキュリティの絡みか、今では反応がない。

なので、

コマンドラインで adb から。


❯ adb shell am broadcast -a android.intent.action.MY_PACKAGE_REPLACED
Broadcasting: Intent { act=android.intent.action.MY_PACKAGE_REPLACED flg=0x400000 }

Exception occurred while executing 'broadcast':
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MY_PACKAGE_REPLACED from pid=6153, uid=2000

ダメですか。

またセキュリティですか。

 

🤔 解決法

一度、ビルドして、 apk をインストールしたらいけた。

Go to Build -> Build APK, and note the location that the .apk is stored.

Then, run in terminal:

adb install -r debugapp.apk

This will trigger the MY_PACKAGE_REPLACED intent, since newer Android SDKs only allow the system to broadcast it.

👉 Android: Broadcast ACTION_MY_PACKAGE_REPLACED never received - Stack Overflow

-r」いるんかね ? いらなくね ?

 

🤔 まとめ

今後以下でやろう。


❯ ./gradlew assembleDebug  
                         
> Configure project :app
BUILD SUCCESSFUL in 59s
42 actionable tasks: 21 executed, 21 up-to-date

❯ find . -name "*.apk" | fzf | xargs adb install

Performing Streamed Install
Success

❯ adb shell am start -a android.intent.action.MAIN -n YOUR_PACKAGE/.TARGET_ACTIVITY 

Starting: Intent { act=android.intent.action.MAIN cmp=YOUR_PACKAGE/.TARGET_ACTIVITY }

当然、バージョン番号は上げておかなければなりません。

👉 junegunn/fzf: :cherry_blossom: A command-line fuzzy finder


【Jetpack Compose】メールアプリを最も簡単に開く方法

指定したURLでWEBブラウザを開くならこう書けます。


@Composable
fun OpenLinkButton(
  urlHandler: UriHandler = LocalUriHandler.current
) {
  Button(
    onClick = {
      urlHandler.openUri("https://android.benigumo.com/")
    }
  ) {
    Text("Open Web link")
  }
}

では、

指定した宛先メールアドレスでメールアプリを開く場合。


@Composable
fun OpenMailAppButton(
  urlHandler: UriHandler = LocalUriHandler.current
) {
  Button(
    onClick = {
      urlHandler.openUri("mailto:[email protected]")
    }
  ) {
    Text("Open Mail App")
  }
}

旧来の Intent は Jetpack Compose では使わないことが多くなってきました!

👉 顔文字 (かおもじ) パック - Google Play のアプリ