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 ();
});
}เป็นผลให้เฟรมเวิร์กคุณจะได้รับซอร์สโค้ดตรงไปตรงมาหลีกเลี่ยงสวิตช์บริบทที่ใช้ CPU จากระบบปฏิบัติการใช้ประโยชน์จาก CPU อย่างมีประสิทธิภาพด้วยเธรดการดำเนินการจำนวนเล็กน้อย
คุณสามารถเรียนรู้เพิ่มเติมเกี่ยวกับประวัติและคุณสมบัติที่สำคัญของ userver จากสิ่งพิมพ์และวิดีโอของเรา
ดูเอกสารสำหรับข้อมูลเพิ่มเติม