Skip to content

Instantly share code, notes, and snippets.

View kemingy's full-sized avatar
🈚
actions

Keming kemingy

🈚
actions
View GitHub Profile
@kemingy
kemingy / timeout.py
Created May 11, 2020 06:13
timeout for Python (signal, futures)
import os
import time
from concurrent import futures
import signal
class Model:
def __init__(self):
self.pid = os.getpid()
@kemingy
kemingy / spec_msg_client.py
Created May 2, 2020 09:57
test spectree for falcon msgpack handlers
import msgpack
import httpx
if __name__ == "__main__":
url = 'http://localhost:8000/'
with httpx.Client() as client:
client.headers.update({'Content-Type': 'application/msgpack'})
packer = msgpack.Packer(
autoreset=True,
@kemingy
kemingy / client.go
Created April 27, 2020 04:16
Unix Domain Socket Communication
package main
import (
"log"
"net"
"time"
)
func main() {
@kemingy
kemingy / benchmark.md
Last active January 12, 2023 04:44
Tensorflow Serving, TensorRT Inference Server (Triton), Multi Model Server (MXNet)

Environments

  • CPU: Intel(R) Xeon(R) Gold 6130 CPU @ 2.10GHz
  • GPU: NVIDIA V100
  • Memory: 251GiB
  • OS: Ubuntu 16.04.6 LTS (Xenial Xerus)

Docker Images:

  • tensorflow/tensorflow:latest-gpu
  • tensorflow/serving:latest-gpu
@kemingy
kemingy / cython_note.md
Last active April 1, 2020 02:54
Cython notes

Install

pip install cython

Build

  • setuptools
  • setup.py
from werkzeug.datastructures import MultiDict
from starlette.datastructures import ImmutableMultiDict
from falcon.util.uri import parse_query_string
from pydantic import BaseModel, root_validator
from typing import List
from typing_extensions import Literal
class Query(BaseModel):
cmd: List[Literal['ls', 'rm', 'cd']]
@kemingy
kemingy / rate_limit.md
Last active February 3, 2020 08:13
rate limiting algorithms
@kemingy
kemingy / python_glue.md
Last active February 3, 2020 02:41
f2py, cython, ctypes, etc.

Using Python as Glue Summary

https://docs.scipy.org/doc/numpy/user/c-info.python-as-glue.html

tools f2py Cython ctypes SWIG
source lang Fortran C/C++ C C/C++
pros It allows clean separation of Python with compiled code while still allowing for separate distribution of the extension module. Easily and quickly work with multidimensional arrays. Easily to distributed. Clean separation of C code from Python Code. Easy integration with numpy. Full argument checking. It can (almost) parse the headers and auto produce the interface.
cons It requires the existence of a Fortran compiler in order for a user to install the code. Need to be familiar with C. Can be hard to reuse the C code for other non-Python-related projects. Hard to distributed. Need shared-libraries for the code. Very little support for C++. It must be done using the concept of typemaps.
@kemingy
kemingy / descriptor.md
Last active January 16, 2020 10:43
python descriptor, decorator, wraps, partial

Descriptor

Define: a descriptor is an object attribute with "binding behavior", one whose attribute access has been overridden by methods in the descriptor protocal.

a.x -> a.__dict__['x'] -> type(a).__dict__['x']

Descriptor Protocol

  • descr.__get__(self, obj, type=None) -> value
  • descr.__set__(self, obj, value) -> None
@kemingy
kemingy / cws.md
Last active January 9, 2020 04:18
chinese words segmentation algorithm