This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tornado http request duration histogram | |
awk '$1 == "[I" && $5 == 200 {sum += 1; duration = int(substr($10, 0, length($10) - 2)); if(duration < 100) r100 +=1; else if(duration < 200) r200 += 1; else if(duration < 500) r500 += 1; else r1000 += 1;} END {print "总请求量", "100ms以内", "200ms以内", "500ms以内", "500ms以外"; print sum, r100, r200, r500, r1000, (r100 + r200) / sum}' /path/app.log | |
# tornado http request top ten qps time | |
awk '$1 == "[I" && $5 == 200 {split($3, time, ","); second = $2" "time[1]; agg[second] += 1} END {for(second in agg) print second, agg[second]}' /path/app.log | sort -nr -k 3 | head | |
# nginx top ten qps time | |
awk '{second = substr($4, 2, length($4) - 1); agg[second] += 1} END {for(second in agg) print second, agg[second]}' logs/access.log | sort -nr -k 2 | head | |
# tornado http request duration greater than 100ms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _AddPropertiesForNonRepeatedScalarField(field, cls): | |
"""Adds a public property for a nonrepeated, scalar protocol message field. | |
Clients can use this property to get and directly set the value of the field. | |
Note that when the client sets the value of a field by using this property, | |
all necessary "has" bits are set as a side-effect, and we also perform | |
type-checking. | |
Args: | |
field: A FieldDescriptor for this field. | |
cls: The class we're constructing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import multiprocessing | |
import os | |
import threading | |
import time | |
def child_thread(lock): | |
with lock: | |
time.sleep(10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This is similar to PyObject_GenericGetAttr(), | |
but uses _PyType_Lookup() instead of just looking in type->tp_dict. */ | |
static PyObject * | |
type_getattro(PyTypeObject *type, PyObject *name) | |
{ | |
PyTypeObject *metatype = Py_TYPE(type); | |
PyObject *meta_attribute, *attribute; | |
descrgetfunc meta_get; | |
if (!PyUnicode_Check(name)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Generic GetAttr functions - put these in your tp_[gs]etattro slot */ | |
PyObject * | |
_PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, PyObject *dict) | |
{ | |
PyTypeObject *tp = Py_TYPE(obj); | |
PyObject *descr = NULL; | |
PyObject *res = NULL; | |
descrgetfunc f; | |
Py_ssize_t dictoffset; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// type object set attribute | |
static int | |
type_setattro(PyTypeObject *type, PyObject *name, PyObject *value) | |
{ | |
if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) { | |
PyErr_Format( | |
PyExc_TypeError, | |
"can't set attributes of built-in/extension type '%s'", | |
type->tp_name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from concurrent.futures import ThreadPoolExecutor | |
import grpc | |
import pytest | |
import a_pb2_grpc | |
from rpc.server import AGRpcServer, BGRpcServer | |
import b_pb2_grpc | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop table if exists s_multi_update_same_row; | |
create table s_multi_update_same_row( | |
id int, | |
count int | |
); | |
insert into s_multi_update_same_row select id, 0 from generate_series(1, 1000) as id; | |
update s_multi_update_same_row A set count = count + 1 from generate_series(1, 10000) as B(id) where A.id = B.id % 1000 + 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop table if exists s_user_table; | |
create table s_user_table ( | |
id int, | |
user_id int | |
); | |
drop table if exists s_user_cnt_table; | |
create table s_user_cnt_table ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun load-protobuf () | |
"Load protobuf." | |
(add-to-list 'load-path "~/.emacs.d/el-get/protobuf-mode") | |
(require 'protobuf-mode) | |
(add-to-list 'auto-mode-alist '("\\.proto\\'" . protobuf-mode)) | |
(add-hook 'protobuf-mode-hook (lambda () (auto-complete-mode))) | |
) |
OlderNewer