普通视图

发现新文章,点击刷新页面。
昨天以前ikeno blog

mac软件推荐

2024年12月13日 08:00

2024年度最香产品:MAC MINI M4 正式登场! 经过几天的抢购,我终于在京东买到了 MAC MINI M4,发货等了一个月。到手后折腾了几天,虽然新鲜劲儿过了,但作为办公电脑,它的表现还是不错的。 回想上次用 Mac Mini 是在 M1 刚发售时,买来玩了几个月,最后发现自己并没有太大需求,于是出掉了。这次我以 3500 元的价格再买了一台 M4,希望它能作为我的工作电脑。

废话不多说,下面是我这边记录的一些已安装的软件,都是一些必备的好用软件:

  1. Microsoft Office/Excel/PPT 三件套 办公必备,没啥好介绍的,工作中一定会用到,比 WPS 好用多了。

  2. BetterDisplay 我用的是 4K 显示器,分辨率适配后字体变得非常小,图标和软件也显得很小。为了不降低分辨率,我使用了 BetterDisplay,这个软件不仅能调整分辨率,还能修改亮度,算是一个不错的解决方案。

  3. 超级右键 Mac 里的复制、粘贴、删除等操作相比 Windows 确实不那么顺手。超级右键可以扩展右键功能,例如直接快速打开常用目录、删除文件、新建文件、剪切粘贴等,使用起来非常便利。

  4. VSCode 宇宙第一 IDE,不解释。

  5. Termius 用来登录服务器。Windows 上一般使用 MobaXterm,因此在 Mac 上也想找一个好用的终端,最终发现 Termius 非常好用。

  6. 有道翻译 主要用于划词翻译,记单词、翻译句子等,算是学习英语的工具。不过有时复制时容易误点。

  7. Chrome 习惯了跨系统的多端浏览器同步书签,所以还是选择 Chrome 浏览器。

  8. CotEditor 我想找一个类似 Notepad++ 的轻量级文本编辑器。试了几个 Atom 之类的,感觉都太繁琐。后来在商店里发现 CotEditor,确实不错,功能够用。

  9. Pixea 比系统自带的图片浏览器好用,简洁方便。

  10. ClashX 懂的都懂,实用的梯子。

  11. Keeweb 密码管理软件,使用体验还不错。

希望这些软件能对使用 Mac Mini 的朋友们有所帮助!

2023sumppary

2023年12月28日 08:00

迟来的2023年终总结:

<audio controls> <source src="http://music.163.com/song/media/outer/url?id=409872504.mp3" type="audio/mpeg"> </audio>

关于工作

工作今年算运气不错吧,去年年底被裁员后,本来以为以咱的垃圾学历和技术,再加上互联网寒冬,估计要失业蛮久的。但运气看来还好,不到一个月就找到了新公司,薪资变化不大,不加班,标准的975,比之前公司感觉好了很多。好像我找工作一直都运气蛮好的,平均面试3次基本上都有一次可以过,毕业到现在也有8年多了吧,从上海到深圳,换了也有4家公司了,这是第五家了,平均2年一家公司,然后有一家是被裁员,也算是什么都经历过了。也不清楚程序员这行能干多久,有存款才有勇气。

关于开发

今年工作有了时间,就想着完成一些以前就想做的开发项目了,博客也算之一,所以就有了这个博客,虽然是用的开源的框架,但也弄了些自己的东西,例如分享啊,数据统计啊,评论,域名,CDN什么的,虽然没什么流量,但在网络上有了自己的一个网站还是蛮开心的。

除了博客外因为今年chatgpt的普及,很多以前很费时间的技术都可以简单的开发了,例如前端页面之类的,虽然技术力有限,但还是弄了一个chrome插件游戏来玩玩,还是蛮有趣的,以后有好点子说不定还可以继续开发一些好玩的浏览器插件。

关于旅游

今年总算可以正常出国旅游了,5月去了上海玩3天,10月去了东京-京都-大阪玩了8天。抛开工作烦恼和国内的压力,能到国外享受旅游真的很放松,看什么都很新鲜。就是国庆旅游花费贵了些,明年应该会办理三年多次的签证,以后淡季去玩应该会便宜很多。希望明年可以有另一半可以一起旅游hh

关于游戏

看了下PlayStation的游玩记录,今年竟然都没有超过10小时的ps5游戏时间,甚至都弄不出年度游玩报告,看来今年大部分时间都是在玩电脑和手游了,现在独占游戏越来越少,steam价格也便宜,还可以打mod。看来以后主机的使用率应该还会变低。明年还有老头环DLC、碧蓝幻想relink、黑神话,还是蛮期待的。

最后

感觉也没啥总结的了,希望明年越来越好吧,暴富!脱单!

AI绘画工具webui简单入门 之 高清化

2023年3月19日 08:00

Webui直接生成出来的图会很模糊,而且有些地方细节不是很好,如果用作4k壁纸会感觉很别扭,所以需要高清修复。

