Initial commit: Complete Software Architecture course with 11 modules
- Added comprehensive course structure with 11 modules - Included theoretical content, practical examples, and tasks - Multi-language code examples (Java, Rust, Node.js, Python) - Detailed analysis of architectural approaches and trade-offs - Complete caching strategies documentation - Architecture examples from real-world systems (Twitter, Netflix, Uber) - Structured navigation and learning path - Ready for educational use
This commit is contained in:
commit
15e744da49
107 files changed
+61762
No files matched your search
@@ -0,0 +1,102 @@
|
||||
# Оптимизация сети
|
||||
|
||||
## Навигация
|
||||
- [🏠 Главная страница курса](../../../README.md)
|
||||
- [📚 Модуль 10](../README.md)
|
||||
|
||||
---
|
||||
|
||||
## Оптимизация сети
|
||||
|
||||
### 1. Connection Pooling
|
||||
```java
|
||||
// Оптимизация HTTP соединений
|
||||
@Configuration
|
||||
public class HttpClientConfig {
|
||||
@Bean
|
||||
public RestTemplate restTemplate() {
|
||||
HttpComponentsClientHttpRequestFactory factory =
|
||||
new HttpComponentsClientHttpRequestFactory();
|
||||
|
||||
// Настройка пула соединений
|
||||
PoolingHttpClientConnectionManager connectionManager =
|
||||
new PoolingHttpClientConnectionManager();
|
||||
connectionManager.setMaxTotal(100);
|
||||
connectionManager.setDefaultMaxPerRoute(20);
|
||||
|
||||
CloseableHttpClient httpClient = HttpClients.custom()
|
||||
.setConnectionManager(connectionManager)
|
||||
.setDefaultRequestConfig(RequestConfig.custom()
|
||||
.setConnectTimeout(5000)
|
||||
.setSocketTimeout(10000)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
factory.setHttpClient(httpClient);
|
||||
return new RestTemplate(factory);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Compression
|
||||
```java
|
||||
// Сжатие HTTP ответов
|
||||
@Configuration
|
||||
public class CompressionConfig {
|
||||
@Bean
|
||||
public FilterRegistrationBean<CompressionFilter> compressionFilter() {
|
||||
FilterRegistrationBean<CompressionFilter> registration =
|
||||
new FilterRegistrationBean<>();
|
||||
registration.setFilter(new CompressionFilter());
|
||||
registration.addUrlPatterns("/*");
|
||||
registration.setName("compressionFilter");
|
||||
registration.setOrder(1);
|
||||
return registration;
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
public class CompressionFilter implements Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
|
||||
HttpServletRequest httpRequest = (HttpServletRequest) request;
|
||||
HttpServletResponse httpResponse = (HttpServletResponse) response;
|
||||
|
||||
String acceptEncoding = httpRequest.getHeader("Accept-Encoding");
|
||||
if (acceptEncoding != null && acceptEncoding.contains("gzip")) {
|
||||
httpResponse.setHeader("Content-Encoding", "gzip");
|
||||
GzipResponseWrapper gzipResponse = new GzipResponseWrapper(httpResponse);
|
||||
chain.doFilter(request, gzipResponse);
|
||||
gzipResponse.finish();
|
||||
} else {
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. CDN Integration
|
||||
```java
|
||||
// Интеграция с CDN
|
||||
@Service
|
||||
public class CDNService {
|
||||
@Value("${cdn.base-url}")
|
||||
private String cdnBaseUrl;
|
||||
|
||||
public String getCDNUrl(String path) {
|
||||
return cdnBaseUrl + "/" + path;
|
||||
}
|
||||
|
||||
public void uploadToCDN(String path, byte[] content) {
|
||||
// Загрузка контента в CDN
|
||||
// Реализация зависит от выбранного CDN провайдера
|
||||
}
|
||||
|
||||
public void invalidateCDNCache(String path) {
|
||||
// Инвалидация кэша CDN
|
||||
// Реализация зависит от выбранного CDN провайдера
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in new issue
Block a user