问题描述
我试图将import { ofType,combineEpics } from 'redux-observable'
import {
mergeMap,withLatestFrom,catchError,debounce,switchMap,} from 'rxjs/operators'
import { from,of,timer,forkJoin } from 'rxjs'
import { IDependencies } from '../../configure-store'
import { apiErrorAction } from '../../reducers/errors/actions'
import {
TOC_FETCH,tocSetAction,ITocFetchActionProps,tocCompleteAction,} from '../../reducers/table-of-contents/actions'
import { defaults } from 'lodash'
// Can probably use forkJoin here,and create multiple API calls as a parallel observable
// https://github.com/patricktran/react-redux-observable-epic-forkjoin-apis/blob/master/src/epics/index.js
export const tocFetchEpic = (
action$: any,state$: any,{ apiClient }: IDependencies,) => {
return action$.pipe(
ofType(TOC_FETCH),debounce(() => timer(300)),// anti-DDoS
withLatestFrom(state$),mergeMap(
([
{
payload: { instance },},]: [{ payload: ITocFetchActionProps },any]) => {
const params = { 'myParam': instance,limit: 1 }
return from(apiClient.get('endpoint',{ params })).pipe(
mergeMap(
(result): any => {
const def = {
limit: -1,'newParam': result.data.results[0],}
const configurations = [
{
uri: 'endpointOne',config: defaults({},def),{
uri: 'endpointTwo',config: defaults(
{
'specialParam': 'table','specialParamTwo': 'http://example.com','iso2:lang': 'en',def,),{
uri: 'endpointThree',config: defaults(
{
'anotherSpecialParam': 'role',]
// Create a bunch of observables
const parallelObservables = configurations.map(api =>
from(
apiClient.get(api.uri,{ params: api.config }),).pipe(
switchMap(response => of(response)),catchError(err =>
of(apiErrorAction(err),tocCompleteAction({ instance })),)
// Return a forkJoin of them.
return forkJoin(
parallelObservables,(names: any,schoolNames: any,storeNames: any) => {
//projection
return { // <- The object returned here is ultimately what gets written into state
instance: result.data.results[0],tables: names.data.results,labels: [
...schoolNames.data.results,...storeNames.data.results,],}
},).pipe(
switchMap(response => {
return of(
tocSetAction(response),tocCompleteAction({ instance }),)
}),)
},catchError(error =>
of(tocCompleteAction({ instance }),apiErrorAction(error)),)
},)
}
export default combineEpics(tocFetchEpic)
文件从本地目录复制到我的Google云存储桶,
使用:
.mp4
这部分工作正常,但是当我尝试限制带宽时,使用:
gsutil cp my_filefile.mp4 gs://my_bucket
上传速度相同,而不是10 kb / s。我已经了解到trickle -d 10 -u 10 gsutil cp my_filefile.mp4 gs://my_bucket
不处理静态可执行文件,因为在终端中运行trickle
时,.mp4似乎是静态的可执行文件,它在终端中返回ldd my_file.mp4
。
有人遇到过同样的问题吗?如果是这种情况,该问题是如何处理的?或者我以错误的方式解决了这个问题?
not a dynamic executable
更新1:
原来,我使用什么文件都没有关系。 gsutil仍然以某种方式绕过trick流。我已经测试过,看一下细流是否可以与其他程序一起使用,并且通过带宽控制按预期执行。
我还测试了
和gsutil mv
,其结果与gsutil rsync
相同。我还测试了在arm64系统上的带宽限制,结果相同。
解决方法
您应按照the documentation中所述限制线程和进程的数量。在多进程的情况下,不应应用流。
trickle -d 10 -u 10 gsutil -o "GSUtil:parallel_process_count=1" \
-o "GSUtil:parallel_thread_count=1" cp my_filefile.mp4 gs://my_bucket