伴我一路走来的那些bug们,你们好

1. failed to write data to stream

2. Git: fatal: Pathspec is in submodule

3. DB: (2013, ‘Lost connection to MySQL server during query’), python decorator, gevent, greenlet, function life cycle

(total request times)/(total time in seconds) = 
10^8 * 150 * (1 + 0.2) / 2 / 60 / 60 = 
180 * 10^8 / 7200 = 
0.025 * 10^8 = 
2.5 * 10^6 = 25 万次请求/每秒

可见其实请求也不是特别大,但是这只是平均请求,天才知道峰值多少呢?其次,zf总不会也要模仿12306那样,请个大公司来做吧。于是,zf里的一个工程师决定,应该把写数据库这个操作异步执行,这样考生在网页上点了下一题之后,虽然立即跳转到下一题,但并不表示考生上一题的答案已经写入数据库了。

ok了,场景大概就是这样了。 详情见代码片段 :

class Test(object):
    @get_dbc
    def assign_user_to_exp(self, dbc, user_id, cell_id):
            self.g_pool.spawn(
                self.async_assign_user_to_exp,
                dbc,
                user_id,
                cell_id,
            )
            return

    def async_assign_user_to_exp(self, dbc, user_id, cell_id):
        return dbc.execute(''' there is a sql sentence that refering user_id and cell_id, just leave details here ''')
class Test(object):
    def assign_user_to_exp(self, user_id, cell_id):
            self.g_pool.spawn(
                self.async_assign_user_to_exp,
                user_id,
                cell_id,
            )
            return

    @get_dbc
    def async_assign_user_to_exp(self, dbc, user_id, cell_id):
        return dbc.execute(''' there is a sql sentence that refering user_id and cell_id, just leave details here ''')

4. fluentd 启动报错: unexpected error error_class=RuntimeError error=#<RuntimeError: can’t call S3 API. Please check your aws_key_id / aws_sec_key or s3_region configuration. error = #>

<match *.group_ab_testing>
  type s3
  aws_key_id ***
  aws_sec_key ***
  s3_bucket dev-test-bucket-name
  path storage_path/
  time_slice_format %Y/%m/%d/dev/%H
  buffer_path /mnt/td-agent/temp_file
  buffer_chunk_limit 10m
  utc
</match>

问题表现得像是这个aws_key_id和aws_sec_key访问不到,或者访问s3超时,已经排除aws_key_id和aws_sec_key无效的可能性。fluentd配置文件也没有错,于是安装 sudo pip install awscli awsci 客户端来调试,调试过程如下:

aaron@dev-aaron:/etc/td-agent$aws configure
AWS Access Key ID [None]: AKIAIZFF6PMYSYCU2Z7Q
AWS Secret Access Key [None]: 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
Default region name [None]:
Default output format [None]:
aaron@dev-aaron:/etc/td-agent$aws s3 ls

A client error (RequestTimeTooSkewed) occurred when calling the ListBuckets operation: The difference between the request time and the current time is too large.

看来问题依然存在,请求伟大的 google,感谢有人已经在伟大的 stackoverflow 上问过类似的问题了: aws-s3-upload-fails-requesttimetooskewed

高人说也许是本地时间和s3上点时间不一致的导致的,果然本地时间比s3时间晚了十几分钟:

aaron@dev-aaron:/etc/td-agent$curl http://s3.amazonaws.com -v
* About to connect() to s3.amazonaws.com port 80 (#0)
*   Trying 54.231.14.248... connected
> GET / HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: s3.amazonaws.com
> Accept: */*
>
< HTTP/1.1 307 Temporary Redirect
< x-amz-id-2: iR7WZjF4wccLoZCfGJeZ5SHM8AQP9SK3oCTNwsBwkW60u02JFI2OqTakcjsLYMv1TnsTZFXHkmc=
< x-amz-request-id: 90748BF8849F53E7
< Date: Tue, 04 Aug 2015 04:41:44 GMT
< Location: http://aws.amazon.com/s3/
< Content-Length: 0
< Server: AmazonS3
<
* Connection #0 to host s3.amazonaws.com left intact
* Closing connection #0
aaron@dev-aaron:/etc/td-agent$date -u
Tue Aug  4 04:23:27 UTC 2015