步骤

打开webui的图生图,调整参数为:

  • 缩放模式:拉伸
  • 采样方法(Sampler):DPM adaptive
  • 宽度和高度在原有的基础上+64 :1280*720 --> 1344*784
  • 重绘幅度(Denoising):0.15
  • 脚本:使用SD放大(SD upscale)
  • 放大算法:R-ESRGAN 4x+ Anime6B

其他参数默认即可,最后点击生成等待成果吧!

放大前:

放大前|inline

放大后:

放大后|inline

其他

最后再推荐一个网站,如果想要把生成的图做壁纸的话,可以把动漫图片用算法最大放大到2k甚至4K。
waifu2x

写在地下城邂逅Ⅳ·灾厄篇·完结之后

2023年3月18日 08:00

BGM

TV动画《期待在地下城邂逅有错吗 Ⅳ 深章 灾厄篇》片尾曲 切り傷
歌手:sajou no hana

<audio controls> <source src="http://music.163.com/song/media/outer/url?id=2024541034.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio>

感想

地错第四季也终于完结啦,新番里最好看的,不枉我每周四蹲首播啃生肉看完,这一季完完整整的把小说第14卷全部一次性讲完啦,完全是琉主场,琉的过去,眷族团灭的原因以及琉内心的变化,

最后也终于释怀了自己的过去,找到了属于自己的正义! 加入白兔后宫团(不是

不得不给节操社(J.C.STAFF)点个赞,还是保持了一贯的高制作水准,没有特别的崩坏,这一季看下来不管是剧情节奏还是画面音乐都非常棒!果然很喜欢这种王道的剧情啊,男孩与女孩的相遇,互相拯救的故事什么的,真是太棒了!

最后一幕琉的笑容真的太 太 太好看啦!

最近也把新的18卷小说看完了,白兔终于也到level5了,女神芙蕾雅线故事的高潮阶段也终于全部讲完,最后琉Level6救场的场景太帅啦!最后还直球告白贝尔!我宣布,琉股暴涨!诸君,我喜欢elf!

琉|inline

最后

外传剑姬神圣谭13 14卷貌似也快出了,看来大森真的想把每一个地错的角色魅力和眷族故事都展示出来,大森你给点力,学学某河马打字机,多出点!孩子爱看!

AI绘画工具webui简单入门 之 工具安装

2023年3月14日 08:00

工具下载地址:

stable-diffusion-webui (推荐)

1.下载完成后运行webui-user.bat文件,会下载相关的依赖,国内网络可能需要翻墙或者用镜像站(修改launch.py文件把github地址都改为国内的镜像站地址),也可以推荐dev-sidecar这个免费工具加速github。 或者可以直接上b站检索秋葉aaakiup主,直接下载整合包,再或者直接下载第三方客户端

2.安装完成后再运行webui-user.bat文件后等待出现Running on local URL: http://127.0.0.1:7860 就可以访问127.0.0.1:7860打开webui页面啦。

3.打开后先别急,需要安装一些基础的插件,点击扩展,从网址安装,然后把git地址粘贴后安装即可,我这边推荐几个最常用的:

汉化插件 安装完后:setting >> user interface >> Localization (requires restart) >> 选择 zh-CN >> apply setting >> reload ui

Control插件 用来加载lora相关模型。

关键字补全插件 用来补全prompt关键字的,适合英文小白~

4.安装完成后到设置里的显示所有页面快捷设置列表填写sd_model_checkpoint,sd_vae然后重启webui,基础工具就安装好啦,接下来就是模型了!

模型下载地址:

Civitai

1.注册好账号后就可以查看很多网上分享的模型,找一个你最喜欢的,例如Counterfeit,点击下载即可。

2.下载好后记得要把模型放到 \webui\models\Stable-diffusion 目录下,这样才会读取到模型,Lora的模型要放到\webui\models\Lora里,有模型后就可以生成AI图片啦!

当然只是简单的模型还是不够的,后续进阶还需要用到vae模型,EasyNegative模型,lora模型,openpose模型,高清化等,这个后续有时间再梳理下,慢慢学习进步!

分享例子:

关键字: ((masterpiece,best quality)),1girl, solo, animal ears, rabbit, barefoot, knees up, dress, sitting, rabbit ears, short sleeves, looking at viewer, grass, short hair, smile, white hair, puffy sleeves, outdoors, puffy short sleeves, bangs, on ground, full body, animal, white dress, sunlight, brown eyes, dappled sunlight, day, depth of field

Negative关键字: EasyNegative, extra fingers,fewer fingers,

Steps: 20, Sampler: DPM++ 2M Karras, CFG scale: 10, Seed: 414619472, Size: 512x728, Model hash: 59ea4aa1d8, Model: cetusMix_cetusVersion3, Denoising strength: 0.7, Hires upscale: 2, Hires steps: 20, Hires upscaler: SwinIR_4x

兔子|inline

Markdown Example

2022年10月1日 08:00

An h1 header

Paragraphs are separated by a blank line.

2nd paragraph. Italic, bold, and monospace. Itemized lists look like:

  • this one
  • that one
  • the other one

Note that --- not considering the asterisk --- the actual text content starts at 4-columns in.

Block quotes are written like so.

They can span multiple paragraphs, if you like.

Use 3 dashes for an em-dash. Use 2 dashes for ranges (ex., "it's all in chapters 12--14"). Three dots ... will be converted to an ellipsis. Unicode is supported. ☺

An h2 header

Here's a numbered list:

  1. first item
  2. second item
  3. third item

Note again how the actual text starts at 4 columns in (4 characters from the left side). Here's a code sample:

# Let me re-iterate ...
for i in 1 .. 10 { do-something(i) }

As you probably guessed, indented 4 spaces. By the way, instead of indenting the block, you can use delimited blocks, if you like:

define foobar() {
    print "Welcome to flavor country!";
}

(which makes copying & pasting easier). You can optionally mark the delimited block for Pandoc to syntax highlight it:

import time
# Quick, count to ten!
for i in range(10):
    # (but not *too* quick)
    time.sleep(0.5)
    print i

An h3 header

Now a nested list:

  1. First, get these ingredients:

    • carrots
    • celery
    • lentils
  2. Boil some water.

  3. Dump everything in the pot and follow this algorithm:

     find wooden spoon
     unimage pot
     stir
     image pot
     balance wooden spoon precariously on pot handle
     wait 10 minutes
     goto first step (or shut off burner when done)
    

    Do not bump wooden spoon or it will fall.

Notice again how text always lines up on 4-space indents (including that last line which continues item 3 above).

Here's a link to a website, to a local doc, and to a section heading in the current doc. Here's a footnote [^1].

[^1]: Footnote text goes here.

Tables can look like this:

size material color


9 leather brown 10 hemp canvas natural 11 glass transparent

Table: Shoes, their sizes, and what they're made of

(The above is the caption for the table.) Pandoc also supports multi-line tables:


keyword text


red Sunsets, apples, and other red or reddish things.

green Leaves, grass, frogs and other things it's not easy being.


A horizontal rule follows.


Here's a definition list:

apples : Good for making applesauce. oranges : Citrus! tomatoes : There's no "e" in tomatoe.

Again, text is indented 4 spaces. (Put a blank line between each term/definition pair to spread things out more.)

Here's a "line block":

| Line one | Line too | Line tree

and images can be specified like so:

Inline math equations go in like so: $\omega = d\phi / dt$. Display math should get its own line and be put in in double-dollarsigns:

$$I = \int \rho R^{2} dV$$

And note that you can backslash-escape any punctuation characters which you wish to be displayed literally, ex.: `foo`, *bar*, etc.

Include Video in the Posts

2022年8月1日 08:00

Just copy the embed code from YouTube or other platforms, and paste it in the markdown file.

---
title: Include Video in the Post
published: 2023-10-19
// ...
---

<iframe width="100%" height="468" src="https://www.youtube.com/embed/5gIf0_xpFPI?si=N1WTorLKL0uwLsU_" title="YouTube video player" frameborder="0" allowfullscreen></iframe>

YouTube

<iframe width="100%" height="468" src="https://www.youtube.com/embed/5gIf0_xpFPI?si=N1WTorLKL0uwLsU_" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>

Bilibili

<iframe width="100%" height="468" src="//player.bilibili.com/player.html?bvid=BV1fK4y1s7Qf&p=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>

Markdown Extended Features

2022年5月1日 08:00

GitHub Repository Cards

You can add dynamic cards that link to GitHub repositories, on page load, the repository information is pulled from the GitHub API.

::github{repo="Fabrizz/MMM-OnSpotify"}

Create a GitHub repository card with the code ::github{repo="<owner>/<repo>"}.

::github{repo="saicaca/fuwari"}

Admonitions

Following types of admonitions are supported: note tip important warning caution

:::note Highlights information that users should take into account, even when skimming. :::

:::tip Optional information to help a user be more successful. :::

:::important Crucial information necessary for users to succeed. :::

:::warning Critical content demanding immediate user attention due to potential risks. :::

:::caution Negative potential consequences of an action. :::

Basic Syntax

:::note
Highlights information that users should take into account, even when skimming.
:::

:::tip
Optional information to help a user be more successful.
:::

Custom Titles

The title of the admonition can be customized.

:::note[MY CUSTOM TITLE] This is a note with a custom title. :::

:::note[MY CUSTOM TITLE]
This is a note with a custom title.
:::

GitHub Syntax

[!TIP] The GitHub syntax is also supported.

> [!NOTE]
> The GitHub syntax is also supported.

> [!TIP]
> The GitHub syntax is also supported.

Simple Guides for Fuwari

2022年4月1日 08:00

image image source: Source

This blog template is built with Astro. For the things that are not mentioned in this guide, you may find the answers in the Astro Docs.

Front-matter of Posts

---
title: My First Blog Post
published: 2023-09-09
description: This is the first post of my new Astro blog.
image: ./image.jpg
tags: [Foo, Bar]
category: Front-end
draft: false
---
Attribute Description
title The title of the post.
published The date the post was published.
description A short description of the post. Displayed on index page.
image The image image path of the post.<br/>1. Start with http:// or https://: Use web image<br/>2. Start with /: For image in public dir<br/>3. With none of the prefixes: Relative to the markdown file
tags The tags of the post.
category The category of the post.
draft If this post is still a draft, which won't be displayed.

Where to Place the Post Files

Your post files should be placed in src/content/posts/ directory. You can also create sub-directories to better organize your posts and assets.

src/content/posts/
├── post-1.md
└── post-2/
    ├── image.png
    └── index.md

Markdown Extended Features

2024年5月1日 08:00

GitHub Repository Cards

You can add dynamic cards that link to GitHub repositories, on page load, the repository information is pulled from the GitHub API.

::github{repo="Fabrizz/MMM-OnSpotify"}

Create a GitHub repository card with the code ::github{repo="<owner>/<repo>"}.

::github{repo="saicaca/fuwari"}

Admonitions

Following types of admonitions are supported: note tip important warning caution

:::note Highlights information that users should take into account, even when skimming. :::

:::tip Optional information to help a user be more successful. :::

:::important Crucial information necessary for users to succeed. :::

:::warning Critical content demanding immediate user attention due to potential risks. :::

:::caution Negative potential consequences of an action. :::

Basic Syntax

:::note
Highlights information that users should take into account, even when skimming.
:::

:::tip
Optional information to help a user be more successful.
:::

Custom Titles

The title of the admonition can be customized.

:::note[MY CUSTOM TITLE] This is a note with a custom title. :::

:::note[MY CUSTOM TITLE]
This is a note with a custom title.
:::

GitHub Syntax

[!TIP] The GitHub syntax is also supported.

> [!NOTE]
> The GitHub syntax is also supported.

> [!TIP]
> The GitHub syntax is also supported.

Simple Guides for Fuwari

2024年4月1日 08:00

Cover image source: Source

This blog template is built with Astro. For the things that are not mentioned in this guide, you may find the answers in the Astro Docs.

Front-matter of Posts

---
title: My First Blog Post
published: 2023-09-09
description: This is the first post of my new Astro blog.
image: ./cover.jpg
tags: [Foo, Bar]
category: Front-end
draft: false
---
Attribute Description
title The title of the post.
published The date the post was published.
description A short description of the post. Displayed on index page.
image The cover image path of the post.<br/>1. Start with http:// or https://: Use web image<br/>2. Start with /: For image in public dir<br/>3. With none of the prefixes: Relative to the markdown file
tags The tags of the post.
category The category of the post.
draft If this post is still a draft, which won't be displayed.

Where to Place the Post Files

Your post files should be placed in src/content/posts/ directory. You can also create sub-directories to better organize your posts and assets.

src/content/posts/
├── post-1.md
└── post-2/
    ├── cover.png
    └── index.md

Markdown Example

2023年10月1日 08:00

An h1 header

Paragraphs are separated by a blank line.

2nd paragraph. Italic, bold, and monospace. Itemized lists look like:

  • this one
  • that one
  • the other one

Note that --- not considering the asterisk --- the actual text content starts at 4-columns in.

Block quotes are written like so.

They can span multiple paragraphs, if you like.

Use 3 dashes for an em-dash. Use 2 dashes for ranges (ex., "it's all in chapters 12--14"). Three dots ... will be converted to an ellipsis. Unicode is supported. ☺

An h2 header

Here's a numbered list:

  1. first item
  2. second item
  3. third item

Note again how the actual text starts at 4 columns in (4 characters from the left side). Here's a code sample:

# Let me re-iterate ...
for i in 1 .. 10 { do-something(i) }

As you probably guessed, indented 4 spaces. By the way, instead of indenting the block, you can use delimited blocks, if you like:

define foobar() {
    print "Welcome to flavor country!";
}

(which makes copying & pasting easier). You can optionally mark the delimited block for Pandoc to syntax highlight it:

import time
# Quick, count to ten!
for i in range(10):
    # (but not *too* quick)
    time.sleep(0.5)
    print i

An h3 header

Now a nested list:

  1. First, get these ingredients:

    • carrots
    • celery
    • lentils
  2. Boil some water.

  3. Dump everything in the pot and follow this algorithm:

     find wooden spoon
     uncover pot
     stir
     cover pot
     balance wooden spoon precariously on pot handle
     wait 10 minutes
     goto first step (or shut off burner when done)
    

    Do not bump wooden spoon or it will fall.

Notice again how text always lines up on 4-space indents (including that last line which continues item 3 above).

Here's a link to a website, to a local doc, and to a section heading in the current doc. Here's a footnote [^1].

[^1]: Footnote text goes here.

Tables can look like this:

size material color


9 leather brown 10 hemp canvas natural 11 glass transparent

Table: Shoes, their sizes, and what they're made of

(The above is the caption for the table.) Pandoc also supports multi-line tables:


keyword text


red Sunsets, apples, and other red or reddish things.

green Leaves, grass, frogs and other things it's not easy being.


A horizontal rule follows.


Here's a definition list:

apples : Good for making applesauce. oranges : Citrus! tomatoes : There's no "e" in tomatoe.

Again, text is indented 4 spaces. (Put a blank line between each term/definition pair to spread things out more.)

Here's a "line block":

| Line one | Line too | Line tree

and images can be specified like so:

Inline math equations go in like so: $\omega = d\phi / dt$. Display math should get its own line and be put in in double-dollarsigns:

$$I = \int \rho R^{2} dV$$

And note that you can backslash-escape any punctuation characters which you wish to be displayed literally, ex.: `foo`, *bar*, etc.

Include Video in the Posts

2023年8月1日 08:00

Just copy the embed code from YouTube or other platforms, and paste it in the markdown file.

---
title: Include Video in the Post
published: 2023-10-19
// ...
---

<iframe width="100%" height="468" src="https://www.youtube.com/embed/5gIf0_xpFPI?si=N1WTorLKL0uwLsU_" title="YouTube video player" frameborder="0" allowfullscreen></iframe>

YouTube

<iframe width="100%" height="468" src="https://www.youtube.com/embed/5gIf0_xpFPI?si=N1WTorLKL0uwLsU_" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>

Bilibili

<iframe width="100%" height="468" src="//player.bilibili.com/player.html?bvid=BV1fK4y1s7Qf&p=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>

用Siri来控制Windows电脑开机关机吧

2024年2月26日 08:00

前因

自从手机从iphone换成Android后,咱的13香就没啥用了,只能放桌子上当时钟,感觉有点浪费啊,所以研究了下苹果的HomeKit,用旧手机当智能中控岂不更好!网上查了下,貌似也蛮简单的。开搞开搞!

准备

  1. 买一个能够连接homekit的智能插座,网上蛮多的,一个插座也就20~50不等,我买的是meross的,好像说是外贸货,反正到手是日本那边的,还行。买来后插上电,用手机先连接2.4g的wifi后扫描下二维码后按提示就可以让插座联网了,加入后只要网络正常,就可以用手机控制插座开关了。
  2. 设置电脑bios,通电后自动启动机器。我的外星人台式机是开机后按F2就可以进入bios,然后找到高级选项--电源选项里有个开机改成通电就Power On就好了。
  3. 给Windows账号加上密码,就是登陆要输入密码才能登陆,这样可以让其他手机或者服务器进行ssh登陆。
  4. 电脑安装OpenSSH。打开Powershell,然后Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0命令,出现进度条后等待安装完毕。然后net start sshd即可启动ssh服务。当然别忘了在防火墙的入站规则里加上TCP的22端口规则允许。还有就是在Windows的服务里找到OpenSSH然后手动改成自动,这样就开机自动启动啦。然后还有就是要把电脑的IP改成静态的,不能DHCP动态分配。最后可以尝试在Powershell里ssh 你的用户名@你的服务器IP,然后输入你的密码就可以正常SSH登陆啦!

嘿 Siri

  1. 准备工作都弄完后,现在就轮到iphone了,先在家庭里创建2个场景,一个是关电脑,就是控制插座关闭电源,另一个的开电脑,控制插座开启电源。弄完后点击试试,看看插座是不是可以正常点一下就开启和关闭了。
  2. 打开苹果的快捷指令,创建一个新的快捷指令,名称叫打开电脑,里面只需要添加开电脑的场景即可。这样只需要喊"嘿!sir,打开电脑" ,就可以开启插座然后通电开机啦。
  3. 再创建一个新的快捷指令,名称叫关闭电脑,然后添加通过SSH发送命令,把服务器的ip、22端口号、用户名、密码都填写,脚本的话填写shutdown -s -t 1。然后再添加等待60秒,最后再添加关电脑的场景即可。这样通过siri喊"嘿!sir,关闭电脑",就可以实现快速关机了!

语音控制

上面通过嘿siri来控制快捷指令来运行关机貌似会有点小问题,因为要等待60s后才会执行下一步,siri好像默认不会等那么久,所以换一种方式,用iphone的辅助功能。里面有个语音控制,开启后新增语音关闭电脑然后运行对应的快捷指令即可,这下连siri都不用了,直接说关闭电脑就好了!

控制中台

iphone的家庭里其实还有一个小功能,就是开启引导界面,然后输入密码设置,你会发现界面会钉在家庭的控制页面,且不会切换,这样就相当于把手机作为了中台,只需要连接电源然后挂在墙上或者桌子上,就可以当一个完美的控制中台啦~

最后

家里马上也要开始装修弄家具了,之前也有了解一些智能家居,但感觉都不是很实用,大部分也就是一些回家后自动开灯,开电器。起床自动打开窗帘和播放音乐之类的,为了这些多花好几万感觉不是很划算,那还不如就简单点用智能插座加场景设置和快捷指令来控制,这样成本低,自己diy,体验也不错。虽然有一些局限性,但本来就图新鲜,好玩就行了~

clickhouse的一些优化建议和工具

2024年1月9日 08:00

起因

自从用cloki+clickhouse来替代日志系统后真是一波三折,问题不断Orz。 只能感叹不亏是小众的开源工具,还是一堆坑,下面记一下踩到的一些坑和对clickhouse的优化。

  • Q:主查询最后的查询会进行全表查询,但是left join的time_series_dist表巨大,有几百G,几十亿条数据,导致每次查询都得全部读取到内存里,一次查询占用80G内存,查询5分钟还查不出结果!
# 查询语句
WITH sel_a AS
    (
        SELECT
            samples.string AS string,
            samples.fingerprint AS fingerprint,
            samples.timestamp_ns AS timestamp_ns
        FROM cloki.samples_v3_dist AS samples
        WHERE ((samples.timestamp_ns >= 1704440225031000000) AND (samples.timestamp_ns <= 1704440525031000000)) AND (samples.fingerprint IN (
            SELECT sel_1.fingerprint
            FROM
            (
                SELECT fingerprint
                FROM cloki.time_series_gin
                WHERE (key = 'app') AND (val = 'myapp')
            ) AS sel_1
            ANY INNER JOIN
            (
                SELECT fingerprint
                FROM cloki.time_series_gin
                WHERE (key = 'cluster') AND (val = 'test-prod')
            ) AS sel_2 ON sel_1.fingerprint = sel_2.fingerprint
        ))
        ORDER BY timestamp_ns DESC
        LIMIT 100
    )
SELECT
    JSONExtractKeysAndValues(time_series.labels, 'String') AS labels,
    sel_a.*
FROM sel_a
ANY LEFT JOIN cloki.time_series_dist AS time_series ON sel_a.fingerprint = time_series.fingerprint
ORDER BY
    labels DESC,
    timestamp_ns DESC
  • A: 估计是开源cloki根据的bug,而且和orderby也有区别,调查了蛮多优化建议,其中比较有用的是
  1. 让表的orderby和查询的orderby一致,这样可以减少最后排序时间,所以我把ORDER BY fingerprint改成ORDER BY (fingerprint, labels)。
  2. left join后的表尽量要是小表,不过这里是固定了所以没法优化,所以只能减少表的大小,还好这个表只是存储标签,把TTL(生命周期)改成1天后就好多了。
  3. 网上还有说让经常查询的key作为主键分区,相当于做了索引,也可以加快查询速度和效率,所以我PARTITION BY date改成了PARTITION BY fingerprint,但其实是有问题的! 因为PARTITION BY是分区,如果是date的话,一天一个分区,这样查询如果是跨天查询就很快,如果改成fingerprint会变成每一个数据一个分区!CK集群直接报错Too many parts (100018) in all partitions in total,分区中存在过多的数据分片了,赶紧删了重新改回来了date,没有完全懂的东西还是不要乱动的好。当然可以把分区时间改成半天,也有一定的效果。
     CREATE TABLE cloki.time_series
     (
         `date` Date,
         `fingerprint` UInt64,
         `labels` String,
         `name` String,
       INDEX idx_fingerprint_labels (fingerprint) TYPE minmax GRANULARITY 8192
     )
     ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/time_series/{shard}', '{replica}', date)
     PARTITION BY date
     ORDER BY (fingerprint, labels)
     TTL date + toIntervalDay(1)
     SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1, merge_with_ttl_timeout = 3600
    
  • R:查询问题解决后,基本上每次查询都可以在10s内完成,而且内存也不需要太大了,clickhouse里也有一些users.xml的default标签参数可以优化查询啥的,例如
    max_threads 这个值不要太高,一般是默认就好了,并不是说线程越高越好,越高内存占用也越大
    distributed_product_mode ReplicatedReplacingMergeTree+Distributed的分布式表一定要弄为global,如果只是MergeTree+Distributed可以local
    group_by_overflow_mode 默认是查询失败就throw丢弃,也可以改成查询超出内存后返回部分结果,一般不需要改
    max_memory_usage 单个查询最大多少内存,默认是10g,当然也可以改大,我是改成90%的内存大小
    max_bytes_before_external_group_by groupby超了多少内存后就写入到磁盘里,防止内存占用过多,虽然会影响效率,一般是改成max_memory_usage的一半
    max_bytes_before_external_sort orderby超了多少内存后就写入到磁盘里,防止内存占用过多,虽然会影响效率,一般是改成max_memory_usage的一半

  • Q:clickhouse其实更适合一次性插入几百万的数据,而不是短时间内大量一条一条的数据插入,就好像现在cloki每一条日志都是一个insert请求,导致大量的单条插入给到clickhouse,然后ck集群的同步会扛不住,会报错merge速度比不上insert速度,然后zookeeper或clickhouse-keeper的负载非常高,触发表readonly的保护机制,只要没merge完就不给写入,因为没有缓存的中间件,一堆日志写入失败丢失。

  • A:说白了就是clickhouse的使用方法不对,如果是数据量不大还好,官方说只要超过500k每秒的插入,基本上就会导致同步不过来表readonly无法写入。所以网上有一些解决方法:

  1. 用buffer表来做缓冲,Buffer(database, table, num_layers, min_time, max_time, min_rows, max_rows, min_bytes, max_bytes [,flush_time [,flush_rows [,flush_bytes]]]), 用下面的例子里的参数解释就是,如果满足最大max的100s或者100w行或者100m的数据其中一个条件,就触发缓存写入到目标表,又或者同时满足所有min的条件过了10s且1w行且10m的数据就会触发写入数据到目标表。不过这个方法官方也说了其实不怎么适用,因为本身clickhouse还是不适合用于短时间大量单条数据的插入,更适合单条插入大量数据的场景,官方建议是每秒不超过1条插入语句。
  CREATE TABLE cloki.samples_v3_buffer
(
    `fingerprint` UInt64,
    `timestamp_ns` Int64 CODEC(DoubleDelta),
    `value` Float64 CODEC(Gorilla),
    `string` String CODEC(ZSTD(5))
)
ENGINE = Buffer('cloki', 'samples_v3', 16, 10, 100, 10000, 1000000, 10000000, 100000000)
  1. buffer表不管用,那就只能想想其他办法,还好这个问题也有解决,clickhouse-bulk 是第三方的开源小工具,主要目的就是把小插入变成大插入,只需要设置好配置文件nohup ./clickhouse-bulk -config config.json >/dev/null 2>&1 &启动即可,所有的小插入会先缓存然后满足配置条件后写入到clickhouse集群里,而且写入失败会生成dump文件,重新尝试插入,相当于缓存了。
    {
    "listen": ":8124",   #启动的端口,clickhouse是8123 ,这个是8124,小心别漏了分号
    "flush_count": 1000000,  #缓存多少行后写入,我这边指定的是100w行写入一次
    "flush_interval": 5000,  #缓存多少秒后写入,我这边指定5秒后写入
    "clean_interval": 0,     #清理内部表的频率,例如插入到不同的临时表,或作为解决query_id等问题的方法,单位:毫秒
    "remove_query_id": true,  #有些驱动程序发送的query_id会阻止批量插入
    "dump_check_interval": 60, #尝试发送转储文件的间隔(秒);-1表示禁用,就是重新尝试插入dump文件的时间
    "debug": false,  # 记录传入的请求日志
    "log_queries": true, 
    "dump_dir": "dumps",   # 转储未发送的数据的目录(如果ClickHouse出错)
    "clickhouse": {
      "down_timeout": 60,  # 服务器宕机时等待的时间(秒)
      "connect_timeout": 10,  # 等待服务器连接的时间(秒)
      "tls_server_name": "", # 覆盖用于证书验证的TLS serverName(例如,如果在多个节点上共享相同的"cluster"证书)
      "insecure_tls_skip_verify": false, # 证书验证
      "servers": [
        "http://127.0.0.1:8123"
      ]
    },
    "use_tls": false,
    "tls_cert_file": "",
    "tls_key_file": ""
  }

最后

到目前为止大部分问题解决了,虽然还有一些小问题,但日志系统也慢慢趋于稳定,clickhouse数据库号称比传统mysql数据库快一万倍,但坑还是蛮多的,目前国内用的其实不多,但以后估计会变成香饽饽吧。

记录一下我的第一个网页游戏Mazeball

2023年11月27日 08:00

游戏链接:

MazeBall

截图:

snapshot{width=200 height=200 }

游戏规则:

  1. 鼠标左键控制小球左右移动,点击页面,小球会根据鼠标的相对位置来移动。 如果鼠标在小球的左边则左移,鼠标在小球的右边则右移,其他则不动。
  2. 鼠标右键控制小球向下移动。
  3. 键盘wsad也可以控制上下左右移动。
  4. 倒计时归零则游戏结束。
  5. 碰到红色障碍物则游戏结束。

    游戏的玩法其实就是在限定的时间内看看能到达第几关,因为每通关一关只会增加5秒倒计时,但层数会增加,所以到越到后面迷宫越长,操作的时间是不够的。 而且很容易出现误触导致失败,所以还是得小心控制小球移动,毕竟是突发奇想的一个简单益智类小游戏,可玩性不高,不过还是挺有意思的~

    我也尝试上架了下chrome的插件商店,虽然没什么人下载,不过也算是熟悉了下发布插件的流程啦,只需要开通账号后绑定下信用卡(我用的招商visa卡), 然后一次性支付5美元就可以上传插件了,填写一些应用描述和截图提交审核即可,还是蛮简单的。

隐私政策URL

2023年1月1日 08:00

本软件尊重并保护所有使用服务用户的个人隐私权。为了给您提供更准确、更有个性化的服务,本软件会按照本隐私权政策的规定使用和披露您的个人信息。但本软件将以高度的勤勉、审慎义务对待这些信息。除本隐私权政策另有规定外,在未征得您事先许可的情况下,本软件不会将这些信息对外披露或向第三方提供。本软件会不时更新本隐私权政策。您在同意本软件服务使用协议之时,即视为您已经同意本隐私权政策全部内容。本隐私权政策属于本软件服务使用协议不可分割的一部分。

1.适用范围

a)在您使用本软件网络服务,本软件自动接收并记录的您的手机上的信息,包括但不限于使用的语言、访问日期和时间、软硬件特征信息及您需求的网页记录等数据;

