Почему среднее время отклика сервиса сократилось с 900 до 350 мс: в чём была проблема и какие изменения внесли?
Asked at
AI answer
This kind of improvement should be tied to a measured bottleneck, not merely to code optimization. For example, profiling may show that requests were calling several external services sequentially or issuing repeated database queries. In that case, independent calls can be parallelized, batch loading can be added, or duplicate queries can be eliminated. First, compare p50/p95/p99, traces, and profiles before and after the changes, and check the load and error rates. If the specific cause is unknown, do not make one up: explain how you investigated it and which changes were confirmed by measurements.
Also asked at GigaChat / Сбер
- app = FastAPI() def get_db(): db = SessionLocal() try: yield db finally: db.close() def heavy_text_parser(file_id: int, db: Session): # Parsing a file that takes 5 minutes parse_and_save(file_id, db) @app.post("/upload") async def upload_file( background_tasks: BackgroundTasks, db: Session = Depends(get_db) ): file_id = save_file_to_db(db) db.commit() background_tasks.add_task(heavy_text_parser, file_id, db) return {"status": "parsing started"}
- def extract_emails_from_huge_file(file_path: str) -> list[str]: with open(file_path, 'r', encoding='utf-8') as f: content = f.read() # Заменяем переносы строк, чтобы текст был "сплошным" content = content.replace('\r\n', ' ').replace('\n', ' ') lines = content.split(' ') emails = [word for word in lines if '@' in word] return emails
Similar questions
- You’ve deployed a release. The service hasn’t gone down, but its response time has risen sharply (from 200 ms to 2 s). What would you do, and where would you look first?
- Could you briefly explain the caching in this case: what was cached, and how did it help?
- You wrote that latency dropped from 120 to 6 milliseconds. Was that mainly thanks to caching?
- A web service endpoint has started responding slowly. What steps would you take to identify and resolve the problem?
- What do you consider a high load: how many requests per second or per minute?