userver
2.6
| 서비스 템플릿 | 개발 / 녹색 트렁크 | v2.0 | v1.0 |
|---|---|---|---|
| 핵심: | [➚] | [➚] | |
| postgresql : | [➚] | [➚] | |
| grpc+postgresql : | [➚] | [➚] |
userver는 C ++ 마이크로 서비스, 서비스 및 유틸리티의 빠르고 편안한 생성을위한 풍부한 추상화 세트를 갖춘 오픈 소스 비동기 프레임 워크입니다.
이 프레임 워크는 개발자에게 효율적인 I/O 상호 작용 문제를 투명하게 해결합니다. 일반적으로 실행 스레드를 중단하는 작업은이를 중단하지 않습니다. 그 대신에 스레드는 다른 요청과 작업을 처리하고 즉시 실행하도록 보장 할 때만 작업의 처리로 돌아갑니다.
# include < userver/easy.hpp >
# include " schemas/key_value.hpp "
int main ( int argc, char * argv[]) {
using namespace userver ;
easy::HttpWith<easy::PgDep>(argc, argv)
// Handles multiple HTTP requests to `/kv` URL concurrently
. Get ( " /kv " , [](formats::json::Value request_json, const easy::PgDep& dep) {
// JSON parser and serializer are generated from JSON schema by userver
auto key = request_json. As <schemas::KeyRequest>(). key ;
// Asynchronous execution of the SQL query in transaction. Current thread
// handles other requests while the response from the DB is being received:
auto res = dep. pg (). Execute (
storages::postgres::ClusterHostType:: kSlave ,
// Query is converted into a prepared statement. Subsequent requests
// send only parameters in a binary form and meta information is
// discarded on the DB side, significantly saving network bandwidth.
" SELECT value FROM key_value_table WHERE key=$1 " , key
);
schemas::KeyValue response{key, res[ 0 ][ 0 ]. As <std::string>()};
return formats::json::ValueBuilder{response}. ExtractValue ();
});
}결과적으로 프레임 워크를 사용하면 간단한 소스 코드를 얻으면 OS에서 CPU가 소비하는 컨텍스트 스위치를 피하고 소량의 실행 스레드와 함께 CPU를 효율적으로 활용하십시오.
출판물 및 비디오에서 사용자 버전의 역사 및 주요 기능에 대한 자세한 내용을 배울 수 있습니다.
자세한 내용은 문서를 참조하십시오.