2.信息的使用

a)在获得您的数据之后,本软件会将其上传至服务器,以生成您的排行榜数据,以便您能够更好地使用服务。

3.信息披露

a)本软件不会将您的信息披露给不受信任的第三方。

b)根据法律的有关规定,或者行政或司法机构的要求,向第三方或者行政、司法机构披露;

c)如您出现违反中国有关法律、法规或者相关规则的情况,需要向第三方披露;

4.信息存储和交换

本软件收集的有关您的信息和资料将保存在本软件及(或)其关联公司的服务器上,这些信息和资料可能传送至您所在国家、地区或本软件收集信息和资料所在地的境外并在境外被访问、存储和展示。

如何使用Clickhouse的索引

2023年10月18日 08:00

简介

    影响ClickHouse查询性能的因素很多。在大多数情况下,关键因素是ClickHouse在计算查询WHERE子句条件时是否可以使用主键。因此,选择适用于最常见查询模式的主键对于有效的表设计至关重要。     用户通常依赖ClickHouse获取时间序列类型的数据,但他们通常希望根据其他业务维度(如客户id、网站URL或产品编号)分析相同的数据。在这种情况下,查询性能可能会相当差,因为可能需要对每个列值进行完整扫描才能应用WHERE子句条件。虽然ClickHouse在这些情况下仍然相对较快,但评估数百万或数十亿个单独的值将导致“非索引”查询的执行速度比基于主键的查询慢得多。     ClickHouse提供了一种不同类型的索引,在特定情况下可以显著提高查询速度。这些结构被标记为“跳过(Skip)”索引,因为它们使ClickHouse能够跳过读取保证没有匹配值的重要数据块。

