Finisky Garden

NLP, 软件工程, 产品设计

Master-slave replication is widely used in production. Monitoring the replication lag is a common and critical task. Typically, we are able to get the real-time difference between the master and the slave by periodically checking the Seconds_Behind_Master variable.

阅读全文 »

博客越写越多,将markdown源文件备份到github变得非常重要。github pages要求免费账户的username.github.io必须是public repository。网上主要有两种方案,一个是用hexo-git-backup插件,另一个是在username.github.io上创建另一个分支进行备份。

这两个方案都偏复杂,第一个引入了额外的依赖,而且看起来和使用的hexo版本还有点关系,第二个用一个branch进行备份略奇怪。

考虑到hexo-deployer-git使用的是.deploy_git目录,与源文件所在目录无关。那么最简单的方案是新开一个repository (public/private均可),让本地博客文件夹直接track这个新的repository即可。同时注意把不必要的文件和目录用.gitignore去除。

阅读全文 »

We developed a REST API long time ago and recently found that the released client has a flaw: the HttpRequestMessage is missing content-type application/json. In earlier version we manually deserialize the request json by reading the request body but now we leverage AspNetCore framework to automatically get the request structure from the API parameter. However, the legacy client will not work: HTTP 415 "Unsupported Media Type" error happens.

Therefore, for backward compatibility, we need to make the server treat all coming requests as application/json even it is a plain text (by default).

阅读全文 »

Someone may argue that there is no reason to disable ipv6 on Linux. For me, the reason is that in some ipv6-enabled website, I frequently be classified as a bot who need to solve captcha which is really annoying :-( . Consider the ipv6 address is never change (assigned by service provider), disable ipv6 is the simplest solution.

阅读全文 »

When we use entity framework to manipulate SQL database, we use where to query and include to load related entities (join operation).

Sample database table schema: Employee: Id, Name, Age Salary: Id, BasePay

Typical query scenarios:

  • Query employee 3's name => Employee.Where(x => x.Id == 3)
  • Query employee Jack's age => Employee.Where(x => x.Name == "Jack")
  • Query employee Jack's basepay => Employee.Where(x => x.Name == "Jack").Include(x => x.Salary) ...

To make the code clean and focus, the following examples will not include dbContext creation logic, we assume db = DbContext() which contains the Employee table.

For code reuse purpose, we may extract a common method like this:

Employee GetEntity(Func<Employee, bool> whereFunc, Func<DbSet<Employee>, IQueryable<Employee>> navigationFunc = null)
{
    IQueryable<Employee> query = navigationFunc != null ? navigationFunc(db.Employee) : db.Employee;
    var employee = await query.Where(x => whereFunc(x)).ToListAsync();
    return employee;
}

The implmentation looks simple and straightfoward: just extract the where and navigation Func<> to a function.

However, the above function has severe perfomance issue: when we execute the function, it retrieves all data from the table and locally applies where filter. Actually, the underlying mechanism is not that simple as entity framework will compile the expression and translated to SQL statements, though it looks like just a syntactic sugar.

阅读全文 »

Install an old library lightsquid on Ubuntu 20.04. When visit the cgi, internal server error pops up.

Debug the cgi by directly run it in /var/www/lightsquid:

/var/www/lightsquid$ perl index.cgi
Can't locate CGI.pm in @INC (you may need to install the CGI module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at index.cgi line 19.
BEGIN failed--compilation aborted at index.cgi line 19.

Seems that some modules are missing, after several search: https://packages.ubuntu.com/search?suite=trusty&arch=any&mode=filename&searchon=contents&keywords=cgi.pm

Combined with the error message:

$ apt install libcgi-pm-perl

Then it works:

/var/www/lightsquid$ perl index.cgi
```html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<HTML>
<HEAD>
  <META name="robots" content="noindex,nofollow">
  <META name="generator" content="LightSquid - http://lightsquid.sf.net">
  <META http-equiv="Content-Type" content="text/html; charset=US-ASCII">
  <META HTTP-EQUIV="REFRESH" CONTENT="600">
...

BBR 是Google 2016年提出的TCP 拥塞控制算法,可以显著地提升Server的吞吐率并降低延迟。在VPS上实测效果非常明显,将VPS的下载速度由10Mbps左右提升至约50Mbps,自动视频质量也由240p升至1080p。

阅读全文 »

View the generated SQL query by entity framework is important. The translated SQL query may not what you expected. Sometimes it leads to significant performance issue.

Print the generated query for an IQueryable<T> in EF Core is different with EF. Finally I found a worked solution which is listed below.

阅读全文 »

2020-11-28更新: 经过四个多月的肌肉练习(引体向上,核心肌群训练,跑步,羽毛球),肩颈疼痛症状显著缓解,坚持锻炼两个月后,落枕、脖子活动受限的情况基本就没再发生过,现在的情况就更好了。全身性的肌肉训练效果还是很好的,亲测推荐!

值得一提的是病来如山倒,病去如抽丝。在急性疼痛期时不建议进行肌肉训练,在慢性期时进行训练也须坚持,就我个人而言,开始练习的一个多月基本感觉不到症状缓解的现象,但再坚持一段时间后(一口气正手引体向上5次以上),效果开始显现,还得让子弹飞一会儿。肌肉力量的增长需要时间,肌肉强健之后,筋膜炎的症状才能缓解。


现代人不论什么工作,都是每天长时间对着电脑工作,不良姿势的久坐导致的问题颇多,以颈椎病和腰椎病最为常见。笔者最近受疫情长时间在家办公影响,肩颈部位酸痛,且几个月都没有缓解。关于肩颈疼痛的缓解方案网上有很多,经过问医、研究和亲身试验,总结下有效和无效的方案。

阅读全文 »

硬盘虽然并不值钱,但对于一个强迫症来说,看到莫名其妙地内容占据了好些空间也非常不爽。记录下在Linux中如何发现空间占用大户,以及可以删除什么以缩减使用空间。

阅读全文 »
0%