介绍

Clickhouse索引的特点为: 排序索引+稀疏索引+列式存储, 因此相应的Clickhouse最合适的场景就是基于排序字段的范围过滤后的聚合查询。

因为排序索引, 所有基于排序字段的查询会明显由于MR类型计算, 否则Hive/Spark这类动态资源的更优 由于稀疏索引, 点查询的效率可能没有KV型数据库高, 因此适合相对大范围的过滤条件 因为列式存储, 数据压缩率高, 对应做聚合查询效率也会更高.

实践

因为表索引不好在创建表后再进行创建,所以最好在创建表的时候就计划好并创建,例如cloki的表主要是samples_v3和time_series_gin表是用作主要查询。
对于cloki.time_series_gin表:
对key列进行索引:ALTER TABLE cloki.time_series_gin_ ADD INDEX idx_key(key) TYPE minmax GRANULARITY 8192;
对val列进行索引:ALTER TABLE cloki.time_series_gin_ ADD INDEX idx_val(val) TYPE minmax GRANULARITY 8192;
对fingerprint列进行索引:ALTER TABLE cloki.time_series_gin_ ADD INDEX idx_fingerprint(fingerprint) TYPE minmax GRANULARITY 8192;

对于cloki.samples_v3表:
对timestamp_ns列进行索引:ALTER TABLE cloki.samples_v3_ ADD INDEX idx_timestamp_ns(timestamp_ns) TYPE minmax GRANULARITY 8192;
对fingerprint列进行索引:ALTER TABLE cloki.samples_v3_ ADD INDEX idx_fingerprint(fingerprint) TYPE minmax GRANULARITY 8192;
对string列进行索引:ALTER TABLE cloki.samples_v3_ ADD INDEX idx_string(string) TYPE minmax GRANULARITY 8192;

如果需要对已有的数据也进行索引,需要 ALTER TABLE cloki.samples_v3_ MATERIALIZE INDEX idx_timestamp_ns; 数据量较大,会非常慢。

参考

官方文档
深入浅出clickhouse-index

❌
❌